// Load the DXF file. If the zlib support is compiled in wxWidgets, // supports also the ".dxf.gz" gzip compressed files. void TestGLCanvas::LoadDXF(const wxString& filename) { wxFileInputStream stream(filename); if (stream.IsOk()) #if wxUSE_ZLIB { if (filename.Right(3).Lower() == wxT(".gz")) { wxZlibInputStream zstream(stream); m_renderer.Load(zstream); } else { m_renderer.Load(stream); } } #else { m_renderer.Load(stream); } #endif }
size_t CUrlOpt::OnWriteData( void *buffer, size_t size, size_t nmemb, void *userp ) { if (m_type==URL_OPT_FETCH) { #if 0 wxMemoryInputStream istream((char*)buffer, size*nmemb); wxZlibInputStream zstream(istream, wxZLIB_GZIP); wxString str; wxStringOutputStream ostream(&str); zstream.Read(ostream); m_content += str; #endif m_pBuf = (char*)realloc(m_pBuf, m_length + size*nmemb); memcpy(m_pBuf+m_length, buffer, size*nmemb); m_length += size*nmemb; wxLogMessage("OnWriteData nmemb*size:%d m_length:%d", nmemb*size, m_length); return nmemb*size; } else if (m_type == URL_OPT_REFRESH) return 0; return 0; }
CURLcode CUrlOpt::Run() { CURL *curl; CURLcode res; char *pUrl, *pPorxy=NULL; m_content.Clear(); if (m_url.IsEmpty()) return (CURLcode)-1; curl = curl_easy_init(); if(!curl){ wxLogError("curl_easy_init fail\n"); return CURLE_FAILED_INIT; } pUrl = (char*)calloc(m_url.Length()+1, 1); wxStrcpy(pUrl, m_url.c_str()); if (!m_proxy.IsEmpty()) { pPorxy= (char*)calloc(m_proxy.Length()+1, 1); wxStrcpy(pPorxy, m_proxy.c_str()); } #ifdef _DEBUG curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_curl_debug_callback); #endif curl_easy_setopt(curl, CURLOPT_URL, pUrl); #if 1 curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curl, CURLOPT_TIMEOUT, m_timeout); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, my_header_callback); curl_easy_setopt(curl, CURLOPT_HEADERDATA, this); if (m_bGzip) curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"); #endif if (!m_proxy.IsEmpty()){ curl_easy_setopt(curl, CURLOPT_PROXY, pPorxy); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); } m_length = 0x0; m_pBuf = NULL; res = curl_easy_perform(curl); curl_easy_cleanup(curl); m_ret = res; if (pUrl) free(pUrl); if (pPorxy) free(pPorxy); if (res==0) { if (m_bGzip) { wxMemoryInputStream istream((char*)m_pBuf, m_length); wxZlibInputStream zstream(istream, wxZLIB_GZIP); wxStringOutputStream ostream(&m_content); zstream.Read(ostream); } else { wxConvAuto *pConv; if (m_bGBK) pConv = new wxConvAuto(wxFONTENCODING_CP936); else pConv = new wxConvAuto(wxFONTENCODING_UTF8); m_content = wxString(m_pBuf, *pConv, m_length); delete pConv; } } return res; }