void CFileDataIO::WriteTag(const CTag& tag) { try { WriteUInt8(tag.GetType()); if (!tag.GetName().IsEmpty()) { WriteString(tag.GetName(),utf8strNone); } else { WriteUInt16(1); WriteUInt8(tag.GetNameID()); } switch (tag.GetType()) { case TAGTYPE_HASH16: // Do NOT use this to transfer any tags for at least half a year!! WriteHash(CMD4Hash(tag.GetHash())); break; case TAGTYPE_STRING: WriteString(tag.GetStr(), utf8strRaw); // Always UTF8 break; case TAGTYPE_UINT64: WriteUInt64(tag.GetInt()); break; case TAGTYPE_UINT32: WriteUInt32(tag.GetInt()); break; case TAGTYPE_FLOAT32: WriteFloat(tag.GetFloat()); break; case TAGTYPE_BSOB: WriteBsob(tag.GetBsob(), tag.GetBsobSize()); break; case TAGTYPE_UINT16: WriteUInt16(tag.GetInt()); break; case TAGTYPE_UINT8: WriteUInt8(tag.GetInt()); break; case TAGTYPE_BLOB: // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a // and any aMule prior to SVN 26/02/2005 WriteUInt32(tag.GetBlobSize()); Write(tag.GetBlob(), tag.GetBlobSize()); break; default: //TODO: Support more tag types // With the if above, this should NEVER happen. AddLogLineNS(CFormat(wxT("CFileDataIO::WriteTag: Unknown tag: type=0x%02X")) % tag.GetType()); wxFAIL; break; } } catch (...) { AddLogLineNS(wxT("Exception in CDataIO:WriteTag")); throw; } }
CDownloadQueue::~CDownloadQueue() { if ( !m_filelist.empty() ) { for ( unsigned int i = 0; i < m_filelist.size(); i++ ) { AddLogLineNS(CFormat(_("Saving PartFile %u of %u")) % (i + 1) % m_filelist.size()); delete m_filelist[i]; } AddLogLineNS(_("All PartFiles Saved.")); } }
void CMuleUDPSocket::OnReceive(int errorCode) { AddDebugLogLineN(logMuleUDP, CFormat(wxT("Got UDP callback for read: Error %i Socket state %i")) % errorCode % Ok()); char buffer[UDP_BUFFER_SIZE]; amuleIPV4Address addr; unsigned length = 0; bool error = false; int lastError = 0; { wxMutexLocker lock(m_mutex); if (errorCode || (m_socket == NULL) || !m_socket->IsOk()) { DestroySocket(); CreateSocket(); return; } length = m_socket->RecvFrom(addr, buffer, UDP_BUFFER_SIZE); lastError = m_socket->LastError(); error = lastError != 0; } const uint32 ip = StringIPtoUint32(addr.IPAddress()); const uint16 port = addr.Service(); if (error) { OnReceiveError(lastError, ip, port); } else if (length < 2) { // 2 bytes (protocol and opcode) is the smallets possible packet. AddDebugLogLineN(logMuleUDP, m_name + wxT(": Invalid Packet received")); } else if (!ip) { // wxFAIL; AddLogLineNS(wxT("Unknown ip receiving a UDP packet! Ignoring: '") + addr.IPAddress() + wxT("'")); } else if (!port) { // wxFAIL; AddLogLineNS(wxT("Unknown port receiving a UDP packet! Ignoring")); } else if (theApp->clientlist->IsBannedClient(ip)) { AddDebugLogLineN(logMuleUDP, m_name + wxT(": Dropped packet from banned IP ") + addr.IPAddress()); } else { AddDebugLogLineN(logMuleUDP, (m_name + wxT(": Packet received (")) << addr.IPAddress() << wxT(":") << port << wxT("): ") << length << wxT("b")); OnPacketReceived(ip, port, (byte*)buffer, length); } }
int CamuleDaemonApp::InitGui(bool ,wxString &) { #ifndef __WXMSW__ if ( !enable_daemon_fork ) { return 0; } AddLogLineNS(_("amuled: forking to background - see you")); theLogger.SetEnabledStdoutLog(false); // // fork to background and detach from controlling tty // while redirecting stdout to /dev/null // for(int i_fd = 0;i_fd < 3; i_fd++) { close(i_fd); } int fd = open("/dev/null",O_RDWR); if (dup(fd)){} // prevent GCC warning if (dup(fd)){} pid_t pid = fork(); wxASSERT(pid != -1); if ( pid ) { exit(0); } else { pid = setsid(); // // Create a Pid file with the Pid of the Child, so any daemon-manager // can easily manage the process // if (!m_PidFile.IsEmpty()) { wxString temp = CFormat(wxT("%d\n")) % pid; wxFFile ff(m_PidFile, wxT("w")); if (!ff.Error()) { ff.Write(temp); ff.Close(); } else { AddLogLineNS(_("Cannot Create Pid File")); } } } #endif return 0; }
bool CamuleDaemonApp::OnInit() { if ( !CamuleApp::OnInit() ) { return false; } AddLogLineNS(_("amuled: OnInit - starting timer")); core_timer = new CTimer(this,ID_CORE_TIMER_EVENT); core_timer->Start(CORE_TIMER_PERIOD); glob_prefs->GetCategory(0)->title = GetCatTitle(thePrefs::GetAllcatFilter()); glob_prefs->GetCategory(0)->path = thePrefs::GetIncomingDir(); return true; }
void CPartFileConvert::StopThread() { if (s_convertPfThread) { s_convertPfThread->Delete(); } else { return; } AddLogLineNS(_("Waiting for partfile convert thread to die...")); while (s_convertPfThread) { wxSleep(1); } }
// // CTRL-C-Handler // see http://msdn.microsoft.com/en-us/library/windows/desktop/ms685049%28v=vs.85%29.aspx // static BOOL CtrlHandler(DWORD fdwCtrlType) { switch (fdwCtrlType) { case CTRL_C_EVENT: case CTRL_CLOSE_EVENT: case CTRL_BREAK_EVENT: // handle these AddLogLineNS(wxT("Received break event, exit main loop")); theApp->ExitMainLoop(); return TRUE; break; case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: default: // don't handle these return FALSE; break; } }
CListenSocket::CListenSocket(wxIPaddress &addr, const CProxyData *ProxyData) : // wxSOCKET_NOWAIT - means non-blocking i/o // wxSOCKET_REUSEADDR - means we can reuse the socket imediately (wx-2.5.3) CSocketServerProxy(addr, wxSOCKET_NOWAIT|wxSOCKET_REUSEADDR, ProxyData) { // 0.42e - vars not used by us bListening = false; shutdown = false; m_OpenSocketsInterval = 0; m_nPendingConnections = 0; totalconnectionchecks = 0; averageconnections = 0.0; // Set the listen socket event handler -- The handler is written in amule.cpp if (IsOk()) { SetEventHandler(*theApp, ID_LISTENSOCKET_EVENT); SetNotify(wxSOCKET_CONNECTION_FLAG); Notify(true); AddLogLineNS(_("ListenSocket: Ok.")); } else { AddLogLineCS(_("ERROR: Could not listen to TCP port.") ); } }
void CDownloadQueue::LoadMetFiles(const CPath& path) { AddLogLineNS(CFormat(_("Loading temp files from %s.")) % path.GetPrintable()); std::vector<CPath> files; // Locate part-files to be loaded CDirIterator TempDir(path); CPath fileName = TempDir.GetFirstFile(CDirIterator::File, wxT("*.part.met")); while (fileName.IsOk()) { files.push_back(path.JoinPaths(fileName)); fileName = TempDir.GetNextFile(); } // Loading in order makes it easier to figure which // file is broken in case of crashes, or the like. std::sort(files.begin(), files.end()); // Load part-files for ( size_t i = 0; i < files.size(); i++ ) { AddLogLineNS(CFormat(_("Loading PartFile %u of %u")) % (i + 1) % files.size()); fileName = files[i].GetFullName(); CPartFile *toadd = new CPartFile(); bool result = toadd->LoadPartFile(path, fileName) != 0; if (!result) { // Try from backup result = toadd->LoadPartFile(path, fileName, true) != 0; } if (result && !IsFileExisting(toadd->GetFileHash())) { { wxMutexLocker lock(m_mutex); m_filelist.push_back(toadd); } NotifyObservers(EventType(EventType::INSERTED, toadd)); Notify_DownloadCtrlAddFile(toadd); } else { wxString msg; if (result) { msg << CFormat(wxT("WARNING: Duplicate partfile with hash '%s' found, skipping: %s")) % toadd->GetFileHash().Encode() % fileName; } else { // If result is false, then reading of both the primary and the backup .met failed AddLogLineN(_("ERROR: Failed to load backup file. Search http://forum.amule.org for .part.met recovery solutions.")); msg << CFormat(wxT("ERROR: Failed to load PartFile '%s'")) % fileName; } AddLogLineCS(msg); // Delete the partfile object in the end. delete toadd; } } AddLogLineNS(_("All PartFiles Loaded.")); if ( GetFileCount() == 0 ) { AddLogLineN(_("No part files found")); } else { AddLogLineN(CFormat(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount())) % GetFileCount()); DoSortByPriority(); CheckDiskspace( path ); Notify_ShowUpdateCatTabTitles(); } }