static void CopyOutbound(OUTBOUND *pOutbounds, USERDATAOPT *pUserdata, char *pchFileName, char *OutboundPath) { FTNADDRESS Address; memset(pOutbounds, 0, sizeof(OUTBOUND)*MAX_ADDRESSES); /* Pfad konstruieren */ if (OutboundPath[0] && OutboundPath[1] == ':') { /* kompletter Pfad */ strcpy(pOutbounds[0].outbound, OutboundPath); } else { /* Teilpfad */ CopyPath(pOutbounds[0].outbound, pchFileName); strcat(pOutbounds[0].outbound, "\\"); strcat(pOutbounds[0].outbound, OutboundPath); } StringToNetAddr(pUserdata->address[0], &Address, NULL); pOutbounds[0].zonenum = Address.usZone; return; }
bool GetNetAddrFromNameAsync(const std::string& name, NetworkAddr& addr) { // We don't use nlGetAddrFromNameAsync here because we have to use SmartPointers // The problem is, if you call this and then delete the memory of the network address // while the thread isn't ready, it will write after to deleted memory. if(getNLaddr(addr) == NULL) return false; if(name == "") { SetNetAddrValid(addr, false); return false; } if (StringToNetAddr(name, addr)) { return true; } ResetSocketError(); // Clear the bad address error if(GetFromDnsCache(name, addr)) { SetNetAddrValid(addr, true); return true; } getNLaddr(addr)->valid = NL_FALSE; { Mutex::ScopedLock l(PendingDnsQueriesMutex); if(PendingDnsQueries.find(name) != PendingDnsQueries.end()) return true; PendingDnsQueries.insert(name); } struct GetAddrFromNameAsync_Executer : Task { std::string addr_name; NetAddrInternal::Ptr_t address; int handle() { if(GetAddrFromNameAsync_Internal(addr_name.c_str(), address.get())) { // TODO: we use default DNS record expire time of 1 hour, we should include some DNS client to make it in correct way AddToDnsCache(addr_name, NetworkAddr(NetAddrInternal(*address.get()))); } // TODO: handle failures here? there should be, but we only have the valid field // For now, we leave it at false, so the timeout handling will just occur. // push a net event onDnsReady.pushToMainQueue(EventData()); Mutex::ScopedLock l(PendingDnsQueriesMutex); PendingDnsQueries.erase(addr_name); return 0; } }; GetAddrFromNameAsync_Executer* data = new GetAddrFromNameAsync_Executer(); if(data == NULL) return false; data->name = "GetNetAddrFromNameAsync for " + name; data->addr_name = name; data->address = NetworkAddrData(addr).getPtr(); taskManager->start(data, TaskManager::QT_NoQueue); return true; }
NetworkAddr StringToNetAddr(const std::string& string) { NetworkAddr ret; ResetNetAddr(ret); StringToNetAddr(string, ret); return ret; };