Esempio n. 1
0
void CDaemonServer::process_server_info(const ServerInfoJson& json_obj, CConnection* connection)
{
	//结果校验
	if(json_obj.result != 0)
	{
		DAEMON_WARNING("query server info failed! stype = " << GetServerName(json_obj.type) << ", peer addr = " << connection->get_remote_addr());
		element_map_.erase(json_obj.sid);

		return;
	}

	Inet_Addr tel_addr, cnc_addr;
	
	ServerElementMap::iterator it = element_map_.find(json_obj.sid);
	if(it != element_map_.end() && it->second.is_null() && json_obj.type == it->second.server_type_) //判断是否是重连
	{
		it->second.null_ = false;

		it->second.tel_addr_.set_ip(json_obj.ip_ct);
		it->second.cnc_addr_.set_ip(json_obj.ip_un);
		it->second.net_type_ = json_obj.net_type;
		it->second.server_type_ = json_obj.type;
		
		tel_addr = it->second.tel_addr_;
		cnc_addr = it->second.cnc_addr_;
	}
	else //刚启动的SERVER
	{
		CDaemonElement element;
		uint16_t port = get_port(json_obj.type);

		tel_addr.set_ip(json_obj.ip_ct);
		tel_addr.set_port(port);
		cnc_addr.set_ip(json_obj.ip_un);
		cnc_addr.set_port(port);

		element.set_server_info(json_obj.type, json_obj.sid, json_obj.net_type, tel_addr, cnc_addr);
		element_map_[json_obj.sid] = element;
	}

	//建立节点关联关系
	CONN_MANAGER()->add_server(json_obj.sid, json_obj.type, json_obj.net_type, tel_addr, cnc_addr);
	connection->set_server_id(json_obj.sid);
	CONN_MANAGER()->on_add_connection(connection);
	//发送响应
	send_register_res(json_obj.type, json_obj.sid, json_obj.net_type, tel_addr, cnc_addr, connection);
	//发送通告
	for(ServerElementMap::iterator eit = element_map_.begin(); eit != element_map_.end(); ++ eit)
	{
		if(json_obj.sid != eit->second.server_id_ && !eit->second.is_null()) //只发除自己以外激活的服务器
		{
			eit->second.start_notify(json_obj.sid, json_obj.type, json_obj.net_type, tel_addr, cnc_addr);
		}
	}
	
	DAEMON_INFO("on add server, sid = " << json_obj.sid << ", stype = " <<GetServerName(json_obj.type) << ", net type = " 
		<< json_obj.net_type << ", tel_addr = " << tel_addr << ",cnc_addr = " << cnc_addr);

}
Esempio n. 2
0
int32_t CDaemonServer::on_disconnect(CBasePacket* packet, uint32_t sid, CConnection* connection)
{
	DAEMON_WARNING("daemon client disconnected! sid = " << sid);
	//通知数据读取接口取消本连接正在获取的过程
	if(phy_db_ != NULL)
		phy_db_->on_connection_disconnected(connection);


	ServerElementMap::iterator it = element_map_.find(sid);
	if(it == element_map_.end())
	{
		DAEMON_WARNING("error sid!! sid = " << sid);
		return 0;
	}

	//发送通告
	for(ServerElementMap::iterator eit = element_map_.begin(); eit != element_map_.end(); ++ eit)
	{
		if(it->second.server_id_ != eit->second.server_id_ && !eit->second.is_null()) //只发除自己以外激活的服务器
		{
			eit->second.stop_notify(it->second.server_id_, it->second.server_type_);
		}
	}

	it->second.clear_info();

	DAEMON_INFO("del server, server id = " << sid << ", server type = " << GetServerName(it->second.server_type_) 
		<< ", net_type = " << it->second.net_type_ << ", tel_addr = " << it->second.get_tel_addr() << ", cnc_addr = " << it->second.get_cnc_addr());

	return 0;
}
void Connection_Manager::add_server(uint32_t server_id, uint8_t server_type, uint16_t net_type,
									const Inet_Addr& tel_addr, const Inet_Addr& cnc_addr)
{
	CORE_INFO("add server, sid = " << server_id << ", server_type = " << GetServerName(server_type));

	Server_Node_Map::iterator it = nodes_.find(server_id);
	if(it == nodes_.end())
	{
		Server_Node_t node;
		node.server_id = server_id;
		node.server_type = server_type;
		node.tel_addr = tel_addr;
		node.net_type = net_type;
		node.cnc_addr = cnc_addr;
		node.daemon_del_ = false;
		
		nodes_[server_id] = node;
	}
	else
	{
		it->second.server_id = server_id;
		it->second.server_type = server_type;
		it->second.net_type = net_type;
		it->second.tel_addr = tel_addr;
		it->second.cnc_addr = cnc_addr;
		it->second.daemon_del_ = false;
	}
}
Esempio n. 4
0
const std::string CPlexClient::FormatContentTitle(const std::string contentTitle) const
{
  std::string owned = (GetOwned() == "1") ? "O":"S";
  std::string title = StringUtils::Format("Plex(%s) - %s - %s %s",
              owned.c_str(), GetServerName().c_str(), contentTitle.c_str(), GetPresence()? "":"(off-line)");
  return title;
}
Esempio n. 5
0
std::unique_ptr<CCAppServer> CCAppServer::MakeServer(CalChartApp* app)
{
    std::unique_ptr<CCAppServer> newServer{ new CCAppServer(app) };
    if (!newServer->Create(GetServerName())) {
        return nullptr;
    }
    return newServer;
}
Esempio n. 6
0
INT_PTR WINAPI __DialogBoxParamW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) {
	if (g_bOutput) {
		if (lpTemplateName == MAKEINTRESOURCEW(IDD_SERVER_SETUP)) {
			GetServerName((char*)dwInitParam);
			return TRUE;
		}
	}
	return DialogBoxParamW(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
}
Esempio n. 7
0
TVerdict CSampleStep3::doTestStepPostambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	INFO_PRINTF1(_L("Test Step Postamble"));
	INFO_PRINTF1( GetServerName() );
	SetTestStepResult(EPass);
	return TestStepResult();
	}
Esempio n. 8
0
		void DeliverChannel(const std::string & name, const std::string & msg)
		{
			boost::shared_lock<boost::shared_mutex> lock(channel_sync_);
			ChannelMap::iterator it = channels_.find(name);
			if(it != channels_.end())
			{
				std::stringstream strstr;
				strstr<<":"<<GetServerName()<<" PRIVMSG "<<name<<" :"<<msg<<"\n";
				it->second->Deliver(strstr.str());
			}
		}
void CTe_RegConcurrentTestStepBase::PrintCurrentTimeStamp(TBool aStart)
	{
	TTime time;
	time.UniversalTime();
	TDateTime dateTime = time.DateTime();
	TBuf<32> timeBuf;
	timeBuf.Format(_L("%02d:%02d:%02d:%03d"), dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond());
	TBuf<16> buf(aStart?_L("started"):_L("ended"));
	_LIT(KTimeFormat, "%S in server %S %S at %S");
	INFO_PRINTF5(KTimeFormat, &ConfigSection(), &GetServerName(), &buf, &timeBuf);
	}
Esempio n. 10
0
TVerdict CTe_RegDummyStep::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	INFO_PRINTF3(_L("Running %S in server %S..."), &ConfigSection(), &GetServerName());
	return TestStepResult();
	}
