summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2006-10-13 19:13:18 (UTC)
committer Michael Krelin <hacker@klever.net>2006-10-13 19:13:18 (UTC)
commit325e7fc43721df3efaa8539190fada6e6e3aa8fa (patch) (side-by-side diff)
treeec03bf74e17eb497e0fcd31b521192b0b14bd83e
parent577427e68ef10a4d2b75d28e42b22952ae3bcf23 (diff)
downloadpumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.zip
pumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.tar.gz
pumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.tar.bz2
Enabled logging of outgoing errors, added reject with explicit error message
when file is too large for the block size set. git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@192 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--PumpKINDlg.cpp7
-rw-r--r--pumpkin.rc5
-rw-r--r--resource.h2
3 files changed, 10 insertions, 4 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp
index 2a01918..bb15211 100644
--- a/PumpKINDlg.cpp
+++ b/PumpKINDlg.cpp
@@ -1,2163 +1,2166 @@
// PumpKINDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PumpKIN.h"
#include "PumpKINDlg.h"
#include "ACLTargetCombo.h"
#include "PropsServer.h"
#include "PropsNetwork.h"
#include "PropsSounds.h"
#include "PropsACL.h"
#include "ConfirmRRQDlg.h"
#include "ConfirmWRQDlg.h"
#include "RequestDlg.h"
#include "Resolver.h"
#include "Retrier.h"
#include "Trayer.h"
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CXferSocket, CAsyncSocket)
IMPLEMENT_DYNAMIC(CWRQSocket, CXferSocket)
IMPLEMENT_DYNAMIC(CRRQSocket, CXferSocket)
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnKlevernet();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(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()
/////////////////////////////////////////////////////////////////////////////
// CPumpKINDlg dialog
CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPumpKINDlg::IDD, pParent), m_MinSize(0,0)
{
m_Listener.m_Daddy = this;
m_bListen = TRUE;
m_ListenPort = 69;
m_bTFTPSubdirs = TRUE;
m_RRQMode = rrqAlwaysConfirm;
m_WRQMode = wrqAlwaysConfirm;
m_TFTPTimeOut = CTimeSpan(0,0,0,30);
m_RetryTimeOut = CTimeSpan(0,0,0,10);
m_LogLength = 100;
m_SpeakPort = 69;
m_PromptTimeOut=30;
m_bShown=TRUE;
m_bExiting=FALSE;
m_BlockSize=1024;
m_bnw.AssignSound("(bang)",IDR_WAVE_RING,CBellsNWhistles::CBang::bangResource);
m_bnw.AssignSound("(done)",IDR_WAVE_FINISHED,CBellsNWhistles::CBang::bangResource);
m_bnw.AssignSound("(oops)",IDR_WAVE_ABORTED,CBellsNWhistles::CBang::bangResource);
m_bnw.AssignSound("(none)",(int)0,CBellsNWhistles::CBang::bangNone);
m_bnwRequest="(bang)"; m_bnwSuccess="(done)";
m_bnwAbort="(oops)";
//{{AFX_DATA_INIT(CPumpKINDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bmpBack.LoadBitmap(IDB_BACKGROUND);
m_bmpBack.GetBitmap(&m_bitmapBack);
m_Retrier = new CRetrier(this);
ASSERT(m_Retrier);
m_Trayer = new CTrayer(this);
ASSERT(m_Trayer);
/* Ensure we're backwards compatible */
ASSERT(CPumpKINDlg::rrqGiveAll==0);
ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1);
ASSERT(CPumpKINDlg::rrqDenyAll==2);
ASSERT(CPumpKINDlg::wrqTakeAll==0);
ASSERT(CPumpKINDlg::wrqConfirmIfExists==1);
ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2);
ASSERT(CPumpKINDlg::wrqDenyAll==3);
/* -- */
LoadSettings();
}
void CPumpKINDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPumpKINDlg)
DDX_Control(pDX, ID_HELP, m_HelpCtl);
DDX_Control(pDX, IDC_PUT, m_PutCtl);
DDX_Control(pDX, IDC_GET, m_GetCtl);
DDX_Control(pDX, IDC_EXIT, m_ExitCtl);
DDX_Control(pDX, IDC_LISTENING, m_ListenCtl);
DDX_Control(pDX, IDC_ABORT, m_AbortCtl);
DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl);
DDX_Control(pDX, IDC_LOG, m_Log);
DDX_Control(pDX, IDC_CONNECTIONS, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPumpKINDlg, CDialog)
//{{AFX_MSG_MAP(CPumpKINDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CREATE()
ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_PUT, OnPut)
ON_BN_CLICKED(IDC_GET, OnGet)
ON_NOTIFY(LVN_DELETEALLITEMS, IDC_CONNECTIONS, OnDeleteallitemsConnections)
ON_NOTIFY(LVN_DELETEITEM, IDC_CONNECTIONS, OnDeleteitemConnections)
ON_NOTIFY(LVN_INSERTITEM, IDC_CONNECTIONS, OnInsertitemConnections)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_CONNECTIONS, OnItemchangedConnections)
ON_BN_CLICKED(IDC_ABORT, OnAbort)
ON_WM_CLOSE()
ON_COMMAND(ID_TRAY_SHOWPUMPKINWINDOW, OnTrayShowpumpkinwindow)
ON_COMMAND(ID_TRAY_LISTEN, OnTrayListen)
ON_COMMAND(ID_TRAY_EXIT, OnTrayExit)
ON_COMMAND(ID_TRAY_ABOUTPUMPKIN, OnTrayAboutpumpkin)
ON_COMMAND(ID_TRAY_FETCHFILE, OnTrayFetchfile)
ON_COMMAND(ID_TRAY_HELP, OnTrayHelp)
ON_COMMAND(ID_TRAY_OPTIONS, OnTrayOptions)
ON_COMMAND(ID_TRAY_SENDFILE, OnTraySendfile)
ON_WM_WINDOWPOSCHANGING()
ON_LBN_SELCHANGE(IDC_LOG, OnSelchangeLog)
ON_COMMAND(ID_TRAY_OPENFILESFOLDER, OnTrayOpenfilesfolder)
ON_WM_DROPFILES()
ON_BN_CLICKED(ID_HELP, OnHelp)
ON_BN_CLICKED(IDC_LISTENING, OnListening)
ON_WM_GETMINMAXINFO()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPumpKINDlg message handlers
BOOL CPumpKINDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
VERIFY(m_Retrier->Create(NULL,"PumpKIN-Retrier",WS_CHILD,CRect(0,0,0,0),this,0));
m_Images.Create(16,16,TRUE,2,1);
m_iRRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_RRQ));
m_iWRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_WRQ));
ASSERT(m_iRRQ>=0);
ASSERT(m_iWRQ>=0);
m_List.SetImageList(&m_Images,LVSIL_NORMAL);
m_List.SetImageList(&m_Images,LVSIL_SMALL);
m_List.SetImageList(&m_Images,LVSIL_STATE);
m_List.SetTextColor(RGB(255,255,0)); // Yellow
m_List.SetTextBkColor(RGB(12,167,0)); // Green
m_List.SetBkColor(RGB(12,167,0)); // Green
CRect listrc;
m_List.GetClientRect(&listrc);
m_List.InsertColumn(0,"File",LVCFMT_LEFT,listrc.Width()-((listrc.Width()/7)*3+listrc.Width()*2/7),subitemFile);
m_List.InsertColumn(1,"type",LVCFMT_CENTER,listrc.Width()/7,subitemType);
m_List.InsertColumn(2,"peer",LVCFMT_LEFT,listrc.Width()*2/7,subitemPeer);
m_List.InsertColumn(3,"ACK",LVCFMT_RIGHT,listrc.Width()/7,subitemBytes);
m_List.InsertColumn(4,"tsize",LVCFMT_RIGHT,listrc.Width()/7,subitemTSize);
LogLine(IDS_LOG_START);
SetupButtons();
CRect wrci, wrco;
GetWindowRect(&wrco);
GetClientRect(&wrci);
CRect brc;
m_GetCtl.GetWindowRect(&brc); ScreenToClient(&brc);
m_rightGapButtons = wrci.right-brc.right;
m_List.GetWindowRect(&brc); ScreenToClient(&brc);
m_rightGapList = wrci.right-brc.right;
m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
m_bottomGapListen = wrci.bottom-brc.bottom;
m_Log.GetWindowRect(&brc); ScreenToClient(&brc);
m_bottomGapLog = wrci.bottom-brc.bottom;
m_MinSize.cx = wrco.Width(); m_MinSize.cy=wrco.Height();
CRect rc, drc;
GetWindowRect(rc);
GetDesktopWindow()->GetWindowRect(drc);
SetWindowPos(NULL,drc.right-6-rc.Width(),6,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
if(m_bShown)
ShowWindow(SW_SHOW);
else
ShowWindow(SW_HIDE);
m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
// CG: The following block was added by the ToolTips component.
{
// Create the ToolTip control.
m_tooltip.Create(this);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(&m_List,IDC_CONNECTIONS);
m_tooltip.AddTool(GetDlgItem(IDC_PUT),IDC_PUT);
m_tooltip.AddTool(GetDlgItem(IDC_GET),IDC_GET);
m_tooltip.AddTool(&m_AbortCtl,IDC_ABORT);
m_tooltip.AddTool(GetDlgItem(IDC_OPTIONS),IDC_OPTIONS);
m_tooltip.AddTool(GetDlgItem(IDC_EXIT),IDC_EXIT);
m_tooltip.AddTool(GetDlgItem(ID_HELP),ID_HELP);
m_tooltip.AddTool(GetDlgItem(IDC_LOG),IDC_LOG);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CPumpKINDlg::OnDestroy()
{
SaveSettings();
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.cbSize=sizeof(nid);
nid.hWnd=m_Trayer->m_hWnd;
nid.uID=IDC_TRAYICON;
nid.uFlags=0;
VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid));
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
POSITION p = m_LogTimes.GetStartPosition();
while(p){
CTime *t,*tt;
m_LogTimes.GetNextAssoc(p,t,tt);
ASSERT(t && tt && t==tt);
delete t;
}
// *** Abort and cleanup transfers
m_LogTimes.RemoveAll();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPumpKINDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC pDC(this);
CDC bmpDC;
bmpDC.CreateCompatibleDC(&pDC);
bmpDC.SelectObject(&m_bmpBack);
CRect rc;
GetClientRect(&rc);
for(int x=-m_bitmapBack.bmWidth*2/4;x<rc.Width();x+=m_bitmapBack.bmWidth)
for(int y=-m_bitmapBack.bmHeight*2/4;y<rc.Height();y+=m_bitmapBack.bmHeight)
pDC.BitBlt(x,y,m_bitmapBack.bmWidth,m_bitmapBack.bmHeight,&bmpDC,0,0,SRCCOPY);
bmpDC.DeleteDC();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPumpKINDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
if(!m_Listener.SetListen(m_bListen)) {
m_bListen=FALSE;
TRACE0("Failed to create socket\n");
AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
}
if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){
TRACE0("Failed to create trayer\n");
return -1;
}
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.cbSize=sizeof(nid);
nid.hWnd=m_Trayer->m_hWnd;
nid.uID=IDC_TRAYICON;
nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
nid.uCallbackMessage=WM_TRAYICON;
nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// *** Load from resource
strcpy(nid.szTip,"PumpKIN");
VERIFY(Shell_NotifyIcon(NIM_ADD,&nid));
return 0;
}
void CListenSocket::OnReceive(int nErrorCode)
{
ASSERT(m_Daddy);
if(nErrorCode){
m_Daddy->LogLine(IDS_LOG_LISTENRECEIVEERROR);
return;
}
DWORD fionread = 0;
VERIFY(IOCtl(FIONREAD,&fionread)); // *** Do some checking on the value acquired
tftp *tftpRQ = tftp::Allocate(fionread);
ASSERT(tftpRQ);
SOCKADDR_IN sin;
if(!tftpRQ->Receive(this,fionread,&sin)){
m_Daddy->LogLine(IDS_LOG_LISTENACCEPTERROR);
delete tftpRQ;
return;
}
#ifndef NDEBUG
CString tmp;
tmp.Format("%u - %s - %u\n",tftpRQ->Opcode(),inet_ntoa(sin.sin_addr),sin.sin_port);
TRACE0(tmp);
#endif
POSITION p = m_Daddy->m_Xfers.GetStartPosition();
while(p){
SOCKET key;
CXferSocket *sock;
m_Daddy->m_Xfers.GetNextAssoc(p,key,sock);
ASSERT(sock);
if(sock->m_Peer.sin_addr.s_addr==sin.sin_addr.s_addr && sock->m_Peer.sin_port==sin.sin_port){
TRACE0("Ignoring request which we are already processing\n");
delete tftpRQ;
return;
}
}
switch(tftpRQ->Opcode()){
case tftp::opRRQ:
// Read Request
{
CString tmp;
tmp.Format(IDS_LOG_RRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr));
m_Daddy->LogLine(tmp);
CRRQSocket *s = new CRRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin);
ASSERT(s);
tftpRQ->GetOptions(&s->m_Options);
if(!s->Create())
s->Destroy(FALSE);
}
break;
case tftp::opWRQ:
// Write Request
{
CString tmp;
tmp.Format(IDS_LOG_WRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr));
m_Daddy->LogLine(tmp);
CWRQSocket *s = new CWRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin);
ASSERT(s);
tftpRQ->GetOptions(&s->m_Options);
if(!s->Create(NULL,NULL))
s->Destroy(FALSE);
}
break;
default:
m_Daddy->LogLine(IDS_LOG_LISTENOPCODE);
delete tftpRQ;
return;
}
delete tftpRQ;
}
BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin)
{
ASSERT(socket);
int saddrLen = sizeof(SOCKADDR_IN);
length = sin ?
socket->ReceiveFrom(udpBase(),maxLength,(SOCKADDR*)sin,&saddrLen)
:
socket->Receive(udpBase(),maxLength)
;
if(!length)
return FALSE;
if(length==(tftpLength)SOCKET_ERROR)
return FALSE;
return TRUE;
}
UINT tftp::Opcode()
{
return REVERSEBYTES(opcode);
}
CString tftp::rqFileName()
{
ASSERT(length);
ASSERT(Opcode()==opRRQ || Opcode()==opWRQ);
CString rv;
if(memchr(&data.m_RQ.data,0,length-sizeof(opcode)))
rv = (LPCTSTR)data.m_RQ.data;
return rv;
}
CString tftp::rqType()
{
ASSERT(length);
ASSERT(Opcode()==opRRQ || Opcode()==opWRQ);
CString rv;
char *tmp = (char*)memchr(&data.m_RQ.data,0,length-sizeof(opcode));
if(tmp++)
rv = (LPCTSTR)tmp;
return rv;
}
UINT tftp::GetOptions(tftp::tftpOptions* ops)
{
ASSERT(length);
ASSERT(Opcode()==opRRQ || Opcode()==opWRQ || Opcode()==opOACK);
ASSERT(ops);
tftpOptions& o = *ops;
LPSTR base = (LPSTR)&data.m_RQ.data;
UINT basePtr = 0;
if(Opcode()==opRRQ || Opcode()==opWRQ){
base = (LPSTR)memchr(&data.m_RQ.data,0,length-sizeof(opcode));
if(!base)
return 0;
base++;
basePtr = (base-(LPSTR)&data.m_RQ.data);
base = (LPSTR)memchr(base,0,length-basePtr);
if(!base)
return 0;
base++;
basePtr = (base-(LPSTR)&data.m_RQ.data);
}
ops->RemoveAll();
UINT rv = 0;
while(basePtr<(length-sizeof(opcode))){
CString onam = (LPSTR)&data.m_RQ.data[basePtr];
basePtr+=onam.GetLength()+1;
CString oval = (LPSTR)&data.m_RQ.data[basePtr];
basePtr+=oval.GetLength()+1;
onam.MakeLower();
o[onam]=oval;
rv++;
}
return rv;
}
tftp::tftp()
{
length=0;
}
void CXferSocket::OnSend(int nErrorCode)
{
if(nErrorCode){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERSEND);
return;
}
if(!m_Queue.IsEmpty()){
tftp *p = m_Queue.GetHead();
ASSERT(p);
m_Queue.RemoveHead();
if(!p->Send(this,&m_Peer)){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERUDPSEND);
}
delete p;
}
DoSelect();
if(m_Queue.IsEmpty()){
switch(state){
case stateDeny:
Destroy(FALSE);
break;
case stateFinish:
Destroy(TRUE);
break;
}
}
}
BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr)
{
ASSERT(socket);
int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN));
if(rv!=length)
return FALSE;
return TRUE;
}
void CXferSocket::DoSelect(BOOL do_select)
{
if(m_Peer.sin_addr.s_addr!=INADDR_NONE)
AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE));
}
void CXferSocket::OnReceive(int nErrorCode)
{
if(nErrorCode){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERRECEIVE);
return;
}
ASSERT(m_Daddy);
DWORD fionread = 0;
VERIFY(IOCtl(FIONREAD,&fionread));
tftp *p = tftp::Allocate(fionread);
ASSERT(p);
SOCKADDR_IN sin;
if(!p->Receive(this,fionread,&sin)){
m_Daddy->LogLine(IDS_LOG_XFERUDPRECEIVE);
delete p;
}else
if(m_Peer.sin_addr.s_addr==INADDR_NONE){
m_Peer.sin_addr=sin.sin_addr;
m_Peer.sin_port=sin.sin_port;
}
BOOL alive = TRUE;
if(state==stateInit){
state=stateXfer;
m_Peer.sin_port=sin.sin_port;
UpdateList();
}
if(sin.sin_addr.s_addr!=m_Peer.sin_addr.s_addr || sin.sin_port!=m_Peer.sin_port){
m_Daddy->LogLine(IDS_LOG_XFERSOURCETID);
// *** Bounce it!
}else{
alive = OnTFTP(p);
}
delete p;
if(alive){
DoSelect();
ResetTimeout();
}
}
void CXferSocket::SetPeer(SOCKADDR_IN *sin)
{
ASSERT(sin);
memmove(&m_Peer,sin,sizeof(m_Peer));
}
void CXferSocket::UpdateList()
{
ASSERT(m_Daddy);
LV_FINDINFO lvf;
memset(&lvf,0,sizeof(lvf));
lvf.flags=LVFI_PARAM;
lvf.lParam=(LPARAM)this;
int i = m_Daddy->m_List.FindItem(&lvf);
if(i<0){
ASSERT(IsKindOf(RUNTIME_CLASS(CRRQSocket)) || IsKindOf(RUNTIME_CLASS(CWRQSocket)));
i=m_Daddy->m_List.InsertItem(0,m_FileName,IsKindOf(RUNTIME_CLASS(CRRQSocket))?m_Daddy->m_iRRQ:m_Daddy->m_iWRQ);
ASSERT(!(i<0));
m_Daddy->m_List.SetItemData(i,(DWORD)this);
}
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemType,m_Type);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemPeer,inet_ntoa(m_Peer.sin_addr));
CString tmp;
tmp.Format(IDS_FMT_BYTES,GetACK());
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp);
if(m_xferSize>=0){
tmp.Format(IDS_FMT_BYTES,m_xferSize);
m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp);
}
}
CXferSocket::CXferSocket()
: m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
m_blkSize(512), m_timeOut(30), m_xferSize(-1),
m__blkSize(512), m__timeOut(30)
{
m_Daddy=NULL;
m_Peer.sin_addr.s_addr=INADDR_NONE;
m_Peer.sin_family=AF_INET;
state=stateNone;
}
ULONG CXferSocket::GetACK()
{
return 0;
}
CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin)
: m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
m_blkSize(512), m_timeOut(30), m_xferSize(-1),
m__blkSize(512), m__timeOut(30)
{
m_Peer.sin_family=AF_INET;
state=stateNone;
ASSERT(daddy);
m_Daddy=daddy;
m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds();
if(sin){
m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr;
m_Peer.sin_port=sin->sin_port;
}else
m_Peer.sin_addr.s_addr=INADDR_NONE;
m_FileName=fileName;
m_Type=type;
}
BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
{
if(!CAsyncSocket::Create(0,SOCK_DGRAM))
return FALSE;
ASSERT(m_Daddy);
ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
m_Daddy->m_Xfers[m_hSocket]=this;
CString lFile = localFile?localFile:m_FileName;
TurnSlashes(lFile,TRUE);
UpdateList();
if(!localFile){ // Check only for incoming requests
if(CheckBadRelativeness(m_FileName)){
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr);
if(atar<0)
atar = m_Daddy->m_RRQMode;
switch(atar){
case CPumpKINDlg::rrqGiveAll:
break;
case CPumpKINDlg::rrqAlwaysConfirm:
if(ConfirmRequest())
break;
default:
TRACE1("Unexpected access target: %d\n",atar);
case CPumpKINDlg::rrqDenyAll:
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
}
CString fn = localFile?ApplyRootGently(lFile):ApplyRoot(lFile);
CFileException e;
if(!m_File.Open(fn,CFile::modeRead|CFile::shareDenyWrite,&e)){
if(localFile){
CString tmp;
tmp.Format(IDS_LOG_FAILEDLOCALFILE,fn);
m_Daddy->LogLine(tmp);
return FALSE;
}
Deny(&e);
return TRUE;
}
m_xferSize=m_File.GetLength(); // *** HANDLE EXCEPTION
if(hostName){
m_HostName=hostName;
CString tmp;
tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName);
m_Daddy->LogLine(tmp);
CString inAddr = hostName;
int at = inAddr.Find('@');
if(at>=0)
inAddr=inAddr.Mid(at+1);
if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
ASSERT(!m_wndResolver);
m_wndResolver = new CResolver(this);
ASSERT(m_wndResolver);
return m_wndResolver->Resolve();
}
else
OnHostKnown();
}else{
tftp::tftpOptions o;
CString v;
if(m_Options.Lookup(tftpoBSize,v)){
m__blkSize=atoi(v);
if(m__blkSize){
m_blkSize=m__blkSize;
v.Format("%u",m_blkSize);
o[tftpoBSize]=v;
}
}
if(m_Options.Lookup(tftpoTSize,v)){
v.Format("%lu",m_xferSize);
o[tftpoTSize]=v;
}
if(m_Options.Lookup(tftpoTOut,v)){
m__timeOut=atoi(v);
if(m__timeOut){
m_timeOut=m__timeOut;
v.Format("%u",m_timeOut);
o[tftpoTOut]=v;
}
}
+ // XXX: see if we can enforce our preference regarding block size here.
+ if(m_xferSize >= (m_blkSize<<16)) {
+ Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG);
+ return TRUE;
+ }
state = stateXfer;
m_ACK=0;
if(o.GetCount()){
tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o));
ASSERT(p);
p->SetOpcode(tftp::opOACK);
p->data.m_OACK.Set(&o);
PostTFTP(p,TRUE);
}else
DoXfer();
}
return TRUE;
}
CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
: CXferSocket(daddy,fileName,type,sin)
{
m_ACK=0;
m_LastSlack=0;
}
UINT tftp::tftpERROR::tftpSize(LPCTSTR msg)
{
return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1;
}
tftp* tftp::Allocate(UINT tftpSize)
{
ASSERT(tftpSize);
tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize];
ASSERT(rv);
rv->length=tftpSize;
return rv;
}
void tftp::errSet(UINT code,LPCTSTR msg)
{
ASSERT(this);
ASSERT(length>=data.m_ERROR.tftpSize(msg));
strcpy((char*)data.m_ERROR.data,msg);
data.m_ERROR.SetCode(code);
}
void CXferSocket::PostTFTP(tftp* p,BOOL retryable)
{
ASSERT(p);
m_Queue.AddTail(p);
DoSelect();
if(!m_bRetry){
if(retryable)
SetTry(p);
else
SetTry();
}
ResetTimeout();
}
void CXferSocket::Deny(UINT errCode,UINT errID)
{
PostError(errCode,errID);
state=stateDeny;
}
void CRRQSocket::DoXfer()
{
tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize));
ASSERT(p);
p->SetOpcode(tftp::opDATA);
TRY{
m_File.Seek(m_ACK*m_blkSize,CFile::begin);
int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize);
p->data.m_DATA.SetBlock(m_ACK+1);
p->length=p->length-m_blkSize+bytes;
m_LastSlack = m_blkSize-bytes;
PostTFTP(p);
if(bytes<m_blkSize){
state=stateClosing; m_ACKtoClose = m_ACK+1;
}
}CATCH(CFileException,e){
Deny(e);
}END_CATCH
}
UINT tftp::tftpDATA::tftpSize(UINT blkSize)
{
return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA)
-sizeof(BYTE)+blkSize;
}
void CXferSocket::Deny(CFileException* e)
{
PostError(e);
state=stateDeny;
}
void CXferSocket::PostError(UINT errCode,UINT errID)
{
CString msg;
msg.LoadString(errID);
ASSERT(m_Daddy);
-/* // ***
CString tmp;
tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg);
m_Daddy->LogLine(tmp);
- */
tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg));
err->SetOpcode(tftp::opERROR);
err->errSet(errCode,msg);
PostTFTP(err);
}
void CXferSocket::PostError(CFileException* e)
{
UINT eCode;
UINT eMsgID;
switch(e->m_cause){
case CFileException::fileNotFound:
eCode=tftp::errNotFound;
eMsgID=IDS_TFTP_ERROR_NOTFOUND;
break;
case CFileException::accessDenied:
eCode=tftp::errAccessViolation;
eMsgID=IDS_TFTP_ERROR_ACCESS;
break;
case CFileException::directoryFull:
eCode=tftp::errDiskFull;
eMsgID=IDS_TFTP_ERROR_DIRFULL;
break;
case CFileException::sharingViolation:
eCode=tftp::errAccessViolation;
eMsgID=IDS_TFTP_ERROR_SHARING;
break;
case CFileException::diskFull:
eCode=tftp::errDiskFull;
eMsgID=IDS_TFTP_ERROR_DISKFULL;
break;
default:
eCode=tftp::errUndefined;
eMsgID=IDS_TFTP_ERROR_UNDEFINED;
break;
}
PostError(eCode,eMsgID);
}
ULONG CRRQSocket::GetACK(void)
{
return (m_ACK*m_blkSize)-m_LastSlack;
}
BOOL CRRQSocket::OnTFTP(tftp* p)
{
BOOL rv = TRUE;
switch(p->Opcode()){
case tftp::opOACK:
{
m_ACK=0;
ASSERT(state!=stateFinish);
tftp::tftpOptions o;
if(p->GetOptions(&o)){
CString v;
if(o.Lookup(tftpoBSize,v)){
m_blkSize=atoi(v);
if(!m_blkSize){ // *** More sanity checks
Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
rv = TRUE;
break;
}
}
if(o.Lookup(tftpoTOut,v)){
m_timeOut=atoi(v);
if(!m_timeOut){ // *** More sanity checks
Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
rv = TRUE;
break;
}
}
if(o.Lookup(tftpoXResume,v)){
m_ACK=atoi(v);
}
}
UpdateList();
DoXfer();
}
break;
case tftp::opACK:
m_ACK=p->data.m_ACK.Block();
if(state==stateClosing && m_ACK==m_ACKtoClose) {
state = stateFinish;
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
m_Daddy->LogLine(tmp);
rv = FALSE;
DoSelect(TRUE);
}else if(state!=stateFinish){
UpdateList();
DoXfer();
}
break;
case tftp::opERROR:
{
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
m_Daddy->LogLine(tmp);
}
Destroy(FALSE);
rv = FALSE;
break;
default:
{
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
m_Daddy->LogLine(tmp);
// *** Self destruct maybe??
}
break;
}
return rv;
}
BOOL CWRQSocket::OnTFTP(tftp* p)
{
switch(p->Opcode()){
case tftp::opOACK:
ASSERT(state!=stateFinish);
{
if(m_bResume)
m_ACK=m_File.GetLength()/m_blkSize;
else
m_ACK=0;
tftp::tftpOptions o;
if(p->GetOptions(&o)){
CString v;
if(o.Lookup(tftpoBSize,v)){
m_blkSize=atoi(v);
if(!m_blkSize){ // *** More sanity checks
Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
return TRUE;
}
}
if(o.Lookup(tftpoTOut,v)){
m_timeOut=atoi(v);
if(!m_timeOut){ // *** More sanity checks
Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
return TRUE;
}
}
if(o.Lookup(tftpoTSize,v)){
m_xferSize=atoi(v);
}
}
UpdateList();
DoXfer();
}
break;
case tftp::opDATA:
{
UINT block = p->data.m_DATA.Block();
TRY{
m_File.Seek((block-1)*m_blkSize,CFile::begin);
int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize);
if(bytes){
m_File.Write(p->data.m_DATA.data,bytes);
// *** Move to the other place where we can do it not that often
m_File.SetLength(m_File.GetPosition());
}
if(bytes<m_blkSize){
state=stateFinish;
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName);
m_Daddy->LogLine(tmp);
}
m_ACK=block;
m_LastSlack=m_blkSize-bytes;
UpdateList();
DoXfer();
}CATCH(CFileException,e){
Deny(e);
}END_CATCH
}
break;
case tftp::opERROR:
{
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
m_Daddy->LogLine(tmp);
}
Destroy(FALSE);
return FALSE;
default:
{
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
m_Daddy->LogLine(tmp);
// *** Self destruct maybe??
}
break;
}
return TRUE;
}
void tftp::SetOpcode(WORD op)
{
opcode = REVERSEBYTES(op);
}
void tftp::tftpDATA::SetBlock(WORD b)
{
block=REVERSEBYTES(b);
}
WORD tftp::tftpDATA::Block()
{
return REVERSEBYTES(block);
}
WORD tftp::tftpACK::Block()
{
return REVERSEBYTES(block);
}
void tftp::tftpACK::SetBlock(WORD b)
{
block = REVERSEBYTES(b);
}
WORD tftp::tftpERROR::Code()
{
return REVERSEBYTES(code);
}
void tftp::tftpERROR::SetCode(WORD c)
{
code = REVERSEBYTES(c);
}
CString tftp::errMessage()
{
CString rv;
if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code)))
rv = (LPCTSTR)data.m_ERROR.data;
return rv;
}
void CXferSocket::Destroy(BOOL success)
{
if(m_wndResolver){
delete m_wndResolver;
m_wndResolver=NULL;
}
SetTry();
m_Daddy->m_bnw.StartSound(
success
? m_Daddy->m_bnwSuccess
: m_Daddy->m_bnwAbort
);
if(m_File.m_hFile!=CFile::hFileNull){
TRY{
m_File.Close();
}CATCH(CFileException,e){
TRACE0("Error closing file\n");
}END_CATCH
}
ASSERT(m_Daddy);
m_Daddy->KillTimer(m_hSocket);
m_Daddy->m_Xfers.RemoveKey(m_hSocket);
LV_FINDINFO lvf;
memset(&lvf,0,sizeof(lvf));
lvf.flags=LVFI_PARAM;
lvf.lParam=(LPARAM)this;
int i = m_Daddy->m_List.FindItem(&lvf);
if(i>=0)
m_Daddy->m_List.DeleteItem(i);
delete this;
}
void CPumpKINDlg::LogLineToScreen(LPCTSTR str)
{
ASSERT(m_LogLength);
while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){
CTime *t = (CTime*)m_Log.GetItemData(0);
if(((DWORD)t)!=LB_ERR){
ASSERT(t);
m_LogTimes.RemoveKey(t);
delete t;
}
m_Log.DeleteString(0);
}
int i = m_Log.AddString(str);
ASSERT(i!=LB_ERR);
CTime *t = new CTime(CTime::GetCurrentTime());
m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t));
m_Log.SetCurSel(i);
}
void CPumpKINDlg::LogLine(UINT msgID)
{
CString tmp;
tmp.Format(msgID);
LogLine(tmp);
}
void CXferSocket::TurnSlashes(CString& fn,BOOL bBack)
{
int s = fn.Find(bBack?'/':'\\');
while(s>=0){
fn.SetAt(s,bBack?'\\':'/');
s = fn.Find(bBack?'/':'\\');
}
}
CString CXferSocket::ApplyRoot(LPCTSTR fileName)
{
ASSERT(m_Daddy);
CString fn = fileName;
CString rv = m_Daddy->m_TFTPRoot;
if(rv.IsEmpty())
rv = ".";
if(rv[rv.GetLength()-1]!='\\')
rv+="\\";
while((!fn.IsEmpty()) && fn[0]=='\\')
fn=fn.Mid(1);
rv+=fn;
return rv;
}
void CPumpKINDlg::OnOptions()
{
CPropertySheet cps(IDS_TITLE_OPTIONS,this);
CPropsServer server;
CPropsNetwork network;
CPropsSounds sounds;
CPropsACL acl;
server.m_RRQMode=m_RRQMode;
server.m_TFTPRoot=m_TFTPRoot;
server.m_TFTPSubdirs=m_bTFTPSubdirs;
server.m_WRQMode=m_WRQMode;
server.m_PromptTimeOut=m_PromptTimeOut;
server.m_LogFile=m_LogFile;
network.m_ListenPort=m_ListenPort;
network.m_SpeakPort=m_SpeakPort;
network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds();
network.m_BlockSize=m_BlockSize;
sounds.m_Request = m_bnwRequest;
sounds.m_Success = m_bnwSuccess;
sounds.m_Abort = m_bnwAbort;
acl.m_rulist = m_aclRules;
cps.AddPage(&server);
cps.AddPage(&network);
cps.AddPage(&sounds);
cps.AddPage(&acl);
if(cps.DoModal()==IDOK){
m_RRQMode=server.m_RRQMode;
m_TFTPRoot=server.m_TFTPRoot;
m_bTFTPSubdirs=server.m_TFTPSubdirs;
m_WRQMode=server.m_WRQMode;
m_PromptTimeOut=server.m_PromptTimeOut;
m_LogFile=server.m_LogFile;
m_ListenPort=network.m_ListenPort;
m_SpeakPort=network.m_SpeakPort;
m_TFTPTimeOut=CTimeSpan(network.m_TimeOut);
m_BlockSize=network.m_BlockSize;
m_bnwRequest = sounds.m_Request;
m_bnwSuccess = sounds.m_Success;
m_bnwAbort = sounds.m_Abort;
m_aclRules = acl.m_rulist;
m_lastlogerr.Empty();
}
}
BOOL CRRQSocket::ConfirmRequest()
{
CConfirmRRQDlg cd(NULL);
cd.m_Daddy=this;
cd.m_File=m_FileName;
cd.m_Host=inet_ntoa(m_Peer.sin_addr);
if(cd.DoModal()==IDOK)
return TRUE;
return FALSE;
}
CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
: CXferSocket(daddy,fileName,type,sin)
{
state=stateNone;
m_ACK=0;
m_LastSlack=0;
m_bResume=FALSE;
}
BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
{
if(!CAsyncSocket::Create(0,SOCK_DGRAM))
return FALSE;
ASSERT(m_Daddy);
ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
m_Daddy->m_Xfers[m_hSocket]=this;
UpdateList();
CString lf;
if(!localFile) {
lf = m_FileName;
TurnSlashes(lf,TRUE);
}
CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf);
if(!localFile){ // This is an incoming request..
if(CheckBadRelativeness(m_FileName)){
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
BOOL exists;
if(!_access((LPCTSTR)fn,0))
m_Rename=exists=TRUE;
else
m_Rename=exists=FALSE;
int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr);
if(atar<0)
atar=m_Daddy->m_WRQMode;
switch(atar){
case CPumpKINDlg::wrqTakeAll:
if(exists){
if(!RenameFile(fn)){
Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME);
return TRUE;
}
}
break;
case CPumpKINDlg::wrqConfirmIfExists:
if(!exists)
break;
case CPumpKINDlg::wrqAlwaysConfirm:
if(exists)
m_bResume=TRUE;
if(ConfirmRequest()){
if(m_Rename){
RenameFile(fn);
if(SaveAs(fn))
break;
}else
break;
}
default:
TRACE1("Unexpected access target: %d\n",atar);
case CPumpKINDlg::wrqDenyAll:
Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
return TRUE;
}
}
CFileException e;
if(!m_File.Open(
fn,
m_bResume
?(CFile::modeWrite|CFile::shareDenyWrite)
:(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite),
&e
)){
if(localFile){ // Outgoing request
CString tmp;
tmp.Format(IDS_LOG_FAILEDTOOPEN,fn);
m_Daddy->LogLine(tmp);
return FALSE;
}else{
Deny(&e);
return TRUE;
}
}
if(hostName){
m_HostName=hostName;
CString tmp;
tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName);
m_Daddy->LogLine(tmp);
CString inAddr = hostName;
int at = inAddr.Find('@');
if(at>=0)
inAddr=inAddr.Mid(at+1);
if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
ASSERT(!m_wndResolver);
m_wndResolver = new CResolver(this);
ASSERT(m_wndResolver);
return m_wndResolver->Resolve();
}else{
OnHostKnown();
return TRUE;
}
}
CString v;
tftp::tftpOptions oack;
if(m_Options.Lookup(tftpoTSize,v)){
m_xferSize=atol(v);
if(!m_xferSize){
Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE);
return TRUE;
}
}
if(m_Options.Lookup(tftpoBSize,v)){
m_blkSize=atoi(v);
if(!m_blkSize){ // *** Do more about sanity check
Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
return TRUE;
}
v.Format("%u",m_blkSize);
oack[tftpoBSize]=v;
}
if(m_Options.Lookup(tftpoTOut,v)){
m_timeOut=atoi(v);
if(!m_timeOut){ // *** Do more about sanity check
Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
return TRUE;
}
v.Format("%u",m_timeOut);
oack[tftpoTOut]=v;
}
if(m_Options.Lookup(tftpoXResume,v) && m_bResume){
m_ACK=m_File.GetLength()/m_blkSize;
v.Format("%u",m_ACK);
oack[tftpoXResume]=v;
}else
m_ACK=0;
state=stateXfer;
if(oack.GetCount()){
tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack));
ASSERT(p);
p->SetOpcode(tftp::opOACK);
p->data.m_OACK.Set(&oack);
PostTFTP(p,TRUE);
}else
DoXfer();
return TRUE;
}
BOOL CWRQSocket::ConfirmRequest()
{
CConfirmWRQDlg cd(NULL);
cd.m_Daddy=this;
cd.m_File=m_FileName;
cd.m_Host=inet_ntoa(m_Peer.sin_addr);
switch(cd.DoModal()){
case IDOK:
m_Rename=FALSE;
m_bResume=FALSE;
return TRUE;
case IDC_RENAME:
m_bResume=FALSE;
m_Rename=TRUE;
return TRUE;
case IDC_RESUME:
m_Rename=FALSE;
m_bResume=TRUE;
return TRUE;
case IDCANCEL:
return FALSE;
}
return FALSE;
}
BOOL CWRQSocket::RenameFile(CString& fn)
{
CString renamed = fn;
if(fn.IsEmpty())
return FALSE;
if(fn[fn.GetLength()-1]==')'){
int op = fn.ReverseFind('(');
if(op>0 && fn[op-1]==' '){
if(fn.Mid(op+1,fn.GetLength()-op-2).SpanExcluding("0123456789").IsEmpty())
renamed = renamed.Left(op-1);
}
}
CString testFN;
for(UINT tmp=0;tmp<32768;tmp++){
testFN.Format("%s (%u)",(LPCTSTR)renamed,tmp);
if(!_access((LPCTSTR)testFN,0))
continue;
fn=testFN;
return TRUE;
}
return FALSE;
}
BOOL CWRQSocket::SaveAs(CString& fn)
{
CFileDialog cfd(FALSE,NULL,fn,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,NULL,m_Daddy);
CString title;
title.LoadString(IDS_RENAME_TITLE);
cfd.m_ofn.lpstrTitle=(LPCTSTR)title;
if(cfd.DoModal()!=IDOK)
return FALSE;
fn = cfd.GetPathName();
return TRUE;
}
void CWRQSocket::DoXfer()
{
tftp *p = tftp::Allocate(tftp::tftpACK::tftpSize());
ASSERT(p);
p->SetOpcode(tftp::opACK);
p->data.m_ACK.SetBlock(m_ACK);
TRACE1("WRQ-ACK-%u\n",m_ACK);
PostTFTP(p,TRUE); // *** ??? Hope this is right
}
UINT tftp::tftpACK::tftpSize()
{
return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpACK);
}
ULONG CWRQSocket::GetACK()
{
return (m_ACK*m_blkSize)-m_LastSlack;
}
void CXferSocket::ResetTimeout()
{
ASSERT(m_Daddy);
m_Daddy->m_Retrier->KillTimer(m_hSocket);
if(m_Retry)
m_Daddy->m_Retrier->SetTimer(m_hSocket,min(60,m_Daddy->m_RetryTimeOut.GetTotalSeconds())*1000,NULL);
if(!m_bRetry){
m_Daddy->KillTimer(m_hSocket);
m_Daddy->SetTimer(m_hSocket,min(60,m_timeOut)*1000,NULL);
}
}
void CXferSocket::Abort()
{
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_XFERABORTED,(LPCTSTR)m_FileName);
m_Daddy->LogLine(tmp);
Destroy(FALSE);
}
void CPumpKINDlg::OnTimer(UINT nIDEvent)
{
CXferSocket *socket;
if(m_Xfers.Lookup(nIDEvent,socket)){
CString tmp;
tmp.Format(IDS_LOG_TIMEDOUT,socket->m_FileName);
LogLine(tmp);
socket->Abort();
}else{
TRACE0("Failed to find timed out socket!\n");
}
CDialog::OnTimer(nIDEvent);
}
void CPumpKINDlg::OnExit()
{
if(!m_Xfers.IsEmpty()){
CString title,text;
title.LoadString(IDS_CONFIRMEXIT_TITLE);
text.LoadString(IDS_CONFIRMEXIT_TEXT);
if(MessageBox(text,title,MB_ICONQUESTION|MB_YESNO)!=IDYES)
return;
}
m_bExiting=TRUE;
EndDialog(IDOK);
}
void CPumpKINDlg::OnPut()
{
CRequestDlg crd(NULL);
crd.m_Put=TRUE;
crd.m_BSize=m_BlockSize;
if(crd.DoModal()==IDOK){
CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
if(crd.m_BSize)
socket->m__blkSize=crd.m_BSize;
if(!socket->Create(crd.m_LocalFile,crd.m_Host))
socket->Destroy();
}
}
void CPumpKINDlg::OnGet()
{
CRequestDlg crd(NULL);
crd.m_Put=FALSE;
crd.m_BSize=m_BlockSize;
if(crd.DoModal()==IDOK){
CWRQSocket *socket = new CWRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
if(crd.m_BSize)
socket->m__blkSize=crd.m_BSize;
if(!socket->Create(crd.m_LocalFile,crd.m_Host))
socket->Destroy();
}
}
void CPumpKINDlg::SetupButtons()
{
m_AbortCtl.EnableWindow(m_List.GetSelectedCount()>0);
}
void CPumpKINDlg::OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
SetupButtons();
*pResult = 0;
}
void CPumpKINDlg::OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
SetupButtons();
*pResult = 0;
}
void CPumpKINDlg::OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
SetupButtons();
*pResult = 0;
}
void CPumpKINDlg::OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
SetupButtons();
*pResult = 0;
}
void CPumpKINDlg::OnAbort()
{
if(!m_List.GetSelectedCount())
return;
int items = m_List.GetItemCount();
for(int tmp=0;tmp<items;tmp++){
if(!(m_List.GetItemState(tmp,LVIS_SELECTED)&LVIS_SELECTED))
continue;
CXferSocket *xfer = (CXferSocket*) m_List.GetItemData(tmp);
ASSERT(xfer);
xfer->Abort();
}
}
void CXferSocket::OnFailedToResolve()
{
TRACE0("Resolve failed\n");
delete m_wndResolver;
m_wndResolver=NULL;
ASSERT(m_Daddy);
CString tmp;
tmp.Format(IDS_LOG_RESOLVEFAILED,m_HostName);
m_Daddy->LogLine(tmp);
Abort();
}
void CXferSocket::OnResolved()
{
delete m_wndResolver;
m_wndResolver=NULL;
TRACE0("Resolved\n");
m_Peer.sin_addr.s_addr = *(DWORD*)(((hostent*)m_ResolveBuff)->h_addr);
}
void CRRQSocket::OnResolved()
{
CXferSocket::OnResolved();
OnHostKnown();
}
void CRRQSocket::OnHostKnown()
{
ASSERT(m_Daddy);
m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
tftp::tftpOptions o;
CString v;
ASSERT(m_xferSize>=0);
v.Format("%lu",m_xferSize);
o[tftpoTSize] = v;
ASSERT(m__blkSize);
v.Format("%u",m__blkSize);
o[tftpoBSize] = v;
ASSERT(m__timeOut);
v.Format("%u",m__timeOut);
o[tftpoTOut] = v;
o[tftpoXResume] = "0";
tftp *p = tftp::Allocate(tftp::tftpWRQ::tftpSize(m_FileName,m_Type,&o));
ASSERT(p);
p->SetOpcode(tftp::opWRQ);
p->data.m_WRQ.Set(m_FileName,m_Type,&o);
PostTFTP(p,TRUE);
state=stateInit;
UpdateList();
}
UINT tftp::tftpRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
UINT rv = tftpHdrSize-tftpSlackSize+strlen(file)+1+strlen(type)+1;
if(ops){
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
rv+=n.GetLength()+1+v.GetLength()+1;
}
}
return rv;
}
UINT tftp::tftpRRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
return tftp::tftpRQ::tftpSize(file,type,ops);
}
UINT tftp::tftpWRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
return tftp::tftpRQ::tftpSize(file,type,ops);
}
UINT tftp::tftpOACK::tftpSize(tftp::tftpOptions* ops)
{
UINT rv = tftpHdrSize-tftpSlackSize;
if(ops){
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
rv+=n.GetLength()+1+v.GetLength()+1;
}
}
return rv;
}
void tftp::tftpRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
// MAY BE DANGEROUS!
UINT ptr = 0;
strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
if(ops){
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
}
}
}
void tftp::tftpRRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
// MAY BE DANGEROUS!
UINT ptr = 0;
strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
if(ops){
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
}
}
}
void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
{
// MAY BE DANGEROUS!
UINT ptr = 0;
strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
if(ops){
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
}
}
}
void tftp::tftpOACK::Set(tftpOptions* ops)
{
ASSERT(ops);
UINT ptr = 0;
tftpOptions& o = *ops;
POSITION p = o.GetStartPosition();
while(p){
CString n,v;
o.GetNextAssoc(p,n,v);
strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
}
}
void CWRQSocket::OnResolved()
{
CXferSocket::OnResolved();
OnHostKnown();
}
void CWRQSocket::OnHostKnown()
{
ASSERT(m_Daddy);
m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
tftp::tftpOptions o;
CString v;
o[tftpoTSize]="0";
if(m__blkSize){
v.Format("%u",m__blkSize);
o[tftpoBSize]=v;
}
if(m__timeOut){
v.Format("%u",m__timeOut);
o[tftpoTOut]=v;
}
tftp *p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o));
ASSERT(p);
p->SetOpcode(tftp::opRRQ);
p->data.m_RRQ.Set(m_FileName,m_Type,&o);
PostTFTP(p,TRUE);
state=stateInit;
UpdateList();
}
void CPumpKINDlg::OnClose()
{
OnTrayShowpumpkinwindow();
}
void CPumpKINDlg::OnTrayShowpumpkinwindow()
{
if(IsWindowVisible()){
m_bShown=FALSE;
ShowWindow(SW_HIDE);
}else{
m_bShown=TRUE;
ShowWindow(SW_SHOW);
SetForegroundWindow();
SetFocus();
}
}
void CPumpKINDlg::OnTrayExit()
{
OnExit();
}
void CPumpKINDlg::OnTrayAboutpumpkin()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CPumpKINDlg::OnTrayFetchfile()
{
OnGet();
}
void CPumpKINDlg::OnTrayHelp()
{
OnHelp();
}
void CPumpKINDlg::OnTrayOptions()
{
OnOptions();
}
void CPumpKINDlg::OnTraySendfile()
{
OnPut();
}
void CPumpKINDlg::LoadSettings()
{
CWinApp *app = AfxGetApp();
ASSERT(app);
m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen);
m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest);
m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess);
m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort);
m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort);
m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength);
m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode);
m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
m_LogFile=app->GetProfileString("General","LogFile",m_LogFile);
m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()));
m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()));
m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode);
m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown);
if(m_TFTPRoot.IsEmpty()){
DWORD dL = ::GetCurrentDirectory(0,NULL);
VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL)));
m_TFTPRoot.ReleaseBuffer();
}
::SetCurrentDirectory(m_TFTPRoot);
m_aclRules.LoadProfile(app);
}
void CPumpKINDlg::SaveSettings()
{
CWinApp *app = AfxGetApp();
ASSERT(app);
app->WriteProfileInt("TFTPSettings","Listen",m_bListen);
app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest);
app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess);
app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort);
app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort);
app->WriteProfileInt("UISettings","LogLength",m_LogLength);
app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode);
app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
app->WriteProfileString("General","LogFile",m_LogFile);
app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds());
app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds());
app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode);
app->WriteProfileInt("UISettings","Visble",m_bShown);
m_aclRules.SaveProfile(app);
}
void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CDialog::OnWindowPosChanging(lpwndpos);
if(!m_bExiting){
if(m_bShown){
lpwndpos->flags&=~SWP_HIDEWINDOW;
lpwndpos->flags|=SWP_SHOWWINDOW;
}else{
lpwndpos->flags&=~SWP_SHOWWINDOW;
lpwndpos->flags|=SWP_HIDEWINDOW;
if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu))
GetDesktopWindow()->SetForegroundWindow();
}
}
}
CString CXferSocket::ApplyRootGently(LPCTSTR fn)
{
CString f = fn;
CString rv = f;
if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0)
rv = ApplyRoot(f);
return rv;
}
BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file)
{
CString tmp = file;
if(tmp.IsEmpty())
return FALSE;
if(tmp.Find("..")>=0)
return TRUE;
if(tmp.Find(":")>=0)
return TRUE;
if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0)
return TRUE;
return FALSE;
}
void CAboutDlg::OnKlevernet()
{
CString url;
url.LoadString(IDS_KLEVERNET_URL);
ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED);
}
BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg)
{
// CG: The following block was added by the ToolTips component.
{
// Let the ToolTip process this message.
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
}
void CPumpKINDlg::OnSelchangeLog()
{
int sel = m_Log.GetCurSel();
if(sel==LB_ERR){
TRACE0("Error retrieving selection\n");
}else{
CTime *t = (CTime*)m_Log.GetItemData(sel);
ASSERT(t);
m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log);
}
}
void CPumpKINDlg::OnTrayOpenfilesfolder()
{
ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT);
}
void CPumpKINDlg::OnDropFiles(HDROP hDropInfo)
{
UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0);
ASSERT(files);
for(UINT file=0;file<files;file++){
CString theFile;
UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0);
ASSERT(fileNameLength);
VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength);
theFile.ReleaseBuffer();
// Send it over!
CRequestDlg crd(NULL);
crd.m_Drop=TRUE;
crd.m_Put=TRUE;
crd.m_BSize=m_BlockSize;
crd.m_LocalFile=theFile;
if(crd.DoModal()==IDOK){
CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
if(crd.m_BSize)
socket->m__blkSize=crd.m_BSize;
if(!socket->Create(crd.m_LocalFile,crd.m_Host))
socket->Destroy();
}
}
::DragFinish(hDropInfo);
}
void CPumpKINDlg::OnCancel()
{
OnClose();
}
CPumpKINDlg::~CPumpKINDlg()
{
delete m_Trayer;
delete m_Retrier;
}
void CXferSocket::OnRetry()
{
if(!m_Retry){
TRACE("Retrying unretriable..\n");
return;
}
TRACE0("Retrying..\n");
m_bRetry=TRUE;
PostTFTP(tftp::Copy(m_Retry));
m_bRetry=FALSE;
}
tftp* tftp::Copy(tftp *src)
{
ASSERT(src);
ASSERT(src->length);
tftp* rv = Allocate(src->length);
ASSERT(rv);
memmove(rv,src,tftpSlackSize+src->length);
return rv;
}
void CXferSocket::SetTry(tftp *p)
{
if(m_Retry)
delete m_Retry;
m_Retry=p?tftp::Copy(p):NULL;
}
void CPumpKINDlg::OnHelp()
{
AfxGetApp()->WinHelp(0,HELP_FINDER);
}
BOOL CListenSocket::SetListen(BOOL b) {
ASSERT(m_Daddy);
if(b==m_bListen)
return TRUE;
if(b) {
if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM))
return FALSE;
return m_bListen=TRUE;
}else{
Close(); m_bListen=FALSE;
return TRUE;
}
}
void CPumpKINDlg::OnListening()
{
if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) {
TRACE0("Failed to create socket\n");
AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
}
m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
m_bListen=m_Listener.m_bListen;
}
void CPumpKINDlg::OnTrayListen()
{
if(!m_Listener.SetListen(!m_Listener.m_bListen)) {
TRACE0("Failed to create socket\n");
AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
}
m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
m_bListen=m_Listener.m_bListen;
}
void CPumpKINDlg::LogLine(LPCTSTR str)
{
LogLineToScreen(str);
if(!m_LogFile.IsEmpty()) {
if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) {
if(m_lastlogerr!=m_LogFile) {
CString tmp;
tmp.Format(IDS_LOG_LOGERROR,m_LogFile);
LogLineToScreen(tmp);
m_lastlogerr=m_LogFile;
}
}
}
}
void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
if(m_MinSize.cx>0 && m_MinSize.cy>0){
lpMMI->ptMinTrackSize.x = m_MinSize.cx;
lpMMI->ptMinTrackSize.y = m_MinSize.cy;
}
}
void CPumpKINDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if(nType==SIZE_RESTORED)
RecalcLayout(cx,cy);
}
void CPumpKINDlg::RecalcLayout(int,int)
{
CRect wrc;
GetClientRect(&wrc);
AdjustButton(m_GetCtl,wrc);
AdjustButton(m_PutCtl,wrc);
AdjustButton(m_AbortCtl,wrc);
AdjustButton(m_HelpCtl,wrc);
AdjustButton(m_ExitCtl,wrc);
AdjustButton(m_OptionsCtl,wrc);
CRect brc;
m_List.GetWindowRect(&brc); ScreenToClient(&brc);
m_List.SetWindowPos(
0,
brc.left, brc.top,
wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
m_Log.GetWindowRect(&brc); ScreenToClient(&brc);
m_Log.SetWindowPos(
0,
brc.left, brc.top,
wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
m_ListenCtl.SetWindowPos(
0,
wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen,
0,0,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
int i = m_Log.GetCount();
if(i!=LB_ERR)
m_Log.SetCurSel(i-1);
}
void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc)
{
CRect brc;
w.GetWindowRect(&brc); ScreenToClient(&brc);
w.SetWindowPos(
0,
wrc.right-brc.Width()-m_rightGapButtons, brc.top,
0, 0,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
}
diff --git a/pumpkin.rc b/pumpkin.rc
index 5ce2438..adca112 100644
--- a/pumpkin.rc
+++ b/pumpkin.rc
@@ -1,686 +1,687 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif\r\n"
"#include ""res\\PumpKIN.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_RRQ ICON DISCARDABLE "res\\wrq.ico"
IDI_WRQ ICON DISCARDABLE "res\\rrq.ico"
IDI_BROWSE ICON DISCARDABLE "shared-data/browse-icon.ico"
IDR_MAINFRAME ICON DISCARDABLE "res\\pumpkin.ico"
IDI_PLAY ICON DISCARDABLE "shared-data/play-icon.ico"
IDI_UP ICON DISCARDABLE "res\\up.ico"
IDI_DOWN ICON DISCARDABLE "res\\down.ico"
IDI_REMOVE ICON DISCARDABLE "res\\remove.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 74
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About PumpKIN"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,7,17,18,20
LTEXT "PumpKIN, Version 2.7.1",IDC_STATIC,40,15,119,8,
SS_NOPREFIX
LTEXT "Copyright © 1997-2006 Klever Group",IDC_STATIC,40,30,
170,8
DEFPUSHBUTTON "OK",IDOK,178,7,32,14,WS_GROUP
PUSHBUTTON "http://www.klever.net/",IDC_KLEVERNET,124,53,86,14
END
IDD_PUMPKIN_DIALOG DIALOGEX 0, 0, 362, 193
STYLE DS_3DLOOK | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_ACCEPTFILES | WS_EX_APPWINDOW
CAPTION " PumpKIN"
-FONT 8, "MS Sans Serif"
+FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
CONTROL "List1",IDC_CONNECTIONS,"SysListView32",LVS_REPORT |
LVS_AUTOARRANGE | WS_BORDER | WS_TABSTOP,7,7,295,108,
WS_EX_DLGMODALFRAME
PUSHBUTTON "&Get File",IDC_GET,305,7,50,17,BS_NOTIFY,
WS_EX_CLIENTEDGE
PUSHBUTTON "&Put File",IDC_PUT,305,25,50,17,BS_NOTIFY,
WS_EX_CLIENTEDGE
PUSHBUTTON "&Abort xfer",IDC_ABORT,305,43,50,17,BS_NOTIFY,
WS_EX_CLIENTEDGE
PUSHBUTTON "&Options",IDC_OPTIONS,305,61,50,17,BS_NOTIFY,
WS_EX_CLIENTEDGE
PUSHBUTTON "E&xit",IDC_EXIT,305,79,50,17,BS_NOTIFY,WS_EX_CLIENTEDGE
PUSHBUTTON "&Help",ID_HELP,305,97,50,17,BS_NOTIFY,WS_EX_CLIENTEDGE
LISTBOX IDC_LOG,7,115,348,64,LBS_USETABSTOPS |
LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_VSCROLL |
WS_HSCROLL,WS_EX_DLGMODALFRAME
PUSHBUTTON "..",IDCANCEL,0,183,6,7,NOT WS_VISIBLE | NOT WS_TABSTOP
CONTROL "&Server is running",IDC_LISTENING,"Button",
BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_FLAT | WS_TABSTOP,286,
181,69,11,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
END
IDD_PROPS_SERVER DIALOG DISCARDABLE 0, 0, 300, 201
STYLE WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Server"
FONT 8, "MS Sans Serif"
BEGIN
GROUPBOX "TFTP filesystem &root (download path)",IDC_STATIC,7,7,
286,38
EDITTEXT IDC_TFTPROOT,13,16,256,13,ES_AUTOHSCROLL
PUSHBUTTON "&B",IDC_BROWSE,274,16,13,13,BS_ICON
CONTROL "Allow access to &subdirectories",IDC_TFTPSUBDIRS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,31,111,10
GROUPBOX "Read Request Behavior",IDC_STATIC,7,48,243,56
CONTROL "Give &all files",IDC_RRQ_GIVEALL,"Button",
BS_AUTORADIOBUTTON | BS_NOTIFY | WS_GROUP,13,63,53,10
CONTROL "&Prompt before giving file",IDC_RRQ_ALWAYSCONFIRM,
"Button",BS_AUTORADIOBUTTON | BS_NOTIFY,43,75,91,10
CONTROL "&Deny all requests",IDC_RRQ_DENYALL,"Button",
BS_AUTORADIOBUTTON | BS_NOTIFY,73,87,70,10
GROUPBOX "Write Request Behavior",IDC_STATIC,7,106,243,56,
WS_GROUP
CONTROL "Take a&ll files",IDC_WRQ_TAKEALL,"Button",
BS_AUTORADIOBUTTON | WS_GROUP,13,116,55,10
CONTROL "Prompt if file &exists",IDC_WRQ_PROMPTEXISTING,"Button",
BS_AUTORADIOBUTTON,43,126,73,10
CONTROL "Always pro&mpt before accepting file",
IDC_WRQ_ALWAYSCONFIRM,"Button",BS_AUTORADIOBUTTON,73,136,
139,10
CONTROL "D&eny all requests",IDC_WRQ_DENYALL,"Button",
BS_AUTORADIOBUTTON,103,146,70,10
CTEXT "Confirmation &timeout",IDC_STATIC,253,52,40,19,
SS_NOTIFY
CONTROL "Slider1",IDC_PROMPTTIMEOUT,"msctls_trackbar32",
TBS_AUTOTICKS | TBS_VERT | TBS_TOP | WS_TABSTOP,272,72,
21,90
GROUPBOX "Log file (leave empty to disable logging to file)",
IDC_STATIC,7,165,286,29
EDITTEXT IDC_LOGFILE,13,175,256,13,ES_AUTOHSCROLL
PUSHBUTTON "",IDC_LOGFILE_BROWSE,274,175,13,13,BS_ICON
END
IDD_PROPS_NETWORK DIALOG DISCARDABLE 0, 0, 300, 201
STYLE WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Network"
FONT 8, "MS Sans Serif"
BEGIN
GROUPBOX "UDP Ports",IDC_STATIC,7,7,286,40
RTEXT "Listen for &incoming requests on port:",IDC_STATIC,13,
18,135,8
EDITTEXT IDC_LISTENPORT,154,16,40,13,ES_AUTOHSCROLL
CONTROL "Spin1",IDC_LISTENSPIN,"msctls_updown32",UDS_WRAP |
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS | UDS_NOTHOUSANDS,183,16,11,13
RTEXT "Send &outging requests to port:",IDC_STATIC,13,31,135,8
EDITTEXT IDC_SPEAKPORT,154,29,40,13,ES_AUTOHSCROLL
CONTROL "Spin1",IDC_SPEAKSPIN,"msctls_updown32",UDS_WRAP |
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS | UDS_NOTHOUSANDS,183,29,11,13
LTEXT "Default connection timeout:",IDC_STATIC,7,52,88,8
EDITTEXT IDC_TIMEOUT,110,50,40,13,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "Spin3",IDC_TIMESPIN,"msctls_updown32",UDS_WRAP |
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS | UDS_NOTHOUSANDS,140,50,11,13
LTEXT "Default block size:",IDC_STATIC,7,66,59,8
LTEXT "seconds",IDC_STATIC,154,52,28,8
LTEXT "bytes",IDC_STATIC,154,66,18,8
EDITTEXT IDC_BLOCKSIZE,110,64,40,13,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "Spin3",IDC_BSIZESPIN,"msctls_updown32",UDS_WRAP |
UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
UDS_ARROWKEYS | UDS_NOTHOUSANDS,140,64,11,13
END
IDD_CONFIRM_RRQ DIALOGEX 0, 0, 181, 79
STYLE DS_MODALFRAME | DS_NOIDLEMSG | DS_SETFOREGROUND | DS_3DLOOK | WS_POPUP |
WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE
CAPTION " PumpKIN - Confirm Read Request"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "&Grant Access",IDOK,27,58,54,14
PUSHBUTTON "&Deny Access",IDCANCEL,97,58,54,14
LTEXT "The host",IDC_STATIC,77,7,29,8
CTEXT "255.255.255.255",IDC_HOST,57,15,68,14,SS_NOTIFY |
SS_SUNKEN | WS_BORDER,WS_EX_DLGMODALFRAME |
WS_EX_CLIENTEDGE
CTEXT "is requesting the file",IDC_STATIC,23,29,135,8
CTEXT "",IDC_FILE,23,37,135,14,SS_NOTIFY | SS_SUNKEN |
WS_BORDER,WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,54,167,1
ICON IDR_MAINFRAME,IDC_STATIC,7,7,18,20
ICON IDR_MAINFRAME,IDC_STATIC,153,7,18,20
END
IDD_CONFIRM_WRQ DIALOGEX 0, 0, 201, 95
STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE
CAPTION " PumpKIN - Confirm Write Request"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "&Accept",IDOK,7,58,59,14
PUSHBUTTON "&Rename",IDC_RENAME,71,58,59,14
PUSHBUTTON "&Deny Access",IDCANCEL,135,58,59,14
LTEXT "The host",IDC_STATIC,87,7,29,8
CTEXT "255.255.255.255",IDC_HOST,67,15,68,14,SS_NOTIFY |
SS_SUNKEN | WS_BORDER,WS_EX_DLGMODALFRAME |
WS_EX_CLIENTEDGE
CTEXT "is attempting to send you a file",IDC_STATIC,33,29,135,
8
CTEXT "",IDC_FILE,33,37,135,14,SS_NOTIFY | SS_SUNKEN |
WS_BORDER,WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,54,187,1
ICON IDR_MAINFRAME,IDC_STATIC,7,7,21,20
ICON IDR_MAINFRAME,IDC_STATIC,173,7,21,20
PUSHBUTTON "Res&ume",IDC_RESUME,71,74,59,14
END
IDD_REQUEST DIALOGEX 0, 0, 191, 161
STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | WS_POPUP | WS_CAPTION |
WS_SYSMENU
EXSTYLE WS_EX_CLIENTEDGE
CAPTION "Request"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
LTEXT "&Local file:",IDC_STATIC,7,7,31,8,SS_NOTIFY
EDITTEXT IDC_LOCALFILE,7,16,157,14,ES_AUTOHSCROLL,
WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
PUSHBUTTON "...",IDC_BROWSE,165,16,19,14,BS_ICON,WS_EX_STATICEDGE
LTEXT "&Remote file:",IDC_STATIC,7,34,38,8,SS_NOTIFY
EDITTEXT IDC_REMOTEFILE,7,44,177,14,ES_AUTOHSCROLL,
WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
LTEXT "Remote &host:",IDC_STATIC,7,61,43,8,SS_NOTIFY
COMBOBOX IDC_TALKS,7,72,157,66,CBS_SIMPLE | CBS_AUTOHSCROLL |
CBS_SORT | CBS_NOINTEGRALHEIGHT | WS_VSCROLL |
WS_TABSTOP,WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
PUSHBUTTON "R\nE\n&F\nR\nE\nS\nH",IDC_REFRESH,165,72,19,66,
BS_CENTER | BS_VCENTER | BS_MULTILINE | BS_NOTIFY,
WS_EX_CLIENTEDGE
LTEXT "&Type:",IDC_STATIC,58,34,19,8
COMBOBOX IDC_TYPE,80,31,43,41,CBS_DROPDOWN | CBS_AUTOHSCROLL |
CBS_LOWERCASE | WS_VSCROLL | WS_TABSTOP
LTEXT "&Block:",IDC_STATIC,127,34,21,8
COMBOBOX IDC_BSIZE,149,31,35,53,CBS_DROPDOWN | WS_VSCROLL |
WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,35,140,50,14
PUSHBUTTON "Cancel",IDCANCEL,101,140,50,14
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDVERT,52,32,1,11
END
IDD_PROPS_SOUNDS DIALOG DISCARDABLE 0, 0, 300, 201
STYLE WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Sounds"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "&Incoming request:",IDC_STATIC,7,9,57,8
COMBOBOX IDC_RING,70,7,188,100,CBS_DROPDOWN | CBS_AUTOHSCROLL |
CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "browse",IDC_RING_BROWSE,263,7,13,13,BS_ICON
PUSHBUTTON "play",IDC_RING_PLAY,280,7,13,13,BS_ICON
LTEXT "xfer &finished:",IDC_STATIC,7,25,57,8
COMBOBOX IDC_FINISHED,70,22,188,100,CBS_DROPDOWN |
CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "browse",IDC_FINISHED_BROWSE,263,22,13,13,BS_ICON
PUSHBUTTON "play",IDC_FINISHED_PLAY,280,22,13,13,BS_ICON
LTEXT "xfer &aborted:",IDC_STATIC,7,40,57,8
COMBOBOX IDC_ABORTED,70,37,188,100,CBS_DROPDOWN | CBS_AUTOHSCROLL |
CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "browse",IDC_ABORTED_BROWSE,263,37,13,13,BS_ICON
PUSHBUTTON "play",IDC_ABORTED_PLAY,280,37,13,13,BS_ICON
END
IDD_PROPS_ACL DIALOG DISCARDABLE 0, 0, 300, 201
STYLE WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Access Lists"
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "List1",IDC_ACL_LIST,"SysListView32",LVS_REPORT |
WS_BORDER | WS_TABSTOP,7,7,258,110
PUSHBUTTON "&Up",IDC_ACL_UP,273,7,20,30,BS_ICON | BS_CENTER |
BS_VCENTER
PUSHBUTTON "&Down",IDC_ACL_DOWN,273,87,20,30,BS_ICON | BS_CENTER |
BS_VCENTER
PUSHBUTTON "&Remove",IDC_ACL_REMOVE,273,47,20,30,BS_ICON |
BS_CENTER | BS_VCENTER
LTEXT "If",IDC_STATIC,13,128,8,8
COMBOBOX IDC_ACL_XFER,21,125,48,67,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "request comes from the address in the network",
IDC_STATIC,71,128,122,8
EDITTEXT IDC_ACL_ADDR,47,143,80,12,ES_AUTOHSCROLL
LTEXT "with netmask",IDC_STATIC,129,145,41,8
EDITTEXT IDC_ACL_NETMASK,173,143,80,12,ES_AUTOHSCROLL
LTEXT "then",IDC_STATIC,124,160,15,8
COMBOBOX IDC_ACL_RULE,143,158,123,117,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Add new rule",IDC_ACL_ADD,7,178,130,16
PUSHBUTTON "&Replace rule",IDC_ACL_REPLACE,152,178,130,16
END
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,7,1,0
PRODUCTVERSION 2,7,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Klever Group (http://www.klever.net/)\0"
VALUE "FileDescription", "PumpKIN, tftp client/daemon\0"
VALUE "FileVersion", "2, 7, 1, 0\0"
VALUE "InternalName", "PUMPKIN\0"
VALUE "LegalCopyright", "Copyright © 1997-2006 Klever Group (http://www.klever.net)\0"
VALUE "LegalTrademarks", "Klever Group (http://www.klever.net/)\0"
VALUE "OriginalFilename", "PUMPKIN.EXE\0"
VALUE "ProductName", "PumpKIN\0"
VALUE "ProductVersion", "2, 7, 1, 0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 210
TOPMARGIN, 7
BOTTOMMARGIN, 67
END
IDD_PUMPKIN_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 355
TOPMARGIN, 7
BOTTOMMARGIN, 186
HORZGUIDE, 115
END
IDD_PROPS_SERVER, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 194
END
IDD_PROPS_NETWORK, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 194
END
IDD_CONFIRM_RRQ, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 174
TOPMARGIN, 7
BOTTOMMARGIN, 72
END
IDD_CONFIRM_WRQ, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 194
TOPMARGIN, 7
BOTTOMMARGIN, 88
END
IDD_REQUEST, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 184
TOPMARGIN, 7
BOTTOMMARGIN, 154
END
IDD_PROPS_SOUNDS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 194
END
IDD_PROPS_ACL, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 194
HORZGUIDE, 117
HORZGUIDE, 125
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_BACKGROUND BITMAP DISCARDABLE "shared-data/klever-background.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// WAVE
//
IDR_WAVE_RING WAVE DISCARDABLE "res\\ring.wav"
IDR_WAVE_FINISHED WAVE DISCARDABLE "res\\finished.wav"
IDR_WAVE_ABORTED WAVE DISCARDABLE "res\\failed.wav"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog Info
//
IDD_REQUEST DLGINIT
BEGIN
IDC_TYPE, 0x403, 6, 0
0x636f, 0x6574, 0x0074,
IDC_TYPE, 0x403, 9, 0
0x656e, 0x6174, 0x6373, 0x6969, "\000"
IDC_BSIZE, 0x403, 4, 0
0x3135, 0x0032,
IDC_BSIZE, 0x403, 5, 0
0x3031, 0x3432, "\000"
IDC_BSIZE, 0x403, 5, 0
0x3032, 0x3834, "\000"
IDC_BSIZE, 0x403, 5, 0
0x3034, 0x3639, "\000"
IDC_BSIZE, 0x403, 5, 0
0x3138, 0x3239, "\000"
0
END
IDD_PROPS_ACL DLGINIT
BEGIN
IDC_ACL_XFER, 0x403, 5, 0
0x6572, 0x6461, "\000"
IDC_ACL_XFER, 0x403, 6, 0
0x7277, 0x7469, 0x0065,
IDC_ACL_RULE, 0x403, 12, 0
0x6361, 0x6563, 0x7470, 0x6620, 0x6c69, 0x0065,
IDC_ACL_RULE, 0x403, 33, 0
0x6361, 0x6563, 0x7470, 0x6120, 0x646e, 0x7220, 0x6e65, 0x6d61, 0x2065,
0x6669, 0x6620, 0x6c69, 0x2065, 0x7865, 0x7369, 0x7374, "\000"
IDC_ACL_RULE, 0x403, 12, 0
0x6572, 0x656a, 0x7463, 0x6620, 0x6c69, 0x0065,
IDC_ACL_RULE, 0x403, 31, 0
0x6166, 0x6c6c, 0x6162, 0x6b63, 0x7420, 0x206f, 0x6874, 0x2065, 0x6c67,
0x626f, 0x6c61, 0x7320, 0x7465, 0x6974, 0x676e, "\000"
0
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDM_POPUPS MENU DISCARDABLE
BEGIN
POPUP "&Tray"
BEGIN
MENUITEM "&Send File", ID_TRAY_SENDFILE
MENUITEM "F&etch file", ID_TRAY_FETCHFILE
MENUITEM "&Options", ID_TRAY_OPTIONS
MENUITEM "&Listen to requests", ID_TRAY_LISTEN
MENUITEM "Show &PumpKIN Window", ID_TRAY_SHOWPUMPKINWINDOW
MENUITEM "Open &Files Folder", ID_TRAY_OPENFILESFOLDER
MENUITEM SEPARATOR
MENUITEM "&Help Topics", ID_TRAY_HELP
MENUITEM "&About PumpKIN", ID_TRAY_ABOUTPUMPKIN
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_TRAY_EXIT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
IDS_ABOUTBOX "&About PumpKIN..."
IDS_FMT_BYTES "%lu"
IDP_SOCKETS_INIT_FAILED "Windows sockets initialization failed."
IDS_TFTP_ERROR_ACCESS "Access violation"
IDS_TFTP_ERROR_NOTFOUND "File not found"
IDS_TFTP_ERROR_DIRFULL "Directory is full"
IDS_TFTP_ERROR_SHARING "Sharing violation"
IDS_TFTP_ERROR_DISKFULL "Disk full"
IDS_TFTP_ERROR_UNDEFINED "Undefined error"
IDS_LOG_START "PumpKIN started"
IDS_LOG_LISTENRECEIVEERROR "Error listening for incoming connections"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_LOG_LISTENACCEPTERROR "Error accepting incoming connection"
IDS_LOG_RRQSERVE "'%s' of type '%s' is requested from %s"
IDS_LOG_LISTENOPCODE "Invalid opcode in initial connection request"
IDS_LOG_XFERUDPSEND "UDP packet send failed"
IDS_LOG_XFERRECEIVE "Error on xfer socket"
IDS_LOG_XFERSEND "Error on xfer socket"
IDS_LOG_XFERUDPRECEIVE "UDP packet receive failed"
IDS_LOG_XFERSOURCETID "Packet from unexpected source"
- IDS_LOG_SENTTFTPERROR ":%u: %s"
+ IDS_LOG_SENTTFTPERROR ">> %u: %s"
IDS_LOG_GOTTFTPERROR "TFTP:%u: %s"
IDS_LOG_XFEROPCODE "Invalid opcode (%u) during transfer received"
IDS_LOG_XFERRRQFINISHED "Transfer of '%s' has successfully completed"
IDS_TITLE_OPTIONS "Options"
IDS_LOG_WRQSERVE "Writing of '%s' of type '%s' is requested by %s"
IDS_TFTP_ERROR_FAILEDTORENAME "Too many clones of the file"
IDS_RENAME_TITLE "Save As"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_LOG_TIMEDOUT "Transmission of '%s' is timed out"
IDS_CONFIRMEXIT_TITLE "Exit"
IDS_CONFIRMEXIT_TEXT "File transmission is currently in progress. Are you sure you want to exit?"
IDS_LOG_XFERWRQFINISHED "Transfer of '%s' has successfully completed"
IDS_LOG_XFERABORTED "Transfer of '%s' was aborted"
IDS_TITLE_PUTREQUEST "Send file"
IDS_TITLE_GETREQUEST "Fetch file"
IDS_WTALKHEADING "Talk with "
IDS_TITLE_BROWSEFILE "Browse"
IDS_LOG_RESOLVEFAILED "Failed to resolve host address for '%s'"
IDS_LOG_FAILEDLOCALFILE "Failed to open local file '%s'"
IDS_LOG_FAILEDTOOPEN "Failed to open '%s'"
IDS_OTALXHEADING "Open Talks: talking to "
IDS_REGISTRYKEY "Klever Group"
IDS_KLEVERNET_URL "http://www.klever.net/"
IDS_LOGTIMEFORMAT "%H:%M:%S %B %d"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TRAY_HELP "Read the help on PumpKIN"
ID_TRAY_ABOUTPUMPKIN "Learn about PumpKIN and it's creator"
ID_TRAY_EXIT "Close PumpKIN"
ID_TRAY_SENDFILE "Send file over the network to your tete-a-tete"
ID_TRAY_FETCHFILE "Fetch file from remote computer"
ID_TRAY_OPTIONS "Set PumpKIN options"
ID_TRAY_SHOWPUMPKINWINDOW "Show main window"
ID_TRAY_OPENFILESFOLDER "Explore TFTP root folder"
ID_TRAY_LISTEN "Listen for incoming requests"
END
STRINGTABLE DISCARDABLE
BEGIN
IDC_CONNECTIONS "Active transfers"
IDC_LOG "PumpKIN Activity Log"
IDC_GET "Fetch file from remote server"
IDC_PUT "Send file over the net"
IDC_ABORT "Abort transfer currently in progress"
IDC_EXIT "Close PumpKIN"
END
STRINGTABLE DISCARDABLE
BEGIN
IDC_OPTIONS "Set PumpKIN options"
IDC_REFRESH "Refresh talks list"
IDC_BROWSE "Browse"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_HELP "Read help on PumpKIN"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_DROPFILES_TITLE "Drop Files"
IDS_NOMULTIPLEDROP_TEXT "You can't drop more than one file here. Only the first one will be accepted"
IDS_LOG_REQUESTING "Requesting '%s' from '%s'"
IDS_LOG_SENDING "Sending '%s' to '%s'"
IDS_WTALKAT "@"
IDS_OTALXAT " at "
IDS_TFTP_ERROR_TSIZE "Invalid transfer size"
IDS_TFTP_ERROR_BSIZE "Invalid block size"
IDS_TFTP_ERROR_TOUT "Invalid timeout"
IDS_SELECT_TFTPROOT "Select TFTP filesystem root.."
IDS_FILTER_WAV "Sound Files (*.wav)|*.wav||"
IDS_TITLE_WAV "Select sound.."
IDS_BOX_CANTBIND "Failed to create listening socket. The port may be in use by another application."
IDS_NO_XFER_OP "No request type specified."
IDS_INVALID_IP "Invalid IP address."
IDS_INVALID_NETMASK "Invalid netmask."
END
STRINGTABLE DISCARDABLE
BEGIN
AFX_IDS_APP_TITLE "PUMPKIN"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_INVALID_RULE "Invalid access rule."
IDS_LOG_LOGERROR "Error logging to '%s'"
+ IDS_TFTP_ERROR_TOOBIG "File is too big, try increasing block size"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif
#include "res\PumpKIN.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
diff --git a/resource.h b/resource.h
index 1bdce59..7961e5e 100644
--- a/resource.h
+++ b/resource.h
@@ -1,171 +1,173 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by PumpKIN.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDC_TRAYICON 101
#define IDD_PUMPKIN_DIALOG 102
#define IDS_FMT_BYTES 102
#define IDP_SOCKETS_INIT_FAILED 103
#define IDS_TFTP_ERROR_ACCESS 104
#define IDS_TFTP_ERROR_NOTFOUND 105
#define IDS_TFTP_ERROR_DIRFULL 106
#define IDD_PROPS_SERVER 106
#define IDS_TFTP_ERROR_SHARING 107
#define IDD_PROPS_NETWORK 107
#define IDS_TFTP_ERROR_DISKFULL 108
#define IDS_TFTP_ERROR_UNDEFINED 109
#define IDS_LOG_START 110
#define IDS_LOG_LISTENRECEIVEERROR 111
#define IDS_LOG_LISTENACCEPTERROR 112
#define IDS_LOG_RRQSERVE 113
#define IDS_LOG_LISTENOPCODE 114
#define IDS_LOG_XFERUDPSEND 115
#define IDS_LOG_XFERRECEIVE 116
#define IDS_LOG_XFERSEND 117
#define IDS_LOG_XFERUDPRECEIVE 118
#define IDS_LOG_XFERSOURCETID 119
#define IDS_LOG_SENTTFTPERROR 120
#define IDS_LOG_GOTTFTPERROR 121
#define IDS_LOG_XFEROPCODE 122
#define IDS_LOG_XFERRRQFINISHED 123
#define IDS_TITLE_OPTIONS 124
#define IDS_LOG_WRQSERVE 125
#define IDS_TFTP_ERROR_FAILEDTORENAME 126
#define IDS_RENAME_TITLE 127
#define IDR_MAINFRAME 128
#define IDS_LOG_TIMEDOUT 128
#define IDS_CONFIRMEXIT_TITLE 129
#define IDI_RRQ 129
#define IDS_CONFIRMEXIT_TEXT 130
#define IDI_WRQ 130
#define IDD_CONFIRM_RRQ 131
#define IDS_LOG_XFERWRQFINISHED 131
#define IDD_CONFIRM_WRQ 132
#define IDB_BACKGROUND 132
#define IDS_LOG_XFERABORTED 132
#define IDS_TITLE_PUTREQUEST 133
#define IDS_TITLE_GETREQUEST 134
#define IDR_WAVE_RING 135
#define IDS_TALKHEADING 135
#define IDS_WTALKHEADING 135
#define IDR_WAVE_FINISHED 136
#define IDS_TITLE_BROWSEFILE 136
#define IDD_REQUEST 137
#define IDS_LOG_RESOLVEFAILED 137
#define IDS_LOG_FAILEDLOCALFILE 138
#define IDD_PROPS_SOUNDS 138
#define IDS_LOG_FAILEDTOOPEN 139
#define IDM_POPUPS 140
#define IDS_OTALXHEADING 140
#define IDS_REGISTRYKEY 141
#define IDS_KLEVERNET_URL 142
#define IDR_WAVE_ABORTED 142
#define IDS_LOGTIMEFORMAT 143
#define IDS_DROPFILES_TITLE 144
#define IDS_NOMULTIPLEDROP_TEXT 145
#define IDI_BROWSE 145
#define IDS_LOG_REQUESTING 146
#define IDS_LOG_SENDING 147
#define IDS_WTALKAT 148
#define IDS_OTALXAT 149
#define IDI_PLAY 149
#define IDS_TFTP_ERROR_TSIZE 150
#define IDD_PROPS_ACL 150
#define IDS_TFTP_ERROR_BSIZE 151
#define IDS_TFTP_ERROR_TOUT 152
#define IDI_UP 152
#define IDS_SELECT_TFTPROOT 153
#define IDI_DOWN 153
#define IDS_FILTER_WAV 154
#define IDI_REMOVE 154
#define IDS_TITLE_WAV 155
#define IDS_BOX_CANTBIND 156
#define IDS_NO_XFER_OP 157
#define IDS_INVALID_IP 158
#define IDS_INVALID_NETMASK 159
#define IDS_INVALID_RULE 160
#define IDS_LOG_LOGERROR 161
+#define IDS_TFTP_ERROR_TOOBIG 162
+#define IDS_LOG_DENYING 163
#define IDC_KLEVERNET 1000
#define IDC_CONNECTIONS 1001
#define IDC_LOG 1003
#define IDC_GET 1004
#define IDC_PUT 1005
#define IDC_ABORT 1006
#define IDC_EXIT 1007
#define IDC_TFTPROOT 1008
#define IDC_TFTPSUBDIRS 1009
#define IDC_RRQ_GIVEALL 1010
#define IDC_RRQ_ALWAYSCONFIRM 1011
#define IDC_RRQ_DENYALL 1012
#define IDC_WRQ_TAKEALL 1013
#define IDC_WRQ_PROMPTEXISTING 1014
#define IDC_WRQ_ALWAYSCONFIRM 1015
#define IDC_WRQ_DENYALL 1016
#define IDC_PROMPTTIMEOUT 1017
#define IDC_LISTENPORT 1018
#define IDC_LISTENSPIN 1019
#define IDC_SPEAKPORT 1020
#define IDC_SPEAKSPIN 1021
#define IDC_MAXUDPSIZE 1022
#define IDC_MAXUDPSPIN 1023
#define IDC_TIMEOUT 1024
#define IDC_TIMESPIN 1025
#define IDC_OPTIONS 1026
#define IDC_BLOCKSIZE 1026
#define IDC_BSIZESPIN 1027
#define IDC_HOST 1028
#define IDC_FILE 1029
#define IDC_RENAME 1030
#define IDC_REMOTEFILE 1030
#define IDC_RESUME 1031
#define IDC_REFRESH 1032
#define IDC_BROWSE 1034
#define IDC_TALKS 1035
#define IDC_LOCALFILE 1036
#define IDC_TYPE 1037
#define IDC_BSIZE 1039
#define IDC_RING 1041
#define IDC_RING_BROWSE 1042
#define IDC_RING_PLAY 1043
#define IDC_ACL_LIST 1043
#define IDC_FINISHED 1044
#define IDC_ACL_UP 1044
#define IDC_FINISHED_BROWSE 1045
#define IDC_ACL_DOWN 1045
#define IDC_FINISHED_PLAY 1046
#define IDC_ACL_REMOVE 1046
#define IDC_ABORTED 1047
#define IDC_ACL_ADDR 1047
#define IDC_ABORTED_BROWSE 1048
#define IDC_ACL_RULE 1048
#define IDC_ABORTED_PLAY 1049
#define IDC_ACL_NETMASK 1049
#define IDC_ACL_ADD 1050
#define IDC_ACL_XFER 1051
#define IDC_ACL_REPLACE 1052
#define IDC_LISTENING 1052
#define IDC_LOGFILE 1053
#define IDC_LOGFILE_BROWSE 1054
#define ID_TRAY_HELP 32771
#define ID_TRAY_ABOUTPUMPKIN 32772
#define ID_TRAY_EXIT 32773
#define ID_TRAY_SENDFILE 32774
#define ID_TRAY_FETCHFILE 32775
#define ID_TRAY_OPTIONS 32776
#define ID_TRAY_SHOWPUMPKINWINDOW 32777
#define ID_TRAY_OPENFILESFOLDER 32778
#define ID_TRAY_LISTEN 32780
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 155
#define _APS_NEXT_COMMAND_VALUE 32781
#define _APS_NEXT_CONTROL_VALUE 1055
#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif