-rw-r--r-- | DipstickDlg.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/DipstickDlg.cpp b/DipstickDlg.cpp index ace2aff..f27b219 100644 --- a/DipstickDlg.cpp +++ b/DipstickDlg.cpp @@ -60,126 +60,129 @@ void CAboutDlg::DoDataExchange(CDataExchange* pDX) //{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_KLEVERNET, OnKlevernet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDipstickDlg dialog
CDipstickDlg::CDipstickDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDipstickDlg::IDD, pParent),
m_DragPad(NULL), m_PingsPerHost(10), m_PingSize(32), m_TimeOut(5000), m_Interval(500),
m_SortCriteria(sortAvg), m_bShown(FALSE), m_MaxThreads(10), m_bExiting(FALSE),
m_bMSWorkAround(TRUE), m_MinSize(-1,-1), m_bAutoBest(TRUE), m_bSmartAdjust(TRUE),
m_bAdjustInnermost(TRUE), m_ActiveThreads(0), m_bIgnorelative(TRUE)
{
CWinApp *app = AfxGetApp();
ASSERT(app);
WORD hi,lo;
hi=app->GetProfileInt("Options","IntervalHi",HIWORD(m_Interval));
lo=app->GetProfileInt("Options","IntervalLo",LOWORD(m_Interval));
m_Interval=MAKELONG(lo,hi);
m_MaxThreads=app->GetProfileInt("Options","MaxThreads",m_MaxThreads);
m_PingSize=app->GetProfileInt("Options","PingSize",m_PingSize);
m_PingsPerHost=app->GetProfileInt("Options","PingsPerHost",m_PingsPerHost);
m_SortCriteria=app->GetProfileInt("Options","SortBy",m_SortCriteria);
hi=app->GetProfileInt("Options","TimeOutHi",HIWORD(m_TimeOut));
lo=app->GetProfileInt("Options","TimeOutLo",LOWORD(m_TimeOut));
m_TimeOut=MAKELONG(lo,hi);
m_bMSWorkAround = app->GetProfileInt("Options","InnermostURL",m_bMSWorkAround);
m_bAutoBest = app->GetProfileInt("Options","AutoBest",m_bAutoBest);
m_bSmartAdjust = app->GetProfileInt("Options","SmartAdjust",m_bSmartAdjust);
m_bAdjustInnermost = app->GetProfileInt("Options","AdjustInnermost",m_bAdjustInnermost);
m_bIgnorelative = app->GetProfileInt("Options","IgnoreRelative",m_bIgnorelative);
m_impexPath = app->GetProfileString("Options","ImportExportPath",m_impexPath);
//{{AFX_DATA_INIT(CDipstickDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bmpBack.LoadBitmap(IDB_DIABACK);
m_bmpBack.GetBitmap(&m_bitmapBack);
CString tmp;
VERIFY(tmp.LoadString(IDS_REGEX_HTMLURL));
VERIFY(m_reHTMLURL.Compile(tmp,CRegEx::regExtended|CRegEx::regIgnoreCase));
+ VERIFY(tmp.LoadString(IDS_REGEX_URL));
+ VERIFY(m_reURL.Compile(tmp,CRegEx::regExtended|CRegEx::regIgnoreCase));
}
CDipstickDlg::~CDipstickDlg()
{
}
void CDipstickDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDipstickDlg)
DDX_Control(pDX, IDC_ADVANCED, m_AdvancedCtl);
DDX_Control(pDX, ID_HELP, m_HelpCtl);
DDX_Control(pDX, IDC_EXIT, m_ExitCtl);
DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl);
DDX_Control(pDX, IDC_MANUALPING, m_ManualPingCtl);
DDX_Control(pDX, IDC_REMOVE, m_RemoveCtl);
DDX_Control(pDX, IDC_REPINGALL, m_RepingAllCtl);
DDX_Control(pDX, IDC_REPING, m_RepingCtl);
DDX_Control(pDX, IDC_CLEAR, m_ClearListCtl);
DDX_Control(pDX, IDC_HOSTLIST, m_HostList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDipstickDlg, CDialog)
//{{AFX_MSG_MAP(CDipstickDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
+ ON_MESSAGE(WM_DNP_URLSPING, OnURLSPing)
ON_MESSAGE(WM_DNP_URLPING, OnUrlPing)
ON_MESSAGE(WM_DNP_ACTIVITYCOUNT, OnActivityCount)
ON_MESSAGE(WM_DNP_UPDATEHOSTDATA, OnUpdateHostData)
ON_MESSAGE(WM_DNP_HTML, OnHTMLTransfer)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_HOSTLIST, OnColumnclickHostlist)
ON_WM_WINDOWPOSCHANGING()
ON_COMMAND(ID_DRAGPAD_OPTIONS, OnDragpadOptions)
ON_COMMAND(ID_DRAGPAD_SHOWMAINWINDOW, OnDragpadShowmainwindow)
ON_COMMAND(ID_DRAGPAD_HELP, OnDragpadHelp)
ON_COMMAND(ID_DRAGPAD_ABOUT, OnDragpadAbout)
ON_COMMAND(ID_DRAGPAD_EXIT, OnDragpadExit)
ON_BN_CLICKED(IDC_MANUALPING, OnManualping)
ON_COMMAND(ID_DRAGPAD_MANUALPING, OnDragpadManualping)
ON_COMMAND(ID_DRAGPAD_REPINGALL, OnDragpadRepingAll)
ON_COMMAND(ID_DRAGPAD_REMOVEALL, OnDragpadRemoveAll)
ON_BN_CLICKED(IDC_REPING, OnReping)
ON_BN_CLICKED(IDC_REPINGALL, OnRepingall)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_NOTIFY(LVN_INSERTITEM, IDC_HOSTLIST, OnInsertitemHostlist)
ON_NOTIFY(LVN_DELETEITEM, IDC_HOSTLIST, OnDeleteitemHostlist)
ON_NOTIFY(LVN_DELETEALLITEMS, IDC_HOSTLIST, OnDeleteallitemsHostlist)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_HOSTLIST, OnItemchangedHostlist)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
ON_NOTIFY(NM_RCLICK, IDC_HOSTLIST, OnRclickHostlist)
ON_COMMAND(ID_HOSTLIST_REPING, OnHostListReping)
ON_COMMAND(ID_HOSTLIST_REMOVE, OnHostListRemove)
ON_COMMAND(ID_HOSTLIST_REPINGALL, OnHostListRepingAll)
ON_COMMAND(ID_HOSTLIST_REMOVEALL, OnHostListRemoveAll)
ON_COMMAND(ID_HOSTLIST_OPENURL, OnHostListOpenURL)
ON_COMMAND(ID_HOSTLIST_PROPERTIES, OnHostListProperties)
ON_NOTIFY(NM_DBLCLK, IDC_HOSTLIST, OnDblclkHostlist)
ON_WM_CLOSE()
ON_WM_GETMINMAXINFO()
ON_WM_SIZE()
ON_BN_CLICKED(ID_HELP, OnHelp)
ON_NOTIFY(LVN_BEGINDRAG, IDC_HOSTLIST, OnBegindragHostlist)
ON_COMMAND(ID_HOSTLIST_PASTEURL, OnPasteurl)
ON_COMMAND(ID_HOSTLIST_COPYURL, OnHostlistCopyurl)
ON_WM_HELPINFO()
ON_WM_DROPFILES()
ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
ON_COMMAND(ID_ADVANCED_EXPORTLIST, OnAdvancedExportlist)
ON_COMMAND(ID_ADVANCED_IMPORTLIST, OnAdvancedImportlist)
ON_COMMAND(ID_DRAGPAD_PASTEURL, OnPasteurl)
ON_COMMAND(ID_DRAGPAD_ADVANCED_EXPORTLIST, OnDragpadAdvancedExportlist)
ON_COMMAND(ID_DRAGPAD_ADVANCED_IMPORTLIST, OnDragpadAdvancedImportlist)
//}}AFX_MSG_MAP
@@ -1140,168 +1143,207 @@ UINT cfNIF = RegisterClipboardFormat("Netscape Image Format"); }
if(pDO->IsDataAvailable(cfHTML)){
HGLOBAL hg = pDO->GetGlobalData(cfHTML);
ASSERT(hg);
LPCTSTR lps = (LPCTSTR)GlobalLock(hg);
ASSERT(lps);
BOOL rv = FALSE;
do{
static LPCTSTR v10 = "Version:1.0\r\n";
if(memcmp(v10,lps,strlen(v10)))
break;
static LPCTSTR strStartSelection = "StartSelection:";
static LPCTSTR strEndSelection = "EndSelection:";
static LPCTSTR strSourceURL = "SourceURL:";
LPTSTR subs = strstr(lps,strStartSelection);
if(!subs)
break;
LONG startSelection = atol(&subs[strlen(strStartSelection)]);
if(!startSelection)
break;
if(!(subs=strstr(lps,strEndSelection)))
break;
LONG endSelection = atol(&subs[strlen(strEndSelection)]);
if(!endSelection)
break;
if(!(subs=strstr(lps,strSourceURL)))
break;
subs = &subs[strlen(strSourceURL)];
LPTSTR eol = strchr(subs,'\r');
if(!eol)
break;
(*eol)=0;
CString sourceURL = subs;
if(!sourceURL.GetLength())
break;
TRACE0("SourceURL = "+sourceURL+"\n");
_xferHTML* xf = new _xferHTML;
VERIFY(xf->src.Crack(sourceURL));
LPTSTR htmlBuff = xf->html.GetBuffer(endSelection-startSelection+2);
ASSERT(htmlBuff);
memmove(htmlBuff,&lps[startSelection],endSelection-startSelection+1);
htmlBuff[endSelection-startSelection+1]=0;
xf->html.ReleaseBuffer();
if(bTestOnly){
rv = m_reHTMLURL.Match(xf->html);
delete xf;
}else{
PostMessage(WM_DNP_HTML,0,(LPARAM)xf);
+ rv = TRUE;
}
}while(FALSE);
GlobalUnlock(hg);
GlobalFree(hg);
return rv;
}
if(pDO->IsDataAvailable(cfNIF)){
if(!bTestOnly){
HGLOBAL hg = pDO->GetGlobalData(cfNIF);
ASSERT(hg);
LPVOID lpv = GlobalLock(hg);
ASSERT(lpv);
struct _nif {
BYTE data[0x20];
DWORD m_offDescr;
DWORD m_offURL;
DWORD m_offToImage;
} *nif = (_nif*)lpv;
PostMessage(WM_DNP_URLPING,0,(LPARAM)new CString((LPCTSTR)&nif->data[nif->m_offURL]));
GlobalUnlock(hg);
GlobalFree(hg);
}
return TRUE;
}
if(pDO->IsDataAvailable(CF_TEXT)){
- if(!bTestOnly){
+ BOOL rv = FALSE;
HGLOBAL hg = pDO->GetGlobalData(CF_TEXT);
ASSERT(hg);
LPVOID lpv = GlobalLock(hg);
ASSERT(lpv);
+ if(bTestOnly){
+ rv = m_reURL.Match((LPCSTR)lpv);
+ }else{
+ CString sel = (LPCSTR)lpv;
+ if(m_reURL.Match(sel)) {
+ rv = TRUE;
+ CString tmp = m_reURL.GetMatch(CRegEx::matchPostMatch);
+ if(m_reURL.Match(tmp)) {
+ PostMessage(WM_DNP_URLSPING,0,(LPARAM)new CString((LPCSTR)lpv));
+ }else{
PostMessage(WM_DNP_URLPING,0,(LPARAM)new CString((LPCTSTR)lpv));
+ }
+ }
+ }
GlobalUnlock(hg);
GlobalFree(hg);
- }
- return TRUE;
+ return rv;
}
return FALSE;
}
LRESULT CDipstickDlg::OnHTMLTransfer(WPARAM wP, LPARAM lP)
{
_xferHTML* xf = (_xferHTML*)lP;
CSelectURLsDlg su;
su.m_bAdjust = m_bSmartAdjust;
su.m_bAdjustInnermost = m_bAdjustInnermost;
BeginWaitCursor();
while(m_reHTMLURL.Match(xf->html)){
CString url = m_reHTMLURL.GetMatch(1);
xf->html = m_reHTMLURL.GetMatch(CRegEx::matchPostMatch);
if(CCrackURL::GetHostName(url)==url){
if(m_bIgnorelative)
continue;
CCrackURL cracked;
VERIFY(cracked.Crack(url));
cracked.Adjust(xf->src);
url = cracked.Build();
}
if(!su.m_URLs.Find(url))
VERIFY(su.m_URLs.AddTail(url));
}
EndWaitCursor();
delete xf;
if(su.DoModal()==IDOK){
POSITION p = su.m_URLs.GetHeadPosition();
while(p){
CString url = su.m_URLs.GetNext(p);
PostMessage(WM_DNP_URLPING,0,(LPARAM)new CString(url));
}
}
return 0;
}
+LRESULT CDipstickDlg::OnURLSPing(WPARAM wP,LPARAM lP)
+{
+CString *sel = (CString*)lP;
+TRACE1("URLS: %s\n",(LPCTSTR)*sel);
+CSelectURLsDlg su;
+ su.m_bAdjust = m_bSmartAdjust;
+ su.m_bAdjustInnermost = m_bAdjustInnermost;
+ BeginWaitCursor();
+ while(m_reURL.Match(*sel)){
+ CString url = m_reURL.GetMatch(CRegEx::matchMatch);
+ (*sel) = m_reURL.GetMatch(CRegEx::matchPostMatch);
+ if(!su.m_URLs.Find(url))
+ VERIFY(su.m_URLs.AddTail(url));
+ }
+ EndWaitCursor();
+ delete sel;
+ if(su.DoModal()==IDOK){
+ POSITION p = su.m_URLs.GetHeadPosition();
+ while(p){
+ CString url = su.m_URLs.GetNext(p);
+ PostMessage(WM_DNP_URLPING,0,(LPARAM)new CString(url));
+ }
+ }
+ return 0;
+}
+
UINT CPingyHost::PingProc(LPVOID pParam)
{
CPingyHost* pThis = (CPingyHost*)pParam;
ASSERT(pThis->m_Daddy);
return pThis->DoPing();
}
UINT CPingyHost::DoPing()
{
CSingleLock slock(&m_mutex);
if(!slock.Lock(2000)){
m_Status.LoadString(IDS_PS_FAILEDTOLOCK);
return 1;
}
m_Pinging = TRUE;
m_bToPing = FALSE;
VERIFY(m_Daddy->m_eveStartup.SetEvent());
m_Daddy->PostMessage(WM_DNP_UPDATEHOSTDATA,0,(LPARAM)this);
in_addr ip;
UINT packets, lost;
packets=lost=0;
CICMP* pICMP = NULL;
UINT dataSize = m_Daddy->m_PingSize;
int ploss = 100;
do{
if(m_HostName.IsEmpty()){
ip.s_addr = m_IP;
hostent *he = gethostbyaddr((char*)&ip,4,PF_INET);
if(!he)
m_HostName.Empty();
else
m_HostName = he->h_name;
}else{
hostent *he = gethostbyname(m_HostName);
if(!he){
m_Status.LoadString(IDS_PS_FAILEDTORESOLVE);
m_IP = 0;
break;
}
memmove(&ip.s_addr,he->h_addr,sizeof(ip.s_addr));
m_IP = ip.s_addr;
}
pICMP = CICMP::CreateICMP();
if(!(pICMP && pICMP->Initialize())){
m_Status.LoadString(IDS_PS_UNABLETOICMP);
break;
}
m_Daddy->PostMessage(WM_DNP_UPDATEHOSTDATA,0,(LPARAM)this);
|