/* return file contenets as qstring from local or remote file ... like php*/
{
qDebug() << "###1 curl_get_contents "<< fullFileName;
QString xdcookiefile, xml_export_file, wwwnetfile;
if (fullFileName.contains("https://", Qt::CaseInsensitive)) {
return inside;
}
Init();
qDebug() << "###2 curl_get_contents "<< fullFileName;
xdcookiefile
= QString( "%1biscotti.html" ).
arg( WORK_CACHEDIR
);
xml_export_file
= QString( "%1_xml_export.xml" ).
arg( WORK_CACHEDIR
);
wwwnetfile
= QString( "%1wwwfull.html" ).
arg( WORK_CACHEDIR
);
if (IsNetFile( fullFileName ) )
{
qt_unlink(wwwnetfile);
qDebug() << "###3 curl_get_contents "<< fullFileName;
/*QString xgeturl = fullFileName; http://shop.ecoplanet.ch/info.php */
char *localfile = lop.data();
char *xwcookiefile = der.data();
char *url = ba.data();
qDebug() << "### entra save to "<< localfile;
qDebug() << "### get url "<< url;
CURL *curl_handle;
FILE *outfile;
curl_global_init(CURL_GLOBAL_ALL);
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
outfile = fopen(localfile, "w");
if (outfile!=NULL) {
/* CURLOPT_COOKIE and must have CURLOPT_COOKIEJAR char * (file to write same as php) */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
#if defined Q_WS_MAC
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mac QT4 / PPK_W @ciz.ch" );
#endif
#if defined(Q_WS_WIN)
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Windows QT4 / PPK_W @ciz.ch" );
#endif
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 2);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , 20 );
curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);
if (curl_easy_perform(curl_handle)==CURLE_OK) {
fclose(outfile);
if (is_file(wwwnetfile)) {
inside = ReadFile( wwwnetfile );
if (inside.size() > 1) {
ERROR_MSG = "";
#if defined Q_WORKS_PEND
/* not delete file */
#else
qt_unlink(wwwnetfile);
#endif
}
}
} else {
ERROR_MSG = "Error time out to get remote file";
}
}
/* return grab result from local file */
return inside;
}
/* ok is a fake normal local file init ..... */
inside = ReadFile( fullFileName );
return inside;
}
/* return file contenets as qstring from local or remote file ... like php*/
QString curl_get_contents( QString fullFileName )
{
QString inside = "";
qDebug() << "###1 curl_get_contents "<< fullFileName;
QString xdcookiefile, xml_export_file, wwwnetfile;
if (fullFileName.contains("https://", Qt::CaseInsensitive)) {
return inside;
}
Init();
qDebug() << "###2 curl_get_contents "<< fullFileName;
xdcookiefile = QString( "%1biscotti.html" ).arg( WORK_CACHEDIR );
xml_export_file = QString( "%1_xml_export.xml" ).arg( WORK_CACHEDIR );
wwwnetfile = QString( "%1wwwfull.html" ).arg( WORK_CACHEDIR );
if (IsNetFile( fullFileName ) )
{
qt_unlink(wwwnetfile);
qDebug() << "###3 curl_get_contents "<< fullFileName;
/*QString xgeturl = fullFileName; http://shop.ecoplanet.ch/info.php */
QByteArray lop = wwwnetfile.toAscii();
char *localfile = lop.data();
QByteArray der = xdcookiefile.toAscii();
char *xwcookiefile = der.data();
QByteArray ba = fullFileName.toAscii();
char *url = ba.data();
qDebug() << "### entra save to "<< localfile;
qDebug() << "### get url "<< url;
CURL *curl_handle;
FILE *outfile;
curl_global_init(CURL_GLOBAL_ALL);
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
outfile = fopen(localfile, "w");
if (outfile!=NULL) {
/* CURLOPT_COOKIE and must have CURLOPT_COOKIEJAR char * (file to write same as php) */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
#if defined Q_WS_MAC
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mac QT4 / PPK_W @ciz.ch" );
#endif
#if defined(Q_WS_WIN)
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Windows QT4 / PPK_W @ciz.ch" );
#endif
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 2);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , 20 );
curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);
if (curl_easy_perform(curl_handle)==CURLE_OK) {
fclose(outfile);
if (is_file(wwwnetfile)) {
inside = ReadFile( wwwnetfile );
if (inside.size() > 1) {
ERROR_MSG = "";
#if defined Q_WORKS_PEND
/* not delete file */
#else
qt_unlink(wwwnetfile);
#endif
}
}
} else {
ERROR_MSG = "Error time out to get remote file";
}
}
/* return grab result from local file */
return inside;
}
/* ok is a fake normal local file init ..... */
inside = ReadFile( fullFileName );
return inside;
}
To copy to clipboard, switch view to plain text mode
Bookmarks