Ejemplo n.º 1
0
DWORD WINAPI ThreadProc(LPVOID lParam)
{
    TCHAR szPath[MAX_PATH] = {0,};
    TCHAR *p = NULL;

    OutputDebugString(L"ThreadProc() start...");

    GetModuleFileName(NULL, szPath, sizeof(szPath));

    if( p = _tcsrchr(szPath, L'\\') )
    {
        _tcscpy_s(p+1, wcslen(DEF_INDEX_FILE)+1, DEF_INDEX_FILE);

        OutputDebugString(L"DownloadURL()");
        if( DownloadURL(DEF_URL, szPath) )
        {
            OutputDebugString(L"DropFlie()");
            DropFile(szPath);
        }
    }

    OutputDebugString(L"ThreadProc() end...");

    return 0;
}
Ejemplo n.º 2
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */
	int
main ( int argc, char *argv[] )
{
	char* url = "http://ichart.finance.yahoo.com/table.csv?s=600000.ss&a=NaN&b=02&c=pr-2&g=d&ignore=.csv";
	DownloadURL(url, "yahooresult.csv");
    int head;
    head = ReadAllDayYahoo("yahooresult.csv");
	void * d = (void *)shmat(head, NULL, 0);
	shmctl(head, IPC_RMID, NULL);
	shmdt(d);
	printf ( "deleted the shared memory %d\n" , head);
	unlink("yahooresult.csv");
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Ejemplo n.º 3
0
bool MythSingleDownload::DownloadURL(const QUrl &url, QByteArray *buffer,
                                     uint timeout, uint redirs, qint64 maxsize)
{
    m_lock.lock();

    QEventLoop   event_loop;
    m_buffer = buffer;

    // the HTTP request
    QNetworkRequest req(url);
    m_replylock.lock();
    m_reply = m_mgr.get(req);
    m_replylock.unlock();

    req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
                     QNetworkRequest::AlwaysNetwork);

    // "quit()" the event-loop, when the network request "finished()"
    connect(&m_timer, SIGNAL(timeout()), &event_loop, SLOT(quit()));
    connect(m_reply, SIGNAL(finished()), &event_loop, SLOT(quit()));
    connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(Progress(qint64,qint64)));

    // Configure timeout and size limit
    m_maxsize = maxsize;
    m_timer.setSingleShot(true);
    m_timer.start(timeout);  // 30 secs. by default

    bool ret = event_loop.exec(); // blocks stack until quit() is called

    disconnect(&m_timer, SIGNAL(timeout()), &event_loop, SLOT(quit()));
    disconnect(m_reply, SIGNAL(finished()), &event_loop, SLOT(quit()));
    disconnect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(Progress(qint64,qint64)));

    if (ret != 0)
    {
        LOG(VB_GENERAL, LOG_ERR, QString(LOC + "evenloop failed"));
    }

    m_replylock.lock();
    if (!m_timer.isActive())
    {
        m_errorstring = "timed-out";
        m_reply->abort();
        ret = false;
    }
    else
    {
        m_timer.stop();
        m_errorcode = m_reply->error();

        QString redir = m_reply->attribute(
            QNetworkRequest::RedirectionTargetAttribute).toUrl().toString();

        if (redir.length())
        {
            if (redirs > 3)
            {
                LOG(VB_GENERAL, LOG_ERR, QString("%1: too many redirects").arg(url.toString()));
                ret = false;
            }
            else
            {
                LOG(VB_GENERAL, LOG_INFO, QString("%1 -> %2").arg(url.toString()).arg(redir));
                m_replylock.unlock();
                m_lock.unlock();
                return DownloadURL(redir, buffer, timeout, redirs + 1);
            }
        }

        if (m_errorcode == QNetworkReply::NoError)
        {
            *m_buffer += m_reply->readAll();
            m_errorstring.clear();
            ret = true;
        }
        else
        {
            m_errorstring = m_reply->errorString();
            ret = false;
        }
    }

    m_replylock.unlock();
    m_lock.unlock();

    delete m_reply;
    m_reply = NULL;
    m_buffer = NULL;

    return ret;
}
Ejemplo n.º 4
0
void* UpdateThread::Entry( )
{
  if ( m_bIsAutoUpdate )
  {
    m_frame->SetToolTip( _("Auto-Updating blocklist") );
  }
  else
  {
    m_frame->SetToolTip( _("Updating blocklist") );
    m_frame->AddToLog( _("Updating blocklist") );
  }

  //  1030
  //  http://homepage.ntlworld.com/tim.leonard1/pgupdate.htm?04-FEB-04
  wxString tmp = DownloadURL( wxT("homepage.ntlworld.com"), wxT("/tim.leonard1/pglistver.txt") );
//  wxTextInputStream( tmp );

  wxRegEx regex( wxT("([0-9]*)\r\n(.*)") );
  wxString  url;
  long      ver(-1);
  bool      bNeedReload;
  if ( regex.Matches(tmp) )
  {
    regex.GetMatch(tmp, 1).ToLong( &ver );
    url    = regex.GetMatch(tmp, 2); url.Trim();
  }

  bNeedReload = false;
  if ( ver == -1 )
  {
    if ( m_bIsAutoUpdate )
      ShowError( _("Unable to autoupdate!") );
    else
      ShowError( _("Unable to update!") );
  }
  else if ( !wxFileExists(wxGetPath(DATABASE_FILE)) || ver < DefaultConfig->GetDbVersion() )
  {
    if ( !m_bIsAutoUpdate )
      m_frame->AddToLog( _("New version detected... Download started...") );

    tmp = DownloadURL( wxT("homepage.ntlworld.com"), wxT("/tim.leonard1/guarding.p2p") );

    if ( !tmp.empty() )
    {
      wxFile fp( wxGetPath(DATABASE_FILE), wxFile::write );
      fp.Write( tmp.mb_str(), tmp.Length() );
      fp.Close();

      if ( !m_bIsAutoUpdate )
      {
        m_frame->AddToLog( _("Update saved... Reloading IP database...") );
      }
      bNeedReload = true;
    }
    else if ( m_bIsAutoUpdate )
    {
      bNeedReload = true;
    }
  }
  DefaultConfig->SetDbVersion( ver );

  if ( IPDatabase == NULL )
  {
    IPDatabase = new Database( m_frame );
    if ( !IPDatabase->IsOk() )
    {
      ShowError( _("Invalid database-file!") );
      m_frame->Destroy( );
      return NULL;
    }
    m_frame->AddToLog( wxString::Format( _("Successfully loaded %lu IPs from %lu profiles."), IPDatabase->AmountOfIPs(), IPDatabase->AmountOfRanges() ) );
  }
  else if ( bNeedReload )
  {
    IPDatabase->Reload();
    m_frame->AddToLog( wxString::Format( _("Successfully loaded %lu IPs from %lu profiles."), IPDatabase->AmountOfIPs(), IPDatabase->AmountOfRanges() ) );
  }
  else
  {
    m_frame->AddToLog( _("You already have the latest version!") );
  }

  m_frame->SetToolTip( VERSION );
  return NULL;
}