【问题标题】:Filter Libcurl Debug Message过滤 Libcurl 调试消息
【发布时间】:2013-12-26 11:13:31
【问题描述】:

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

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

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] 

【问题讨论】:

    标签: c++ ftp wxwidgets libcurl


    【解决方案1】:

    首先通过在 curl_easy_setopt 中将verbose 设置为1L 即CURLOPT_VERBOSE 来启用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;
        }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-17
      • 2018-10-18
      • 1970-01-01
      • 2013-10-07
      • 2020-03-31
      • 2014-07-22
      • 1970-01-01
      相关资源
      最近更新 更多