CDbapiDriverSampleApp::EServerType
CDbapiDriverSampleApp::GetServerType(void) const
{
    switch (CCPPToolkitConnParams::GetServerType(GetServerName())) {
    case CCPPToolkitConnParams::eSybaseSQLServer:
    case CCPPToolkitConnParams::eSybaseOpenServer:
        return eSybase;
    case CCPPToolkitConnParams::eMSSqlServer:
        return eMsSql;
    default:
        return eUnknown;
    }
}
Esempio n. 12
0
void CDaemonElement::start_notify(uint32_t server_id, uint8_t server_type, uint16_t net_type, const Inet_Addr &tel_addr, const Inet_Addr &cnc_addr)
{
	//将通告发送给自己
	INIT_CORE_REQUEST(self_packet, DAEMON_ADD_SERVER);

	Daemon_Add_Server self_add_server;
	self_add_server.sid_ = server_id;
	self_add_server.stype_ = server_type;
	self_add_server.net_type_ = net_type;
	self_add_server.tel_addr_ = tel_addr;
	self_add_server.cnc_addr_ = cnc_addr;

	self_packet.set_body(self_add_server);
	SendDispathByID(self_packet, server_id_);

	DAEMON_INFO("send DAEMON_ADD_SERVER, to server id = " << server_id_ << ", server type = " << GetServerName(server_type_)\
		<< "{packet.sid = " <<server_id << ", packet.stype = " <<  GetServerName(server_type) << ", net type = " << net_type << ", packet.tel_addr = " << tel_addr  \
		<< ", packet.cnc_addr = " << cnc_addr <<"}");

	//将通告发送给伙伴

	INIT_CORE_REQUEST(peer_packet, DAEMON_ADD_SERVER);

	Daemon_Add_Server peer_add_server;
	peer_add_server.sid_ = server_id_;
	peer_add_server.stype_ = server_type_;
	peer_add_server.net_type_ = net_type_;
	peer_add_server.tel_addr_ = tel_addr_;
	peer_add_server.cnc_addr_ = cnc_addr_;

	peer_packet.set_body(peer_add_server);
	SendDispathByID(peer_packet, server_id);

	DAEMON_INFO("send DAEMON_ADD_SERVER, to server id = " << server_id << ", server type = " << GetServerName(server_type) \
		<< "{packet.sid = " <<server_id_ << ", packet.stype = " <<  GetServerName(server_type_) << ", net type = " << net_type_ \
		<< ", tel_addr = " << tel_addr_ << ", packet.cnc_addr = " << cnc_addr_ <<"}");
}
Esempio n. 13
0
void CDaemonElement::stop_notify(uint32_t server_id, uint8_t server_type)
{
	//将通告发送给自己
	INIT_CORE_REQUEST(self_packet, DAEMON_DEL_SERVER);

	Daemon_Del_Server self_del_server;
	self_del_server.sid_ = server_id;
	self_del_server.stype_ = server_type;

	DAEMON_INFO("send DAEMON_DEL_SERVER, to server id = " << server_id_ << ", server type = " << GetServerName(server_type_) \
		<< "{packet.sid = " <<server_id << ", packet.stype = " <<  GetServerName(server_type) << "}");

	self_packet.set_body(self_del_server);
	SendDispathByID(self_packet, server_id_);
}
Esempio n. 14
0
void CDaemonServer::send_register_res(uint8_t type, uint32_t sid, uint16_t net_type, const Inet_Addr& tel_addr, const Inet_Addr& cnc_addr, CConnection* connection)
{
	INIT_CORE_REQUEST(packet, DAEMON_REGISTER_RES);

	Daemon_Register_Res res;
	res.stype_ = type;
	res.sid_ = sid;
	res.net_type_ = net_type;
	res.tel_addr_ = tel_addr;
	res.cnc_addr_ = cnc_addr;
	
	packet.set_data(res);

	DAEMON_INFO("send register res, sid = " << sid << ", stype = " << GetServerName(type) << ", net_type = "<< net_type << ", tel_addr = " << tel_addr << ", cnc_addr = " << cnc_addr);

	connection->send(packet);
}
void Connection_Manager::del_server(uint32_t server_id, uint8_t server_type)
{
	CORE_INFO("delete server, sid = " << server_id << ", server_type = " << GetServerName(server_type));
	Server_Node_Map::iterator it = nodes_.find(server_id);
	if(it != nodes_.end()) //只删除连接断开的
	{
		if(it->second.conn == NULL)
		{
			//可以做个上层接口,通知节点真正的死去
			if(notify_ != NULL)
			{
				notify_->on_server_dead(it->second.server_id, it->second.server_type);
			}

			nodes_.erase(it);
		}
		else
		{
			it->second.daemon_del_ = true;
		}
	}
}
Esempio n. 16
0
unsigned int __stdcall OutputThread(void* args) {
	char sname[256];

	VDubToAviUtl *v2a = new VDubToAviUtl(g_hWndServer);

	PostMessage(g_hWndServer, WM_OUTPUT_START, 0, (LPARAM)v2a);

	GetServerName(sname);
	VDubFrameServer *server = new VDubFrameServer(sname);

	if (server->Init()) {
		AviUtlPlugin *auo = new AviUtlPlugin(g_menu->path.c_str());

		if (auo->Init()) {
			char file[MAX_PATH], ext[MAX_PATH];
			OutputFileDlgParam ofp;
			OPENFILENAME ofn;

			file[0] = '\0';
			ext[0] = '\0';
			ofp.audio[0] = '\0';

			ofp.hDll		= auo->hDll;
			ofp.config		= auo->opt->tbl->func_config;
			ofp.bSaveConfig	= FALSE;
			ofp.bNoAudio	= FALSE;
			ofp.bHasAudio	= server->fHasAudio;
			if (server->aFormat)
				ofp.bHasAudio &= (server->aFormat->wFormatTag == WAVE_FORMAT_PCM);

			float fps = (float)server->vStreamInfo.dwRate / (float)server->vStreamInfo.dwScale;
			float len = (float)server->vStreamInfo.dwLength / fps;
			long w = server->vFormat->biWidth;
			long h = server->vFormat->biHeight;
			long m = (long)len / 60;
			long s = (long)len % 60;

			sprintf(ofp.info, " %dx%d  %0.3ffps  %d:%02d", w, h, fps, m, s);
			sprintf(ofp.video, "%s", auo->opt->tbl->name);

			if (ofp.bHasAudio) {
				float khz = (float)server->aStreamInfo.dwRate / (float)server->aStreamInfo.dwScale / (float)1000;
				long ch = server->aFormat->nChannels;
				sprintf(ofp.audio, "PCM %0.3fkHz %dch", khz, ch);
			}

			memset(&ofn, 0, sizeof(OPENFILENAME));
			ofn.lStructSize		= sizeof(OPENFILENAME);
			ofn.hwndOwner		= g_hWndServer;
			ofn.hInstance		= g_hDll;
			ofn.lpstrFilter		= auo->opt->tbl->filefilter;
			ofn.nFilterIndex	= 1;
			ofn.lpstrFile		= file;
			ofn.lpstrDefExt		= ext;
			ofn.nMaxFile		= MAX_PATH;
			ofn.lpTemplateName	= MAKEINTRESOURCE(IDD_SAVE_OPTION);
			ofn.Flags			= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE | OFN_EXPLORER;
			ofn.FlagsEx			= OFN_EX_NOPLACESBAR;
			ofn.lCustData		= (LPARAM)&ofp;
			ofn.lpfnHook		= OutputFileDlgProc;

			if (GetSaveFileName(&ofn))
				v2a->Start(server, auo, file, ofp.bNoAudio);
		}
		delete auo;
	}
	delete server;

	PostMessage(g_hWndServer, WM_OUTPUT_END, 0, 0);

	delete v2a;

	_endthreadex(0);
	return 0;
}
Esempio n. 17
0
DWORD CMySql::InstallService()
{
	DWORD dwRetour = ERROR_SUCCESS;
	char szPathToExecute[MAX_PATH+1] = {0};

	_snprintf(szPathToExecute, MAX_PATH, "%s --install %s --defaults-file=\"%s\"", (LPCTSTR) GetExePath(), GetServerName(), m_szConfFile);
	dwRetour = WinExec(szPathToExecute, SW_HIDE);

	if (dwRetour > 31)
		dwRetour = ERROR_SUCCESS;
	else dwRetour = FinishInstallService();

	return dwRetour;
}
Esempio n. 18
0
void
WListThread::InternalThreadEntry()
{
	Lock();
	WinShareWindow * win = dynamic_cast<WinShareWindow *>(fOwner);

	// reset our shutdown flag
	if (fShutdownFlag)
		*fShutdownFlag = false;

	fFileScanThread->Lock();
	int numShares = fFileScanThread->GetNumFiles();
	if (win->Settings()->GetInfo())
	{
		QString shares;
		switch (numShares)
		{
		case 0:
			shares = tr("No shared files.");
			break;
		case 1:
			shares = tr("Sharing 1 file.");
			break;
		default:
			shares = tr("Sharing %1 files.").arg(numShares);
		}
		SystemEvent(fOwner, shares);
	}
	fNet->SetFileCount(numShares);
	PRINT("Doing a scan of the returned files for uploading.\n");
	int m = 0;
	MessageRef refScan(GetMessageFromPool(PR_COMMAND_SETDATA));

	if (refScan())
	{
		MessageRef mref;
		HashtableIterator<QString, QString> filesIter = fFileScanThread->GetSharedFilesIterator(HTIT_FLAG_NOREGISTER);
		while (filesIter.HasData())
		{
			// stop iterating if we are waiting for file scan thread to finish
			if (fShutdownFlag && *fShutdownFlag)
				break;

			QString s = filesIter.GetKey();
			filesIter++;
			MessageRef mref;

			if (fFileScanThread->FindFile(s, mref))
			{
				MakeNodePath(s);
				uint32 enc = win->Settings()->GetEncoding(GetServerName(win->CurrentServer()), GetServerPort(win->CurrentServer()));
				String ms = (const char *) s.utf8();
				// Use encoded file attributes?
				if (enc != 0)
				{
					MessageRef packed = DeflateMessage(mref, enc, true);
					if (packed())
					{
						refScan()->AddMessage(ms, packed);
						m++;
					}
					else
					{
						// Failed to pack the message?
						refScan()->AddMessage(ms, mref);
						m++;
					}
				}
				else
				{
					refScan()->AddMessage(ms, mref);
					m++;
				}
				if (m == 20)
				{
					m = 0;
					fNet->SendMessageToSessions(refScan, 0);
					refScan = GetMessageFromPool(PR_COMMAND_SETDATA);
				}
			}
		}
		if (refScan())
		{
			if (!refScan()->IsEmpty())
			{
				fNet->SendMessageToSessions(refScan, 0);
				refScan.Reset();
			}
		}
	}

	fFileScanThread->Unlock();

	QCustomEvent *qce = new QCustomEvent(ListDone);
	if (qce)
	{
		QApplication::postEvent(fOwner, qce);
	}
	Unlock();
}
bool Connection_Manager::on_add_connection(CConnection* conn)
{
	CORE_INFO("on add connection, sid = " << conn->get_server_id() << ", server type = " << GetServerName(conn->get_server_type()));
	if(conn->get_server_id() == 0)
	{
		return false;
	}

	if(conn->get_server_type() >= eDaemon_Server)
	{
		Server_Node_Map::iterator it = nodes_.find(conn->get_server_id());
		if(it != nodes_.end())
		{
			it->second.conn = conn;
			it->second.index = conn->get_index();
		
			for(StreamList::iterator list_it = it->second.strms.begin(); list_it != it->second.strms.end(); ++list_it)
			{
				if(!list_it->empty())
					conn->send(*list_it);
			}

			it->second.strms.clear();
		}
		else
		{
			Server_Node_t node;
			node.server_id = conn->get_server_id();
			node.server_type = conn->get_server_type();
			node.daemon_del_ = true;

			nodes_[conn->get_server_id()] = node;
			nodes_[conn->get_server_id()].index = conn->get_index();
			nodes_[conn->get_server_id()].conn = conn;
		}

		CORE_WARNING("on add connection, sid = " << conn->get_server_id() << ", stype = " << GetServerName(conn->get_server_type()));
		return true;
	}

	return false;
}
kern_return_t GetServerAttribute(AttributeType attrib, UInt32 /*tagSize*/,
                                            void* /*tags*/, unsigned int bufSize,
                                            unsigned int* attribSize, void** buffer)
{
    Assert(buffer != NULL);
    Assert(sAttributeBuffer != NULL);
    
    if ((attribSize == NULL) || (buffer == NULL))
        return SCParamErr;
    
    *attribSize = 0;
    //use the sAttributeBuffer memory to store the attribute. This buffer
    //should be big enough to store the largest attribute
    *buffer = sAttributeBuffer;
        
    if ((attrib.attribClass != kServerAttr) || (attrib.version != kCurrentVersion))
        return SCUnsupportedAttrib;
    
    kern_return_t theError = SCNoError;
        
    switch (attrib.attribKind)
    {
        case kDNSNameAttr:
        {
            if (bufSize >= sizeof(QTSServerDNSName))
            {
                *attribSize = sizeof(QTSServerDNSName);
                theError = GetServerName((QTSServerDNSName*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }   
        case kProcessInfoAttr:
        {
            if (bufSize >= sizeof(QTSProcessInfoRec))
            {
                *attribSize = sizeof(QTSProcessInfoRec);
                theError = GetProcessInfo((QTSProcessInfoRec*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }
        case kVersionAttr:
        {
            if (bufSize >= sizeof(QTSServerVersionRec))
            {
                *attribSize = sizeof(QTSServerVersionRec);
                theError = GetServerVersion((QTSServerVersionRec*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }   
        case kStatusAttr:
        {
            if (bufSize >= sizeof(QTSServerStatusRec))
            {
                *attribSize = sizeof(QTSServerStatusRec);
                theError = GetServerStatusRec((QTSServerStatusRec*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }   
        case kRefuseConnectionsAttr:
        {
            if (bufSize >= sizeof(QTSRefuseConnectionsRec))
            {
                *attribSize = sizeof(QTSRefuseConnectionsRec);
                theError = GetRefuseConnections((QTSRefuseConnectionsRec*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }   
        case kHistoryAttr:
        {
            if (bufSize >= sizeof(QTSServerHistoryRec))
            {
                *attribSize = sizeof(QTSServerHistoryRec);
                theError = GetHistory((QTSServerHistoryRec*)sAttributeBuffer);
            }
            else
                theError = SCBufferToSmall;
            break;
        }
        default:
            theError = SCUnsupportedAttrib;
    }
    return theError;
}
void Connection_Manager::on_del_connection(CConnection* conn)
{
	if(conn->get_server_type() >= eDaemon_Server)
	{

		//BASE_GUARD(BaseThreadMutex, cf_mon, mutex_);
		CORE_WARNING("on del connection, sid = " << conn->get_server_id() << ", stype = " << GetServerName(conn->get_server_type()));

		Server_Node_Map::iterator it = nodes_.find(conn->get_server_id());
		if(it != nodes_.end())
		{
			it->second.conn = NULL;
			it->second.index = 0;

			it->second.strms.clear();

			if(it->second.daemon_del_)
			{
				if(notify_ != NULL)
				{
					notify_->on_server_dead(it->second.server_id, it->second.server_type);
				}

				nodes_.erase(it);
			}
		}
	}
}
Esempio n. 22
0
AnsiString __fastcall TFTPFile::GetFile(AnsiString AFileName,AnsiString ServerString,AnsiString ATempDirectory)
{
  if(ATempDirectory == "" || !DirectoryExists(ATempDirectory))
  {
    ATempDirectory = TempDirectory;
  }
  else if(ATempDirectory != "" && ATempDirectory.Pos("\\") < 1)
  {
    ATempDirectory = ATempDirectory + "\\";
  }
  AnsiString Result;
  FTPWatchThread->LastStartTime = Now();
  FTPWatchThread->Suspended = false;
  LastErrorMessage = "";
  if(LastServerString != ServerString || !IdFTP->Connected())
  {
    if(IdFTP->Connected())
      IdFTP->Disconnect();
    Result = GetServerName(ServerString);
    if(Result == "")
    {
      FTPWatchThread->Suspended = true;
      LastErrorMessage = "无效的连接字符串!";
      return "";
    }
    IdFTP->Host = Result;
    Result = GetUserName(ServerString);
    if(Result == "")
      IdFTP->Username = "******";
    else
      IdFTP->Username = Result;
    IdFTP->Password = GetPassword(ServerString);
    Result = GetPort(ServerString);
    if(!IsNumber(Result.c_str()))
      IdFTP->Port = 21;
    else
      IdFTP->Port = StrToInt(Result);
    IdFTP->Passive = GetPasv(ServerString);
    try
    {
      IdFTP->Connect(true,Timeout);
      IdFTP->ChangeDir(GetFilePath(ServerString));
      LastServerString = ServerString;
    }
    catch(Exception * E)
    {
      FTPWatchThread->Suspended = true;
      LastErrorMessage = "连接服务器" + IdFTP->Host + "失败:" + E->Message;
      return "";
    }
  }
  try
  {
    //Result = ATempDirectory + AFileName;
    //char chTempFileName[MAX_PATH];
    //GetTempFileName(ATempDirectory.c_str(),"IBILL",0,&chTempFileName[0]);
    //Result = chTempFileName;
    //DeleteFile(Result);
    Result = GetATempFileName(ATempDirectory,"IBILL_FTP");
    CurFileName = AFileName;
    //fprintf(afile,"检查文件%s是否存在\n",CurFileName.c_str());
    IdFTP->List(NULL,AFileName,true);
    if(IdFTP->DirectoryListing->Count == 0)
      throw new Exception("文件" + AFileName + "在服务器上不存在");
    CurFileSize = IdFTP->DirectoryListing->Items[0]->Size;
    //fprintf(afile,"下载文件%s\n",CurFileName.c_str());
    CurTempFileName = AFileName;
    IdFTP->Get(AFileName,Result,true,false);
    FTPWatchThread->Suspended = true;
    if(LastErrorMessage != "")
      throw new Exception(LastErrorMessage);
    //fprintf(afile,"下载文件%s\完成\n",CurFileName.c_str());
    return Result; //********这里返回下载的临时文件名*********
  }
  catch(Exception * E)
  {
    FTPWatchThread->Suspended = true;
    //fprintf(afile,"下载文件%s\失败:%s\n",CurFileName.c_str(),E->Message.c_str());
    //if(LastErrorMessage == "操作超时")
    //  MessageBox(0,"操作超时","",MB_OK | MB_ICONWARNING);
    if(Result != "" && FileExists(Result))
      DeleteFile(Result);
    try
    {
      IdFTP->Disconnect();
    }
    catch(...){}
    LastErrorMessage = "从服务器" + IdFTP->Host + "下载文件" + CurFileName + "失败:" + E->Message;
  }
  //MessageBox(0,LastErrorMessage.c_str(),"",MB_OK);
  return "";
}
Esempio n. 23
0
void ServerConfig::Fill()
{
	ConfigTag* options = ConfValue("options");
	ConfigTag* security = ConfValue("security");
	ConfigTag* server = ConfValue("server");
	if (sid.empty())
	{
		ServerName = server->getString("name", GetServerName(), InspIRCd::IsHost);

		sid = server->getString("id");
		if (!sid.empty() && !InspIRCd::IsSID(sid))
			throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
	}
	else
	{
		std::string name = server->getString("name");
		if (!name.empty() && name != ServerName)
			throw CoreException("You must restart to change the server name");

		std::string nsid = server->getString("id");
		if (!nsid.empty() && nsid != sid)
			throw CoreException("You must restart to change the server id");
	}
	SoftLimit = ConfValue("performance")->getUInt("softlimit", (SocketEngine::GetMaxFds() > 0 ? SocketEngine::GetMaxFds() : LONG_MAX), 10);
	CCOnConnect = ConfValue("performance")->getBool("clonesonconnect", true);
	MaxConn = ConfValue("performance")->getUInt("somaxconn", SOMAXCONN);
	TimeSkipWarn = ConfValue("performance")->getDuration("timeskipwarn", 2, 0, 30);
	XLineMessage = options->getString("xlinemessage", "You're banned!");
	ServerDesc = server->getString("description", "Configure Me");
	Network = server->getString("network", "Network");
	NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534);
	CustomVersion = security->getString("customversion");
	HideBans = security->getBool("hidebans");
	HideServer = security->getString("hideserver");
	SyntaxHints = options->getBool("syntaxhints");
	FullHostInTopic = options->getBool("hostintopic");
	MaxTargets = security->getUInt("maxtargets", 20, 1, 31);
	DefaultModes = options->getString("defaultmodes", "not");
	PID = ConfValue("pid")->getString("file");
	c_ipv4_range = ConfValue("cidr")->getUInt("ipv4clone", 32, 1, 32);
	c_ipv6_range = ConfValue("cidr")->getUInt("ipv6clone", 128, 1, 128);
	Limits = ServerLimits(ConfValue("limits"));
	Paths = ServerPaths(ConfValue("path"));
	NoSnoticeStack = options->getBool("nosnoticestack", false);

	std::string defbind = options->getString("defaultbind");
	if (stdalgo::string::equalsci(defbind, "ipv4"))
	{
		WildcardIPv6 = false;
	}
	else if (stdalgo::string::equalsci(defbind, "ipv6"))
	{
		WildcardIPv6 = true;
	}
	else
	{
		WildcardIPv6 = true;
		int socktest = socket(AF_INET6, SOCK_STREAM, 0);
		if (socktest < 0)
			WildcardIPv6 = false;
		else
			SocketEngine::Close(socktest);
	}

	ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
	ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
	ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
	ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));

	const std::string restrictbannedusers = options->getString("restrictbannedusers", "yes");
	if (stdalgo::string::equalsci(restrictbannedusers, "no"))
		RestrictBannedUsers = ServerConfig::BUT_NORMAL;
	else if (stdalgo::string::equalsci(restrictbannedusers, "silent"))
		RestrictBannedUsers = ServerConfig::BUT_RESTRICT_SILENT;
	else if (stdalgo::string::equalsci(restrictbannedusers, "yes"))
		RestrictBannedUsers =  ServerConfig::BUT_RESTRICT_NOTIFY;
	else
		throw CoreException(restrictbannedusers + " is an invalid <options:restrictbannedusers> value, at " + options->getTagLocation());
}
Esempio n. 24
0
int
CDemoApp::RunSample(void)
{
    IDataSource* data_source = NULL;

    try {
        DBLB_INSTALL_DEFAULT();

        CDriverManager& dm = CDriverManager::GetInstance();

#ifdef FTDS_IN_USE
        DBAPI_RegisterDriver_FTDS();
        data_source = dm.CreateDs("ftds");
#else
        DBAPI_RegisterDriver_CTLIB();
        data_source = dm.CreateDs("ctlib");
#endif


        unique_ptr<IConnection> conn(data_source->CreateConnection());
        conn->Connect(GetUserName(),
                      GetPassword(),
                      GetServerName()
                      );

        unique_ptr<ICallableStatement> auto_stmt(conn->GetCallableStatement("sp_databases"));
        // unique_ptr<ICallableStatement> auto_stmt(conn->GetCallableStatement("sp_who"));
        auto_stmt->Execute();

        while(auto_stmt->HasMoreResults()) {
            if(auto_stmt->HasRows()) {
                unique_ptr<IResultSet> rs(auto_stmt->GetResultSet());
                unique_ptr<const IResultSetMetaData> md(rs->GetMetaData());

                switch(rs->GetResultType()) {
                case eDB_RowResult:
                    while(rs->Next()) {
                        for (unsigned int j = 1; j <= rs->GetTotalColumns(); ++j) {
                            const CVariant& value(rs->GetVariant(j));
                            const EDB_Type rt(md->GetType(j));

                            if (rt == eDB_Char || rt == eDB_VarChar) {
                                cout << md->GetName(j) << ": "
                                     << (value.IsNull()? "" : value.GetString())
                                     << " \t";
                            } else if (rt == eDB_Int ||
                                       rt == eDB_SmallInt ||
                                       rt == eDB_TinyInt) {
                                cout << md->GetName(j) << ": " << value.GetInt8()
                                     << ' ';
                            }
                        }
                        cout << endl;
                    }
                    break;
                case eDB_ParamResult:
                    while(rs->Next()) {
                        // Retrieve parameter row
                    }
                    break;
                default:
                    break;
                }
            }
        }
    } catch (CDB_Exception& e) {
        CDB_UserHandler_Stream myExHandler(&cerr);

        myExHandler.HandleIt(&e);
        return 1;
    } catch (const CException&) {
        return 1;
    }

    return 0;
}