2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 Angel Vidal ( kry@amule.org )
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "config.h" // Needed for VERSION
31 #include <common/ClientVersion.h>
33 #include "TextClient.h"
36 #include <unistd.h> // Do_not_auto_remove
40 //-------------------------------------------------------------------
43 //-------------------------------------------------------------------
45 #include <ec/cpp/ECSpecialTags.h>
47 #include <wx/tokenzr.h>
49 #include <common/Format.h> // Needed for CFormat
50 #include "OtherFunctions.h"
51 #include "KnownFile.h" // Needed for Priority Levels
52 #include "DataToText.cpp" // Needed for PriorityToStr
54 #define APP_INIT_SIZE_X 640
55 #define APP_INIT_SIZE_Y 480
57 #define theApp (*((CamulecmdApp*)wxTheApp))
59 //-------------------------------------------------------------------
66 CMD_ID_PRIORITY_NORMAL
,
74 CMD_ID_DISCONNECT_ED2K
,
75 CMD_ID_DISCONNECT_KAD
,
77 CMD_ID_RELOAD_IPFILTER
,
78 CMD_ID_SET_IPFILTER_ON
,
79 CMD_ID_SET_IPFILTER_OFF
,
80 CMD_ID_SET_IPFILTER_CLIENTS_ON
,
81 CMD_ID_SET_IPFILTER_CLIENTS_OFF
,
82 CMD_ID_SET_IPFILTER_SERVERS_ON
,
83 CMD_ID_SET_IPFILTER_SERVERS_OFF
,
84 CMD_ID_SET_IPFILTER_LEVEL
,
86 CMD_ID_GET_IPFILTER_STATE
,
87 CMD_ID_GET_IPFILTER_STATE_CLIENTS
,
88 CMD_ID_GET_IPFILTER_STATE_SERVERS
,
89 CMD_ID_GET_IPFILTER_LEVEL
,
98 CMD_ID_SET_BWLIMIT_UP
,
99 CMD_ID_SET_BWLIMIT_DOWN
,
103 CMD_ID_SEARCH_GLOBAL
,
106 CMD_ID_SEARCH_RESULTS
,
107 CMD_ID_SEARCH_PROGRESS
,
109 // IDs for deprecated commands
114 // method to create a SearchFile
115 SearchFile::SearchFile(CEC_SearchFile_Tag
*tag
)
117 nHash
= tag
->FileHash();
118 sHash
= nHash
.Encode();
119 sFileName
= tag
->FileName();
120 lFileSize
= tag
->SizeFull();
121 lSourceCount
= tag
->SourceCount();
122 bPresent
= tag
->AlreadyHave();
125 //-------------------------------------------------------------------
126 IMPLEMENT_APP (CamulecmdApp
)
127 //-------------------------------------------------------------------
129 void CamulecmdApp::OnInitCmdLine(wxCmdLineParser
& parser
)
131 CaMuleExternalConnector::OnInitCmdLine(parser
);
132 parser
.AddOption(wxT("c"), wxT("command"),
133 _("Execute <str> and exit."),
134 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_OPTIONAL
);
137 bool CamulecmdApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
139 m_HasCmdOnCmdLine
= parser
.Found(wxT("command"), &m_CmdString
);
140 return CaMuleExternalConnector::OnCmdLineParsed(parser
);
143 void CamulecmdApp::TextShell(const wxString
& prompt
)
145 if (m_HasCmdOnCmdLine
)
146 Parse_Command(m_CmdString
);
148 CaMuleExternalConnector::TextShell(prompt
);
151 int CamulecmdApp::ProcessCommand(int CmdId
)
153 wxString args
= GetCmdArgs();
154 CECPacket
*request
= 0;
155 std::list
<CECPacket
*> request_list
;
157 EC_SEARCH_TYPE search_type
= EC_SEARCH_KAD
;
159 // Implementation of the deprecated command 'SetIPFilter'.
160 if (CmdId
== CMD_ID_SET_IPFILTER
) {
161 if ( ! args
.IsEmpty() ) {
162 if (args
.IsSameAs(wxT("ON"), false)) {
163 CmdId
= CMD_ID_SET_IPFILTER_ON
;
164 } else if (args
.IsSameAs(wxT("OFF"), false)) {
165 CmdId
= CMD_ID_SET_IPFILTER_OFF
;
167 return CMD_ERR_INVALID_ARG
;
170 CmdId
= CMD_ID_GET_IPFILTER_STATE
;
176 request_list
.push_back(new CECPacket(EC_OP_STAT_REQ
, EC_DETAIL_CMD
));
179 case CMD_ID_SHUTDOWN
:
180 request_list
.push_back(new CECPacket(EC_OP_SHUTDOWN
));
184 if ( !args
.IsEmpty() ) {
187 // Not much we can do against this unicode2char.
188 int result
= sscanf(unicode2char(args
), "%d.%d.%d.%d:%d", &ip
[0], &ip
[1], &ip
[2], &ip
[3], &port
);
190 // Try to resolve DNS -- good for dynamic IP servers
191 wxString
serverName(args
.BeforeFirst(wxT(':')));
193 bool ok
= args
.AfterFirst(wxT(':')).ToLong(&lPort
);
194 port
= (unsigned int)lPort
;
196 a
.Hostname(serverName
);
198 result
= sscanf(unicode2char(a
.IPAddress()), "%d.%d.%d.%d", &ip
[0], &ip
[1], &ip
[2], &ip
[3]);
199 if (serverName
.IsEmpty() || !ok
|| (result
!= 4)) {
200 Show(_("Invalid IP format. Use xxx.xxx.xxx.xxx:xxxx\n"));
205 addr
.m_ip
[0] = ip
[0];
206 addr
.m_ip
[1] = ip
[1];
207 addr
.m_ip
[2] = ip
[2];
208 addr
.m_ip
[3] = ip
[3];
210 request
= new CECPacket(EC_OP_SERVER_CONNECT
);
211 request
->AddTag(CECTag(EC_TAG_SERVER
, addr
));
212 request_list
.push_back(request
);
214 request_list
.push_back(new CECPacket(EC_OP_CONNECT
));
218 case CMD_ID_CONNECT_ED2K
:
219 request_list
.push_back(new CECPacket(EC_OP_SERVER_CONNECT
));
222 case CMD_ID_CONNECT_KAD
:
223 request_list
.push_back(new CECPacket(EC_OP_KAD_START
));
226 case CMD_ID_DISCONNECT
:
227 request_list
.push_back(new CECPacket(EC_OP_DISCONNECT
));
230 case CMD_ID_DISCONNECT_ED2K
:
231 request_list
.push_back(new CECPacket(EC_OP_SERVER_DISCONNECT
));
234 case CMD_ID_DISCONNECT_KAD
:
235 request_list
.push_back(new CECPacket(EC_OP_KAD_STOP
));
238 case CMD_ID_RELOAD_SHARED
:
239 request_list
.push_back(new CECPacket(EC_OP_SHAREDFILES_RELOAD
));
242 case CMD_ID_RELOAD_IPFILTER
:
243 request_list
.push_back(new CECPacket(EC_OP_IPFILTER_RELOAD
));
246 case CMD_ID_SET_IPFILTER_ON
:
247 case CMD_ID_SET_IPFILTER_CLIENTS_ON
:
248 case CMD_ID_SET_IPFILTER_SERVERS_ON
:
250 case CMD_ID_SET_IPFILTER_OFF
:
251 case CMD_ID_SET_IPFILTER_CLIENTS_OFF
:
252 case CMD_ID_SET_IPFILTER_SERVERS_OFF
:
254 if (CmdId
== CMD_ID_SET_IPFILTER_CLIENTS_ON
|| CmdId
== CMD_ID_SET_IPFILTER_CLIENTS_OFF
) {
255 CmdId
= CMD_ID_GET_IPFILTER_STATE_CLIENTS
;
256 } else if (CmdId
== CMD_ID_SET_IPFILTER_SERVERS_ON
|| CmdId
== CMD_ID_SET_IPFILTER_SERVERS_OFF
) {
257 CmdId
= CMD_ID_GET_IPFILTER_STATE_SERVERS
;
259 CmdId
= CMD_ID_GET_IPFILTER_STATE
;
262 request
= new CECPacket(EC_OP_SET_PREFERENCES
);
263 CECEmptyTag
prefs(EC_TAG_PREFS_SECURITY
);
264 if (CmdId
!= CMD_ID_GET_IPFILTER_STATE_SERVERS
) {
265 prefs
.AddTag(CECTag(EC_TAG_IPFILTER_CLIENTS
, (uint8
)tmp_int
));
267 if (CmdId
!= CMD_ID_GET_IPFILTER_STATE_CLIENTS
) {
268 prefs
.AddTag(CECTag(EC_TAG_IPFILTER_SERVERS
, (uint8
)tmp_int
));
270 request
->AddTag(prefs
);
271 request_list
.push_back(request
);
273 case CMD_ID_GET_IPFILTER
:
274 case CMD_ID_GET_IPFILTER_STATE
:
275 case CMD_ID_GET_IPFILTER_STATE_CLIENTS
:
276 case CMD_ID_GET_IPFILTER_STATE_SERVERS
:
277 request
= new CECPacket(EC_OP_GET_PREFERENCES
);
278 request
->AddTag(CECTag(EC_TAG_SELECT_PREFS
, (uint32
)EC_PREFS_SECURITY
));
279 request_list
.push_back(request
);
282 case CMD_ID_SET_IPFILTER_LEVEL
:
283 if (!args
.IsEmpty()) // This 'if' must stay as long as we support the deprecated 'IPLevel' command.
285 unsigned long int level
= 0;
286 if (args
.ToULong(&level
) == true && level
< 256) {
287 request
= new CECPacket(EC_OP_SET_PREFERENCES
);
288 CECEmptyTag
prefs(EC_TAG_PREFS_SECURITY
);
289 prefs
.AddTag(CECTag(EC_TAG_IPFILTER_LEVEL
, (uint8
)level
));
290 request
->AddTag(prefs
);
291 request_list
.push_back(request
);
293 return CMD_ERR_INVALID_ARG
;
296 CmdId
= CMD_ID_GET_IPFILTER_LEVEL
;
297 case CMD_ID_GET_IPFILTER_LEVEL
:
298 request
= new CECPacket(EC_OP_GET_PREFERENCES
);
299 request
->AddTag(CECTag(EC_TAG_SELECT_PREFS
, (uint32
)EC_PREFS_SECURITY
));
300 request_list
.push_back(request
);
307 if ( args
.IsEmpty() ) {
308 Show(_("This command requires an argument. Valid arguments: 'all', filename, or a number.\n"));
311 wxStringTokenizer
argsTokenizer(args
);
315 // Grab the entire dl queue right away
316 CECPacket
request_all(EC_OP_GET_DLOAD_QUEUE
, EC_DETAIL_CMD
);
317 const CECPacket
*reply_all
= SendRecvMsg_v2(&request_all
);
322 request
= new CECPacket(EC_OP_PARTFILE_PAUSE
); break;
324 request
= new CECPacket(EC_OP_PARTFILE_DELETE
); break;
326 request
= new CECPacket(EC_OP_PARTFILE_RESUME
); break;
327 default: wxASSERT(0);
330 // We loop through all the arguments
331 while(argsTokenizer
.HasMoreTokens()) {
332 token
=argsTokenizer
.GetNextToken();
334 // If the user requested all, then we select all files and exit the loop
335 // since there is little point to add anything more to "everything"
336 if( token
== wxT("all") ) {
337 for(int i
= 0;i
< reply_all
->GetTagCount();i
++) {
338 const CECTag
*tag
= reply_all
->GetTagByIndex(i
);
340 request
->AddTag(CECTag(EC_TAG_PARTFILE
, tag
->GetMD4Data()));
344 } else if ( hash
.Decode(token
.Trim(false).Trim(true)) ) {
345 if ( !hash
.IsEmpty() ) {
346 Show(_("Processing by hash: "+token
+wxT("\n")));
347 request
->AddTag(CECTag(EC_TAG_PARTFILE
, hash
));
350 // Go through the dl queue and look at each filename
351 for(int i
= 0; i
< reply_all
->GetTagCount(); i
++) {
352 CEC_PartFile_Tag
*tag
= (CEC_PartFile_Tag
*)reply_all
->GetTagByIndex(i
);
354 wxString partmetname
= tag
->PartMetName();
356 // We check for filename, XXX.pat.met, XXX.part, XXX
357 if( tag
->FileName() == token
||
358 partmetname
== token
||
359 partmetname
.Truncate(partmetname
.Len()-4) == token
||
360 partmetname
.Truncate(partmetname
.Len()-5) == token
) {
361 Show(_("Processing by filename: "+token
+wxT("\n")));
362 request
->AddTag(CECTag(EC_TAG_PARTFILE
, tag
->GetMD4Data()));
366 } // End of filename check else
367 } // End of argument token loop
369 request_list
.push_back(request
);
373 } // End of dl queue processing
375 } // end of command processing
379 case CMD_ID_PRIORITY_LOW
:
380 case CMD_ID_PRIORITY_NORMAL
:
381 case CMD_ID_PRIORITY_HIGH
:
382 case CMD_ID_PRIORITY_AUTO
:
383 if ( args
.IsEmpty() ) {
384 Show(_("This command requires an argument. Valid arguments: a file hash.\n"));
388 if (hash
.Decode(args
.Trim(false).Trim(true))) {
389 if (!hash
.IsEmpty()) {
390 request
= new CECPacket(EC_OP_PARTFILE_PRIO_SET
);
391 CECTag
hashtag(EC_TAG_PARTFILE
, hash
);
393 case CMD_ID_PRIORITY_LOW
:
394 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, (uint8
)PR_LOW
));
396 case CMD_ID_PRIORITY_NORMAL
:
397 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, (uint8
)PR_NORMAL
));
399 case CMD_ID_PRIORITY_HIGH
:
400 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, (uint8
)PR_HIGH
));
402 case CMD_ID_PRIORITY_AUTO
:
403 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, (uint8
)PR_AUTO
));
405 default: wxASSERT(0);
407 request
->AddTag(hashtag
);
408 request_list
.push_back(request
);
410 Show(_("Not a valid number\n"));
414 Show(_("Not a valid hash (length should be exactly 32 chars)\n"));
421 request_list
.push_back(new CECPacket(EC_OP_GET_ULOAD_QUEUE
));
425 request_list
.push_back(new CECPacket(EC_OP_GET_DLOAD_QUEUE
));
428 case CMD_ID_SHOW_LOG
:
429 request_list
.push_back(new CECPacket(EC_OP_GET_LOG
));
432 case CMD_ID_SHOW_SERVERS
:
433 request_list
.push_back(new CECPacket(EC_OP_GET_SERVER_LIST
, EC_DETAIL_CMD
));
436 case CMD_ID_RESET_LOG
:
437 request_list
.push_back(new CECPacket(EC_OP_RESET_LOG
));
441 if (args
.compare(0, 7, wxT("ed2k://")) == 0) {
442 //aMule doesn't like AICH links without |/| in front of h=
443 if (args
.Find(wxT("|h=")) > -1 && args
.Find(wxT("|/|h=")) == -1) {
444 args
.Replace(wxT("|h="),wxT("|/|h="));
447 request
= new CECPacket(EC_OP_ADD_LINK
);
448 request
->AddTag(CECTag(EC_TAG_STRING
, args
));
449 request_list
.push_back(request
);
452 case CMD_ID_SET_BWLIMIT_UP
:
453 tmp_int
= EC_TAG_CONN_MAX_UL
- EC_TAG_CONN_MAX_DL
;
454 case CMD_ID_SET_BWLIMIT_DOWN
:
455 tmp_int
+= EC_TAG_CONN_MAX_DL
;
457 unsigned long int limit
;
458 if (args
.ToULong(&limit
)) {
459 request
= new CECPacket(EC_OP_SET_PREFERENCES
);
460 CECEmptyTag
prefs(EC_TAG_PREFS_CONNECTIONS
);
461 prefs
.AddTag(CECTag(tmp_int
, (uint16
)limit
));
462 request
->AddTag(prefs
);
463 request_list
.push_back(request
);
465 return CMD_ERR_INVALID_ARG
;
468 case CMD_ID_GET_BWLIMITS
:
469 request
= new CECPacket(EC_OP_GET_PREFERENCES
);
470 request
->AddTag(CECTag(EC_TAG_SELECT_PREFS
, (uint32
)EC_PREFS_CONNECTIONS
));
471 request_list
.push_back(request
);
474 case CMD_ID_STATTREE
:
475 request
= new CECPacket(EC_OP_GET_STATSTREE
);
476 if (!args
.IsEmpty()) {
477 unsigned long int max_versions
;
478 if (args
.ToULong(&max_versions
)) {
479 if (max_versions
< 256) {
480 request
->AddTag(CECTag(EC_TAG_STATTREE_CAPPING
, (uint8
)max_versions
));
483 return CMD_ERR_INVALID_ARG
;
487 return CMD_ERR_INVALID_ARG
;
490 request_list
.push_back(request
);
492 case CMD_ID_SEARCH_GLOBAL
:
493 search_type
= EC_SEARCH_GLOBAL
;
494 case CMD_ID_SEARCH_LOCAL
:
495 if (search_type
!= EC_SEARCH_GLOBAL
){
496 search_type
= EC_SEARCH_LOCAL
;
498 case CMD_ID_SEARCH_KAD
:
499 if (search_type
!= EC_SEARCH_GLOBAL
&& search_type
!= EC_SEARCH_LOCAL
){
500 search_type
= EC_SEARCH_KAD
;
504 wxString search
= args
;
505 wxString type
= wxT("");
506 wxString extention
= wxT("");
511 request
= new CECPacket(EC_OP_SEARCH_START
);
512 request
->AddTag(CEC_Search_Tag (search
, search_type
, type
, extention
, avail
, min_size
, max_size
));
513 request_list
.push_back(request
);
517 printf("No search type defined.\nType 'help search' to get more help.\n");
521 case CMD_ID_SEARCH_RESULTS
:
522 request_list
.push_back(new CECPacket(EC_OP_SEARCH_RESULTS
, EC_DETAIL_FULL
));
525 case CMD_ID_SEARCH_PROGRESS
:
526 request_list
.push_back(new CECPacket(EC_OP_SEARCH_PROGRESS
));
529 case CMD_ID_DOWNLOAD
:
532 unsigned long int id
= 0;
533 if (args
.ToULong(&id
) == true && id
< m_Results_map
.size()) {
535 SearchFile
* file
= m_Results_map
[id
];
536 printf("Download File: %lu %s\n", id
, (const char*)unicode2char(file
->sFileName
));
537 request
= new CECPacket(EC_OP_DOWNLOAD_SEARCH_RESULT
);
538 // get with id the hash and category=0
540 CECTag
hashtag(EC_TAG_PARTFILE
, file
->nHash
);
541 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
542 request
->AddTag(hashtag
);
543 request_list
.push_back(request
);
545 return CMD_ERR_INVALID_ARG
;
551 return CMD_ERR_PROCESS_CMD
;
554 m_last_cmd_id
= CmdId
;
556 if ( ! request_list
.empty() ) {
557 std::list
<CECPacket
*>::iterator it
= request_list
.begin();
558 while ( it
!= request_list
.end() ) {
559 CECPacket
*curr
= *it
++;
560 const CECPacket
*reply
= SendRecvMsg_v2(curr
);
563 Process_Answer_v2(reply
);
567 request_list
.resize(0);
570 if (CmdId
== CMD_ID_SHUTDOWN
)
577 * Method to show the results in the console
579 void CamulecmdApp::ShowResults(CResultMap results_map
)
581 unsigned int name_max
= 80;
582 unsigned int mb_max
= 5;
583 unsigned int nr_max
= 5;
584 unsigned long int id
= 0;
585 wxString output
, name
, sources
, mb
, kb
;
587 printf("Nr. Filename: Size(MB): Sources: \n");
588 printf("-----------------------------------------------------------------------------------------------------------\n");
590 for( std::map
<unsigned long int,SearchFile
*>::iterator iter
= results_map
.begin(); iter
!= results_map
.end(); iter
++ ) {
592 SearchFile
* file
= (*iter
).second
;
594 output
.Printf(wxT("%i. "), id
);
595 output
= output
.SubString(0, nr_max
).Append(file
->sFileName
).Append(' ', name_max
);
596 mb
.Printf(wxT(" %d"), file
->lFileSize
/1024/1024);
597 kb
.Printf(wxT(".%d"), file
->lFileSize
/1024%1024);
598 output
= output
.SubString(0, nr_max
+ name_max
+ mb_max
- mb
.Length() ).Append(mb
).Append(kb
);
599 printf("%s %ld\n",(const char*)unicode2char(output
), file
->lSourceCount
);
604 // Formats a statistics (sub)tree to text
605 wxString
StatTree2Text(CEC_StatTree_Node_Tag
*tree
, int depth
)
608 return wxEmptyString
;
610 wxString result
= wxString(wxChar(' '), depth
) + tree
->GetDisplayString() + wxT("\n");
611 for (int i
= 0; i
< tree
->GetTagCount(); ++i
) {
612 CEC_StatTree_Node_Tag
*tmp
= (CEC_StatTree_Node_Tag
*)tree
->GetTagByIndex(i
);
613 if (tmp
->GetTagName() == EC_TAG_STATTREE_NODE
) {
614 result
+= StatTree2Text(tmp
, depth
+ 1);
621 * Format EC packet into text form for output to console
623 void CamulecmdApp::Process_Answer_v2(const CECPacket
*response
)
626 wxString
msgFailedUnknown(_("Request failed with an unknown error."));
628 switch (response
->GetOpCode()) {
630 s
<< _("Operation was successful.");
633 if (response
->GetTagCount()) {
634 const CECTag
*tag
= response
->GetTagByIndex(0);
636 s
<< CFormat(_("Request failed with the following error: %s")) % wxGetTranslation(tag
->GetStringData());
638 s
<< msgFailedUnknown
;
641 s
<< msgFailedUnknown
;
644 case EC_OP_SET_PREFERENCES
:
646 const CECTag
*tab
= response
->GetTagByNameSafe(EC_TAG_PREFS_SECURITY
);
647 const CECTag
*ipfilterLevel
= tab
->GetTagByName(EC_TAG_IPFILTER_LEVEL
);
649 if (m_last_cmd_id
== CMD_ID_GET_IPFILTER
||
650 m_last_cmd_id
== CMD_ID_GET_IPFILTER_STATE
||
651 m_last_cmd_id
== CMD_ID_GET_IPFILTER_STATE_CLIENTS
) {
652 s
<< wxString::Format(_("IP filtering for clients is %s.\n"),
653 (tab
->GetTagByName(EC_TAG_IPFILTER_CLIENTS
) == NULL
) ? _("OFF") : _("ON"));
655 if (m_last_cmd_id
== CMD_ID_GET_IPFILTER
||
656 m_last_cmd_id
== CMD_ID_GET_IPFILTER_STATE
||
657 m_last_cmd_id
== CMD_ID_GET_IPFILTER_STATE_SERVERS
) {
658 s
<< wxString::Format(_("IP filtering for servers is %s.\n"),
659 (tab
->GetTagByName(EC_TAG_IPFILTER_SERVERS
) == NULL
) ? _("OFF") : _("ON"));
661 if (m_last_cmd_id
== CMD_ID_GET_IPFILTER
||
662 m_last_cmd_id
== CMD_ID_GET_IPFILTER_LEVEL
) {
663 s
<< wxString::Format(_("Current IPFilter Level is %d.\n"),
664 ipfilterLevel
->GetInt());
667 tab
= response
->GetTagByNameSafe(EC_TAG_PREFS_CONNECTIONS
);
668 const CECTag
*connMaxUL
= tab
->GetTagByName(EC_TAG_CONN_MAX_UL
);
669 const CECTag
*connMaxDL
= tab
->GetTagByName(EC_TAG_CONN_MAX_DL
);
670 if (connMaxUL
&& connMaxDL
) {
671 s
<< wxString::Format(_("Bandwidth limits: Up: %u kB/s, Down: %u kB/s.\n"),
672 (uint16
)connMaxUL
->GetInt(),
673 (uint16
)connMaxDL
->GetInt());
678 for (int i
= 0; i
< response
->GetTagCount(); ++i
) {
679 const CECTag
*tag
= response
->GetTagByIndex(i
);
681 s
<< tag
->GetStringData() << wxT("\n");
687 CEC_ConnState_Tag
*connState
= (CEC_ConnState_Tag
*)response
->GetTagByName(EC_TAG_CONNSTATE
);
689 s
<< _("eD2k") << wxT(": ");
690 if (connState
->IsConnectedED2K()) {
691 CECTag
*server
= connState
->GetTagByName(EC_TAG_SERVER
);
692 CECTag
*serverName
= server
? server
->GetTagByName(EC_TAG_SERVER_NAME
) : NULL
;
693 if (server
&& serverName
) {
694 s
<< CFormat(_("Connected to %s %s %s")) %
695 serverName
->GetStringData() %
696 server
->GetIPv4Data().StringIP() %
697 (connState
->HasLowID() ? _("with LowID") : _("with HighID"));
699 } else if (connState
->IsConnectingED2K()) {
700 s
<< _("Now connecting");
702 s
<< _("Not connected");
704 s
<< wxT('\n') << _("Kad") << wxT(": ");
705 if (connState
->IsKadRunning()) {
706 if (connState
->IsConnectedKademlia()) {
707 s
<< _("Connected") << wxT(" (");
708 if (connState
->IsKadFirewalled()) {
709 s
<< _("firewalled");
715 s
<< _("Not connected");
718 s
<< _("Not running");
722 const CECTag
*tmpTag
;
723 if ((tmpTag
= response
->GetTagByName(EC_TAG_STATS_DL_SPEED
)) != 0) {
724 s
<< CFormat(_("\nDownload:\t%s")) % CastItoSpeed(tmpTag
->GetInt());
726 if ((tmpTag
= response
->GetTagByName(EC_TAG_STATS_UL_SPEED
)) != 0) {
727 s
<< CFormat(_("\nUpload:\t%s")) % CastItoSpeed(tmpTag
->GetInt());
729 if ((tmpTag
= response
->GetTagByName(EC_TAG_STATS_UL_QUEUE_LEN
)) != 0) {
730 s
<< wxString::Format(_("\nClients in queue:\t%d\n"), tmpTag
->GetInt());
732 if ((tmpTag
= response
->GetTagByName(EC_TAG_STATS_TOTAL_SRC_COUNT
)) != 0) {
733 s
<< wxString::Format(_("\nTotal sources:\t%d\n"), tmpTag
->GetInt());
737 case EC_OP_DLOAD_QUEUE
:
738 for(int i
= 0; i
< response
->GetTagCount(); ++i
) {
739 CEC_PartFile_Tag
*tag
=
740 (CEC_PartFile_Tag
*)response
->GetTagByIndex(i
);
742 uint64 filesize
, donesize
;
743 filesize
= tag
->SizeFull();
744 donesize
= tag
->SizeDone();
745 s
<< tag
->FileHashString() << wxT(" ") <<
747 wxString::Format(wxT("\n\t [%.1f%%] %4i/%4i "),
748 ((float)donesize
) / ((float)filesize
)*100.0,
749 (int)tag
->SourceCount() - (int)tag
->SourceNotCurrCount(),
750 (int)tag
->SourceCount()) <<
751 ((int)tag
->SourceCountA4AF() ? wxString::Format(wxT("+%2.2i "),(int)tag
->SourceCountA4AF()) : wxString(wxT(" "))) <<
752 ((int)tag
->SourceXferCount() ? wxString::Format(wxT("(%2.2i) - "),(int)tag
->SourceXferCount()) : wxString(wxT(" - "))) <<
753 tag
->GetFileStatusString();
754 s
<< wxT(" - ") << tag
->PartMetName();
755 if (tag
->Prio() < 10) {
756 s
<< wxT(" - ") << PriorityToStr((int)tag
->Prio(), 0);
758 s
<< wxT(" - ") << PriorityToStr((tag
->Prio() - 10), 1);
760 if ( tag
->SourceXferCount() > 0) {
761 s
<< wxT(" - ") + CastItoSpeed(tag
->Speed());
767 case EC_OP_ULOAD_QUEUE
:
768 for(int i
= 0; i
< response
->GetTagCount(); ++i
) {
769 const CECTag
*tag
= response
->GetTagByIndex(i
);
770 const CECTag
*clientName
= tag
? tag
->GetTagByName(EC_TAG_CLIENT_NAME
) : NULL
;
771 const CECTag
*partfileName
= tag
? tag
->GetTagByName(EC_TAG_PARTFILE_NAME
) : NULL
;
772 const CECTag
*partfileSizeXfer
= tag
? tag
->GetTagByName(EC_TAG_PARTFILE_SIZE_XFER
) : NULL
;
773 const CECTag
*partfileSpeed
= tag
? tag
->GetTagByName(EC_TAG_CLIENT_UP_SPEED
) : NULL
;
774 if (tag
&& clientName
&& partfileName
&& partfileSizeXfer
&& partfileSpeed
) {
776 wxString::Format(wxT("%10u "), tag
->GetInt()) <<
777 clientName
->GetStringData() << wxT(" ") <<
778 partfileName
->GetStringData() << wxT(" ") <<
779 CastItoXBytes(partfileSizeXfer
->GetInt()) << wxT(" ") <<
780 CastItoSpeed(partfileSpeed
->GetInt());
785 for (int i
= 0; i
< response
->GetTagCount(); ++i
) {
786 const CECTag
*tag
= response
->GetTagByIndex(i
);
788 s
<< tag
->GetStringData() << wxT("\n");
793 case EC_OP_SERVER_LIST
:
794 for(int i
= 0; i
< response
->GetTagCount(); i
++) {
795 const CECTag
*tag
= response
->GetTagByIndex(i
);
796 const CECTag
*serverName
= tag
? tag
->GetTagByName(EC_TAG_SERVER_NAME
) : NULL
;
797 if (tag
&& serverName
) {
798 wxString ip
= tag
->GetIPv4Data().StringIP();
799 ip
.Append(' ', 24 - ip
.Length());
800 s
<< ip
<< serverName
->GetStringData() << wxT("\n");
804 case EC_OP_STATSTREE
:
805 s
<< StatTree2Text((CEC_StatTree_Node_Tag
*)response
->GetTagByName(EC_TAG_STATTREE_NODE
), 0);
808 case EC_OP_SEARCH_RESULTS
:
809 m_Results_map
.clear();
810 s
<< wxString::Format(_("Number of search results: %i\n"),response
->GetTagCount());
811 for (int i
= 0;i
< response
->GetTagCount();i
++) {
812 CEC_SearchFile_Tag
*tag
= (CEC_SearchFile_Tag
*)response
->GetTagByIndex(i
);
813 //printf("Tag FileName: %s \n",(const char*)unicode2char(tag->FileName()));
815 m_Results_map
[i
] = new SearchFile(tag
);
816 //const CECTag *tag = response->GetTagByIndex(i);
819 ShowResults(m_Results_map
);
822 case EC_OP_SEARCH_PROGRESS
:
823 s
<< _("TODO - show progress of a search");
824 // gives compilation error!!
825 // const CECTag *tab = response->GetTagByNameSafe(EC_TAG_SEARCH_STATUS);
826 //s << wxString::Format(_("Search progress: %u %% \n"),(const char*)unicode2char(tab->GetStringData()));
829 s
<< wxString::Format(_("Received an unknown reply from the server, OpCode = %#x."), response
->GetOpCode());
834 void CamulecmdApp::OnInitCommandSet()
840 CaMuleExternalConnector::OnInitCommandSet();
842 m_commands
.AddCommand(wxT("Status"), CMD_ID_STATUS
, wxTRANSLATE("Show short status information."),
843 wxTRANSLATE("Show connection status, current up/download speeds, etc.\n"), CMD_PARAM_NEVER
);
845 m_commands
.AddCommand(wxT("Statistics"), CMD_ID_STATTREE
, wxTRANSLATE("Show full statistics tree."),
846 wxTRANSLATE("Optionally, a number in the range 0-255 can be passed as an argument to this\ncommand, which tells how many entries of the client version subtrees should be\nshown. Passing 0 or omitting it means 'unlimited'.\n\nExample: 'statistics 5' will show only the top 5 versions for each client type.\n"));
848 m_commands
.AddCommand(wxT("Shutdown"), CMD_ID_SHUTDOWN
, wxTRANSLATE("Shut down aMule."),
849 wxTRANSLATE("Shut down the remote running core (amule/amuled).\nThis will also shut down the text client, since it is unusable without a\nrunning core.\n"), CMD_PARAM_NEVER
);
851 tmp
= m_commands
.AddCommand(wxT("Reload"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Reloads the given object."), wxEmptyString
, CMD_PARAM_NEVER
);
852 tmp
->AddCommand(wxT("Shared"), CMD_ID_RELOAD_SHARED
, wxTRANSLATE("Reloads shared files list."), wxEmptyString
, CMD_PARAM_NEVER
);
853 tmp
->AddCommand(wxT("IPFilter"), CMD_ID_RELOAD_IPFILTER
, wxTRANSLATE("Reloads IP Filter table from file."), wxEmptyString
, CMD_PARAM_NEVER
);
855 tmp
= m_commands
.AddCommand(wxT("Connect"), CMD_ID_CONNECT
, wxTRANSLATE("Connect to the network."),
856 wxTRANSLATE("This will connect to all networks that are enabled in Preferences.\nYou may also optionally specify a server address in IP:Port form, to connect to\nthat server only. The IP must be a dotted decimal IPv4 address,\nor a resolvable DNS name."), CMD_PARAM_OPTIONAL
);
857 tmp
->AddCommand(wxT("ED2K"), CMD_ID_CONNECT_ED2K
, wxTRANSLATE("Connect to eD2k only."), wxEmptyString
, CMD_PARAM_NEVER
);
858 tmp
->AddCommand(wxT("Kad"), CMD_ID_CONNECT_KAD
, wxTRANSLATE("Connect to Kad only."), wxEmptyString
, CMD_PARAM_NEVER
);
860 tmp
= m_commands
.AddCommand(wxT("Disconnect"), CMD_ID_DISCONNECT
, wxTRANSLATE("Disconnect from the network."),
861 wxTRANSLATE("This will disconnect from all networks that are currently connected.\n"), CMD_PARAM_NEVER
);
862 tmp
->AddCommand(wxT("ED2K"), CMD_ID_DISCONNECT_ED2K
, wxTRANSLATE("Disconnect from eD2k only."), wxEmptyString
, CMD_PARAM_NEVER
);
863 tmp
->AddCommand(wxT("Kad"), CMD_ID_DISCONNECT_KAD
, wxTRANSLATE("Disconnect from Kad only."), wxEmptyString
, CMD_PARAM_NEVER
);
865 m_commands
.AddCommand(wxT("Add"), CMD_ID_ADDLINK
, wxTRANSLATE("Adds an eD2k or magnet link to core."),
866 wxTRANSLATE("The eD2k link to be added can be:\n*) a file link (ed2k://|file|...), it will be added to the download queue,\n*) a server link (ed2k://|server|...), it will be added to the server list,\n*) or a serverlist link, in which case all servers in the list will be added to the\n server list.\n\nThe magnet link must contain the eD2k hash and file length.\n"), CMD_PARAM_ALWAYS
);
868 tmp
= m_commands
.AddCommand(wxT("Set"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Set a preference value."),
869 wxEmptyString
, CMD_PARAM_NEVER
);
871 tmp2
= tmp
->AddCommand(wxT("IPFilter"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Set IPFilter preferences."), wxEmptyString
, CMD_PARAM_NEVER
);
872 tmp2
->AddCommand(wxT("On"), CMD_ID_SET_IPFILTER_ON
, wxTRANSLATE("Turn IP filtering on for both clients and servers."), wxEmptyString
, CMD_PARAM_NEVER
);
873 tmp2
->AddCommand(wxT("Off"), CMD_ID_SET_IPFILTER_OFF
, wxTRANSLATE("Turn IP filtering off for both clients and servers."), wxEmptyString
, CMD_PARAM_NEVER
);
874 tmp3
= tmp2
->AddCommand(wxT("Clients"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Enable/Disable IP filtering for clients."), wxEmptyString
, CMD_PARAM_NEVER
);
875 tmp3
->AddCommand(wxT("On"), CMD_ID_SET_IPFILTER_CLIENTS_ON
, wxTRANSLATE("Turn IP filtering on for clients."), wxEmptyString
, CMD_PARAM_NEVER
);
876 tmp3
->AddCommand(wxT("Off"), CMD_ID_SET_IPFILTER_CLIENTS_OFF
, wxTRANSLATE("Turn IP filtering off for clients."), wxEmptyString
, CMD_PARAM_NEVER
);
877 tmp3
= tmp2
->AddCommand(wxT("Servers"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Enable/Disable IP filtering for servers."), wxEmptyString
, CMD_PARAM_NEVER
);
878 tmp3
->AddCommand(wxT("On"), CMD_ID_SET_IPFILTER_SERVERS_ON
, wxTRANSLATE("Turn IP filtering on for servers."), wxEmptyString
, CMD_PARAM_NEVER
);
879 tmp3
->AddCommand(wxT("Off"), CMD_ID_SET_IPFILTER_SERVERS_OFF
, wxTRANSLATE("Turn IP filtering off for servers."), wxEmptyString
, CMD_PARAM_NEVER
);
880 tmp2
->AddCommand(wxT("Level"), CMD_ID_SET_IPFILTER_LEVEL
, wxTRANSLATE("Select IP filtering level."),
881 wxTRANSLATE("Valid filtering levels are in the range 0-255, and it's default (initial)\nvalue is 127.\n"), CMD_PARAM_ALWAYS
);
883 tmp2
= tmp
->AddCommand(wxT("BwLimit"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Set bandwidth limits."),
884 wxTRANSLATE("The value given to these commands has to be in kilobytes/sec.\n"), CMD_PARAM_NEVER
);
885 tmp2
->AddCommand(wxT("Up"), CMD_ID_SET_BWLIMIT_UP
, wxTRANSLATE("Set upload bandwidth limit."),
886 wxT("The given value must be in kilobytes/sec.\n"), CMD_PARAM_ALWAYS
);
887 tmp2
->AddCommand(wxT("Down"), CMD_ID_SET_BWLIMIT_DOWN
, wxTRANSLATE("Set download bandwidth limit."),
888 wxT("The given value must be in kilobytes/sec.\n"), CMD_PARAM_ALWAYS
);
890 tmp
= m_commands
.AddCommand(wxT("Get"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Get and display a preference value."),
891 wxEmptyString
, CMD_PARAM_NEVER
);
893 tmp2
= tmp
->AddCommand(wxT("IPFilter"), CMD_ID_GET_IPFILTER
, wxTRANSLATE("Get IPFilter preferences."), wxEmptyString
, CMD_PARAM_NEVER
);
894 tmp3
= tmp2
->AddCommand(wxT("State"), CMD_ID_GET_IPFILTER_STATE
, wxTRANSLATE("Get IPFilter state for both clients and servers."), wxEmptyString
, CMD_PARAM_NEVER
);
895 tmp3
->AddCommand(wxT("Clients"), CMD_ID_GET_IPFILTER_STATE_CLIENTS
, wxTRANSLATE("Get IPFilter state for clients only."), wxEmptyString
, CMD_PARAM_NEVER
);
896 tmp3
->AddCommand(wxT("Servers"), CMD_ID_GET_IPFILTER_STATE_SERVERS
, wxTRANSLATE("Get IPFilter state for servers only."), wxEmptyString
, CMD_PARAM_NEVER
);
897 tmp2
->AddCommand(wxT("Level"), CMD_ID_GET_IPFILTER_LEVEL
, wxTRANSLATE("Get IPFilter level."), wxEmptyString
, CMD_PARAM_NEVER
);
899 tmp
->AddCommand(wxT("BwLimits"), CMD_ID_GET_BWLIMITS
, wxTRANSLATE("Get bandwidth limits."), wxEmptyString
, CMD_PARAM_NEVER
);
901 tmp
= m_commands
.AddCommand(wxT("Search"), CMD_ID_SEARCH
, wxTRANSLATE("Makes a search."),
902 wxTRANSLATE("A search type has to be specified by giving the type:\n GLOBAL\n LOCAL\n KAD\nExample: 'search kad file' will execute a kad search for \"file\".\n"), CMD_PARAM_ALWAYS
);
903 tmp
->AddCommand(wxT("global"), CMD_ID_SEARCH_GLOBAL
, wxTRANSLATE("Executes a global search."), wxEmptyString
, CMD_PARAM_ALWAYS
);
904 tmp
->AddCommand(wxT("local"), CMD_ID_SEARCH_LOCAL
, wxTRANSLATE("Executes a local search"), wxEmptyString
, CMD_PARAM_ALWAYS
);
905 tmp
->AddCommand(wxT("kad"), CMD_ID_SEARCH_KAD
, wxTRANSLATE("Executes a kad search"), wxEmptyString
, CMD_PARAM_ALWAYS
);
907 m_commands
.AddCommand(wxT("Results"), CMD_ID_SEARCH_RESULTS
, wxTRANSLATE("Shows the results of the last search."),
908 wxTRANSLATE("Returns the results of the previous search.\n"), CMD_PARAM_NEVER
);
910 m_commands
.AddCommand(wxT("Progress"), CMD_ID_SEARCH_PROGRESS
, wxTRANSLATE("Shows the progress of a search."),
911 wxTRANSLATE("Shows the progress of a search.\n"), CMD_PARAM_NEVER
);
913 m_commands
.AddCommand(wxT("Download"), CMD_ID_DOWNLOAD
, wxTRANSLATE("Start downloading a file"),
914 wxTRANSLATE("The number of a file from the last search has to be given.\nExample: 'download 12' will start to download the file with the number 12 of the previous search.\n"), CMD_PARAM_ALWAYS
);
918 // TODO: These commands below need implementation and/or rewrite!
921 m_commands
.AddCommand(wxT("Pause"), CMD_ID_PAUSE
, wxTRANSLATE("Pause download."),
922 wxEmptyString
, CMD_PARAM_ALWAYS
);
924 m_commands
.AddCommand(wxT("Resume"), CMD_ID_RESUME
, wxTRANSLATE("Resume download."),
925 wxEmptyString
, CMD_PARAM_ALWAYS
);
927 m_commands
.AddCommand(wxT("Cancel"), CMD_ID_CANCEL
, wxTRANSLATE("Cancel download."),
928 wxEmptyString
, CMD_PARAM_ALWAYS
);
930 tmp
= m_commands
.AddCommand(wxT("Priority"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Set download priority."),
931 wxTRANSLATE("Set priority of a download to Low, Normal, High or Auto.\n"), CMD_PARAM_ALWAYS
);
932 tmp
->AddCommand(wxT("Low"), CMD_ID_PRIORITY_LOW
, wxTRANSLATE("Set priority to low."), wxEmptyString
, CMD_PARAM_ALWAYS
);
933 tmp
->AddCommand(wxT("Normal"), CMD_ID_PRIORITY_NORMAL
, wxTRANSLATE("Set priority to normal."), wxEmptyString
, CMD_PARAM_ALWAYS
);
934 tmp
->AddCommand(wxT("High"), CMD_ID_PRIORITY_HIGH
, wxTRANSLATE("Set priority to high."), wxEmptyString
, CMD_PARAM_ALWAYS
);
935 tmp
->AddCommand(wxT("Auto"), CMD_ID_PRIORITY_AUTO
, wxTRANSLATE("Set priority to auto."), wxEmptyString
, CMD_PARAM_ALWAYS
);
937 tmp
= m_commands
.AddCommand(wxT("Show"), CMD_ERR_INCOMPLETE
, wxTRANSLATE("Show queues/lists."),
938 wxTRANSLATE("Shows upload/download queue, server list or shared files list.\n"), CMD_PARAM_NEVER
);
939 tmp
->AddCommand(wxT("UL"), CMD_ID_SHOW_UL
, wxTRANSLATE("Show upload queue."), wxEmptyString
, CMD_PARAM_NEVER
);
940 tmp
->AddCommand(wxT("DL"), CMD_ID_SHOW_DL
, wxTRANSLATE("Show download queue."), wxEmptyString
, CMD_PARAM_NEVER
);
941 tmp
->AddCommand(wxT("Log"), CMD_ID_SHOW_LOG
, wxTRANSLATE("Show log."), wxEmptyString
, CMD_PARAM_NEVER
);
942 tmp
->AddCommand(wxT("Servers"), CMD_ID_SHOW_SERVERS
, wxTRANSLATE("Show servers list."), wxEmptyString
, CMD_PARAM_NEVER
);
943 // tmp->AddCommand(wxT("Shared"), CMD_ID_SHOW_SHARED, wxTRANSLATE("Show shared files list."), wxEmptyString, CMD_PARAM_NEVER);
945 m_commands
.AddCommand(wxT("Reset"), CMD_ID_RESET_LOG
, wxTRANSLATE("Reset log."), wxEmptyString
, CMD_PARAM_NEVER
);
948 // Deprecated commands, kept for backwards compatibility only.
951 #define DEPRECATED(OLDCMD, ID, NEWCMD, PARAM) \
952 m_commands.AddCommand(wxT(OLDCMD), CMD_ID_##ID | CMD_DEPRECATED, CFormat(wxTRANSLATE("Deprecated command, use '%s' instead.")) % wxT(NEWCMD), \
953 CFormat(wxTRANSLATE("This is a deprecated command, and may be removed in the future.\nUse '%s' instead.\n")) % wxT(NEWCMD), CMD_PARAM_##PARAM)
955 DEPRECATED("Stats", STATUS
, "Status", NEVER
);
956 DEPRECATED("SetIPFilter", SET_IPFILTER
, "Set IPFilter", OPTIONAL
);
957 DEPRECATED("GetIPLevel", GET_IPFILTER_LEVEL
, "Get IPFilter Level", NEVER
);
958 DEPRECATED("SetIPLevel", SET_IPFILTER_LEVEL
, "Set IPFilter Level", ALWAYS
);
959 DEPRECATED("IPLevel", SET_IPFILTER_LEVEL
, "Get/Set IPFilter Level", OPTIONAL
);
960 DEPRECATED("Servers", SHOW_SERVERS
, "Show Servers", NEVER
);
961 DEPRECATED("GetBWLimits", GET_BWLIMITS
, "Get BwLimits", NEVER
);
962 DEPRECATED("SetUpBWLimit", SET_BWLIMIT_UP
, "Set BwLimit Up", ALWAYS
);
963 DEPRECATED("SetDownBWLimit", SET_BWLIMIT_DOWN
, "Set BwLimit Down", ALWAYS
);
966 int CamulecmdApp::OnRun()
968 ConnectAndRun(wxT("aMulecmd"), wxT(VERSION
));
971 // File_checked_for_headers