| 1724 | } |
| 1725 | |
| 1726 | CECPacket *CECServerSocket::ProcessRequest2(const CECPacket *request) |
| 1727 | { |
| 1728 | |
| 1729 | if ( !request ) { |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
| 1733 | CECPacket *response = NULL; |
| 1734 | |
| 1735 | switch (request->GetOpCode()) { |
| 1736 | // |
| 1737 | // Misc commands |
| 1738 | // |
| 1739 | case EC_OP_SHUTDOWN: |
| 1740 | if (!theApp->IsOnShutDown()) { |
| 1741 | response = new CECPacket(EC_OP_NOOP); |
| 1742 | AddLogLineC(_("External Connection: shutdown requested")); |
| 1743 | #ifndef AMULE_DAEMON |
| 1744 | { |
| 1745 | wxCloseEvent evt; |
| 1746 | evt.SetCanVeto(false); |
| 1747 | theApp->ShutDown(evt); |
| 1748 | } |
| 1749 | #else |
| 1750 | theApp->ExitMainLoop(); |
| 1751 | #endif |
| 1752 | } else { |
| 1753 | response = new CECPacket(EC_OP_FAILED); |
| 1754 | response->AddTag(CECTag(EC_TAG_STRING, wxTRANSLATE("Already shutting down."))); |
| 1755 | } |
| 1756 | break; |
| 1757 | case EC_OP_ADD_LINK: { |
| 1758 | // Aggregate the per-link results into a single response: until |
| 1759 | // #206 was filed, every iteration overwrote the previous response, |
| 1760 | // so a batch of N-1 successes followed by one failure looked like |
| 1761 | // a total failure to the caller (and vice versa). |
| 1762 | int successCount = 0; |
| 1763 | int failCount = 0; |
| 1764 | for (CECPacket::const_iterator it = request->begin(); it != request->end(); ++it) { |
| 1765 | const CECTag &tag = *it; |
| 1766 | wxString link = tag.GetStringData(); |
| 1767 | int category = 0; |
| 1768 | const CECTag *cattag = tag.GetTagByName(EC_TAG_PARTFILE_CAT); |
| 1769 | if (cattag) { |
| 1770 | category = cattag->GetInt(); |
| 1771 | } |
| 1772 | AddLogLineC(CFormat(_("ExternalConn: adding link '%s'.")) % link); |
| 1773 | if ( theApp->downloadqueue->AddLink(link, category) ) { |
| 1774 | ++successCount; |
| 1775 | } else { |
| 1776 | // Per-link error reasons are already printed by AddLink(). |
| 1777 | ++failCount; |
| 1778 | } |
| 1779 | } |
| 1780 | if (failCount == 0) { |
| 1781 | response = new CECPacket(EC_OP_NOOP); |
| 1782 | } else if (successCount == 0) { |
| 1783 | response = new CECPacket(EC_OP_FAILED); |
nothing calls this directly
no test coverage detected