过滤Libcurl调试消息

时间:2013-12-26 11:13:31

标签: c++ ftp wxwidgets libcurl

是否可以过滤调试数据功能文本?我希望一次显示命令而另一次显示完整输出(我想要例如过滤掉Adding handle: send: 0)。我一直收到很多消息。我想要像Filezilla Short消息一样好的东西。

这是我的调试功能代码,下面是一条消息。我已启用详细信息

int Uploader::DebugDataCallBack(CURL* handle, curl_infotype infotype, char* msg, size_t size, void* f)
{
    int level= 1; //debug info 0-None, 1-necessary 2 - All TODO: Should come from config
    switch(level) //error level
    {
        case 0:
        {
            break; //do nothing
        }
        case 1:
        {
            //only necessary, skip headers
            if(infotype==CURLINFO_TEXT)
            {
                static_cast<Uploader*>(f)->SendMessage(wxString(msg));
            }
        }
        default:
        {
            //full debug messages
            static_cast<Uploader*>(f)->SendMessage(wxString(msg));
        }
    }

    return 0;//must return 0
}

----------Thu Dec 26 14:14:40 2013---------- 
STATE: INIT => CONNECT handle 0x7fffd0001a08; line 998 (connection #-5000) 
 [14:14:40]
STATE: INIT => CONNECT handle 0x7fffd0001a08; line 998 (connection #-5000) 
 [14:14:40]
Rebuilt URL to: ftp://ftp.mysite.com/
 [14:14:40]
Rebuilt URL to: ftp://ftp.mysite.com/
 [14:14:40]
About to connect() to ftp.mysite.com port 21 (#0)
 [14:14:40]
About to connect() to ftp.mysite.com port 21 (#0)
 [14:14:40]
  Trying 31.170.162.203...
 [14:14:40]
  Trying 31.170.162.203...
 [14:14:40]
Adding handle: conn: 0x7fffd0013b48
 [14:14:40]
Adding handle: conn: 0x7fffd0013b48
 [14:14:40]
Adding handle: send: 0
 [14:14:40]
Adding handle: send: 0
 [14:14:40]
Adding handle: recv: 0
 [14:14:40]
Adding handle: recv: 0
 [14:14:40]
Curl_addHandleToPipeline: length: 1
 [14:14:40]
Curl_addHandleToPipeline: length: 1
 [14:14:40]
0x7fffd0001a08 is at send pipe head!
 [14:14:40]
0x7fffd0001a08 is at send pipe head!
 [14:14:40]
- Conn 0 (0x7fffd0013b48) send_pipe: 1, recv_pipe: 0
 [14:14:40]
- Conn 0 (0x7fffd0013b48) send_pipe: 1, recv_pipe: 0
 [14:14:40]
STATE: CONNECT => WAITCONNECT handle 0x7fffd0001a08; line 1045 (connection #0) 
 [14:14:40]
STATE: CONNECT => WAITCONNECT handle 0x7fffd0001a08; line 1045 (connection #0) 
 [14:14:40]
Connected to ftp.mysite.com (31.170.162.203) port 21 (#0)
 [14:14:40]
Connected to ftp.mysite.com (31.170.162.203) port 21 (#0)
 [14:14:40]
FTP 0x7fffd0013fe0 (line 3174) state change from STOP to WAIT220
 [14:14:40]
FTP 0x7fffd0013fe0 (line 3174) state change from STOP to WAIT220
 [14:14:40]
STATE: WAITCONNECT => PROTOCONNECT handle 0x7fffd0001a08; line 1158 (connection #0) 
 [14:14:40]
STATE: WAITCONNECT => PROTOCONNECT handle 0x7fffd0001a08; line 1158 (connection #0) 
 [14:14:40] 

1 个答案:

答案 0 :(得分:0)

首先通过在curl_easy_setopt中将详细信息设置为CURLOPT_VERBOSE的1L来启用curl。它设置了调试功能,即CURLOPT_DEBUGFUNCTION来接收调试消息。然后使用代码信息类型来过滤掉你想要的东西。如果你想获得命令/响应,就像我想要从Header输入/输出消息。这是一段代码,只是为了展示它!

switch(infotype)
{
    case CURLINFO_HEADER_OUT:
    {
        wxString message = _("COMMAND: ")+wxString(msg);
        SendMessage(message);
        break; 
    }
    case CURLINFO_HEADER_IN:
    {
        wxString message = _("RESPONSE: ")+wxString(msg);
        SendMessage(message);
        break;
    }

}