summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.cpp
Unidiff
Diffstat (limited to 'PumpKINDlg.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-xPumpKINDlg.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp
index 3ff1500..0c5c19b 100755
--- a/PumpKINDlg.cpp
+++ b/PumpKINDlg.cpp
@@ -1103,279 +1103,281 @@ void tftp::tftpDATA::SetBlock(WORD b)
1103WORD tftp::tftpDATA::Block() 1103WORD tftp::tftpDATA::Block()
1104{ 1104{
1105 return REVERSEBYTES(block); 1105 return REVERSEBYTES(block);
1106} 1106}
1107WORD tftp::tftpACK::Block() 1107WORD tftp::tftpACK::Block()
1108{ 1108{
1109 return REVERSEBYTES(block); 1109 return REVERSEBYTES(block);
1110} 1110}
1111void tftp::tftpACK::SetBlock(WORD b) 1111void tftp::tftpACK::SetBlock(WORD b)
1112{ 1112{
1113 block = REVERSEBYTES(b); 1113 block = REVERSEBYTES(b);
1114} 1114}
1115WORD tftp::tftpERROR::Code() 1115WORD tftp::tftpERROR::Code()
1116{ 1116{
1117 return REVERSEBYTES(code); 1117 return REVERSEBYTES(code);
1118} 1118}
1119void tftp::tftpERROR::SetCode(WORD c) 1119void tftp::tftpERROR::SetCode(WORD c)
1120{ 1120{
1121 code = REVERSEBYTES(c); 1121 code = REVERSEBYTES(c);
1122} 1122}
1123 1123
1124 1124
1125CString tftp::errMessage() 1125CString tftp::errMessage()
1126{ 1126{
1127CString rv; 1127CString rv;
1128 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code))) 1128 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code)))
1129 rv = (LPCTSTR)data.m_ERROR.data; 1129 rv = (LPCTSTR)data.m_ERROR.data;
1130 return rv; 1130 return rv;
1131} 1131}
1132 1132
1133void CXferSocket::Destroy(BOOL success) 1133void CXferSocket::Destroy(BOOL success)
1134{ 1134{
1135 if(m_wndResolver){ 1135 if(m_wndResolver){
1136 delete m_wndResolver; 1136 delete m_wndResolver;
1137 m_wndResolver=NULL; 1137 m_wndResolver=NULL;
1138 } 1138 }
1139 SetTry(); 1139 SetTry();
1140 m_Daddy->m_bnw.StartSound( 1140 m_Daddy->m_bnw.StartSound(
1141 success 1141 success
1142 ? m_Daddy->m_bnwSuccess 1142 ? m_Daddy->m_bnwSuccess
1143 : m_Daddy->m_bnwAbort 1143 : m_Daddy->m_bnwAbort
1144 ); 1144 );
1145 if(m_File.m_hFile!=CFile::hFileNull){ 1145 if(m_File.m_hFile!=CFile::hFileNull){
1146 TRY{ 1146 TRY{
1147 m_File.Close(); 1147 m_File.Close();
1148 }CATCH(CFileException,e){ 1148 }CATCH(CFileException,e){
1149 TRACE0("Error closing file\n"); 1149 TRACE0("Error closing file\n");
1150 }END_CATCH 1150 }END_CATCH
1151 } 1151 }
1152 ASSERT(m_Daddy); 1152 ASSERT(m_Daddy);
1153 m_Daddy->KillTimer(m_hSocket); 1153 m_Daddy->KillTimer(m_hSocket);
1154 m_Daddy->m_Xfers.RemoveKey(m_hSocket); 1154 m_Daddy->m_Xfers.RemoveKey(m_hSocket);
1155LV_FINDINFO lvf; 1155LV_FINDINFO lvf;
1156 memset(&lvf,0,sizeof(lvf)); 1156 memset(&lvf,0,sizeof(lvf));
1157 lvf.flags=LVFI_PARAM; 1157 lvf.flags=LVFI_PARAM;
1158 lvf.lParam=(LPARAM)this; 1158 lvf.lParam=(LPARAM)this;
1159int i = m_Daddy->m_List.FindItem(&lvf); 1159int i = m_Daddy->m_List.FindItem(&lvf);
1160 if(i>=0) 1160 if(i>=0)
1161 m_Daddy->m_List.DeleteItem(i); 1161 m_Daddy->m_List.DeleteItem(i);
1162 delete this; 1162 delete this;
1163} 1163}
1164 1164
1165void CPumpKINDlg::LogLineToScreen(LPCTSTR str) 1165void CPumpKINDlg::LogLineToScreen(LPCTSTR str)
1166{ 1166{
1167 ASSERT(m_LogLength); 1167 ASSERT(m_LogLength);
1168 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){ 1168 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){
1169 CTime *t = (CTime*)m_Log.GetItemData(0); 1169 CTime *t = (CTime*)m_Log.GetItemData(0);
1170 if(((DWORD)t)!=LB_ERR){ 1170 if(((DWORD)t)!=LB_ERR){
1171 ASSERT(t); 1171 ASSERT(t);
1172 m_LogTimes.RemoveKey(t); 1172 m_LogTimes.RemoveKey(t);
1173 delete t; 1173 delete t;
1174 } 1174 }
1175 m_Log.DeleteString(0); 1175 m_Log.DeleteString(0);
1176 } 1176 }
1177int i = m_Log.AddString(str); 1177int i = m_Log.AddString(str);
1178 ASSERT(i!=LB_ERR); 1178 ASSERT(i!=LB_ERR);
1179CTime *t = new CTime(CTime::GetCurrentTime()); 1179CTime *t = new CTime(CTime::GetCurrentTime());
1180 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t)); 1180 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t));
1181 m_Log.SetCurSel(i); 1181 m_Log.SetCurSel(i);
1182} 1182}
1183 1183
1184void CPumpKINDlg::LogLine(UINT msgID) 1184void CPumpKINDlg::LogLine(UINT msgID)
1185{ 1185{
1186CString tmp; 1186CString tmp;
1187 tmp.Format(msgID); 1187 tmp.Format(msgID);
1188 LogLine(tmp); 1188 LogLine(tmp);
1189} 1189}
1190 1190
1191void CXferSocket::TurnSlashes(CString& fn,BOOL bBack) 1191void CXferSocket::TurnSlashes(CString& fn,BOOL bBack)
1192{ 1192{
1193 ints = fn.Find(bBack?'/':'\\'); 1193 ints = fn.Find(bBack?'/':'\\');
1194 while(s>=0){ 1194 while(s>=0){
1195 fn.SetAt(s,bBack?'\\':'/'); 1195 fn.SetAt(s,bBack?'\\':'/');
1196 s = fn.Find(bBack?'/':'\\'); 1196 s = fn.Find(bBack?'/':'\\');
1197 } 1197 }
1198} 1198}
1199 1199
1200CString CXferSocket::ApplyRoot(LPCTSTR fileName) 1200CString CXferSocket::ApplyRoot(LPCTSTR fileName)
1201{ 1201{
1202 ASSERT(m_Daddy); 1202 ASSERT(m_Daddy);
1203CString fn = fileName; 1203CString fn = fileName;
1204CString rv = m_Daddy->m_TFTPRoot; 1204CString rv = m_Daddy->m_TFTPRoot;
1205 if(rv.IsEmpty()) 1205 if(rv.IsEmpty())
1206 rv = "."; 1206 rv = ".";
1207 if(rv[rv.GetLength()-1]!='\\') 1207 if(rv[rv.GetLength()-1]!='\\')
1208 rv+="\\"; 1208 rv+="\\";
1209 while((!fn.IsEmpty()) && fn[0]=='\\') 1209 while((!fn.IsEmpty()) && fn[0]=='\\')
1210 fn=fn.Mid(1); 1210 fn=fn.Mid(1);
1211 rv+=fn; 1211 rv+=fn;
1212 return rv; 1212 return rv;
1213} 1213}
1214 1214
1215void CPumpKINDlg::OnOptions() 1215void CPumpKINDlg::OnOptions()
1216{ 1216{
1217CPropertySheet cps(IDS_TITLE_OPTIONS,this); 1217CPropertySheet cps(IDS_TITLE_OPTIONS,this);
1218CPropsServer server; 1218CPropsServer server;
1219CPropsNetwork network; 1219CPropsNetwork network;
1220CPropsSounds sounds; 1220CPropsSounds sounds;
1221CPropsACL acl; 1221CPropsACL acl;
1222 1222
1223 server.m_RRQMode=m_RRQMode; 1223 server.m_RRQMode=m_RRQMode;
1224 server.m_TFTPRoot=m_TFTPRoot; 1224 server.m_TFTPRoot=m_TFTPRoot;
1225 server.m_TFTPSubdirs=m_bTFTPSubdirs; 1225 server.m_TFTPSubdirs=m_bTFTPSubdirs;
1226 server.m_WRQMode=m_WRQMode; 1226 server.m_WRQMode=m_WRQMode;
1227 server.m_PromptTimeOut=m_PromptTimeOut; 1227 server.m_PromptTimeOut=m_PromptTimeOut;
1228 server.m_LogFile=m_LogFile; 1228 server.m_LogFile=m_LogFile;
1229 1229
1230 network.m_ListenPort=m_ListenPort; 1230 network.m_ListenPort=m_ListenPort;
1231 network.m_ListenAddress=m_ListenAddress;
1231 network.m_SpeakPort=m_SpeakPort; 1232 network.m_SpeakPort=m_SpeakPort;
1232 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds(); 1233 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds();
1233 network.m_BlockSize=m_BlockSize; 1234 network.m_BlockSize=m_BlockSize;
1234 1235
1235 sounds.m_Request = m_bnwRequest; 1236 sounds.m_Request = m_bnwRequest;
1236 sounds.m_Success = m_bnwSuccess; 1237 sounds.m_Success = m_bnwSuccess;
1237 sounds.m_Abort = m_bnwAbort; 1238 sounds.m_Abort = m_bnwAbort;
1238 1239
1239 acl.m_rulist = m_aclRules; 1240 acl.m_rulist = m_aclRules;
1240 1241
1241 cps.AddPage(&server); 1242 cps.AddPage(&server);
1242 cps.AddPage(&network); 1243 cps.AddPage(&network);
1243 cps.AddPage(&sounds); 1244 cps.AddPage(&sounds);
1244 cps.AddPage(&acl); 1245 cps.AddPage(&acl);
1245 if(cps.DoModal()==IDOK){ 1246 if(cps.DoModal()==IDOK){
1246 m_RRQMode=server.m_RRQMode; 1247 m_RRQMode=server.m_RRQMode;
1247 m_TFTPRoot=server.m_TFTPRoot; 1248 m_TFTPRoot=server.m_TFTPRoot;
1248 m_bTFTPSubdirs=server.m_TFTPSubdirs; 1249 m_bTFTPSubdirs=server.m_TFTPSubdirs;
1249 m_WRQMode=server.m_WRQMode; 1250 m_WRQMode=server.m_WRQMode;
1250 m_PromptTimeOut=server.m_PromptTimeOut; 1251 m_PromptTimeOut=server.m_PromptTimeOut;
1251 m_LogFile=server.m_LogFile; 1252 m_LogFile=server.m_LogFile;
1252 1253
1253 m_ListenPort=network.m_ListenPort; 1254 m_ListenPort=network.m_ListenPort;
1255 m_ListenAddress=network.m_ListenAddress;
1254 m_SpeakPort=network.m_SpeakPort; 1256 m_SpeakPort=network.m_SpeakPort;
1255 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut); 1257 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut);
1256 m_BlockSize=network.m_BlockSize; 1258 m_BlockSize=network.m_BlockSize;
1257 1259
1258 m_bnwRequest = sounds.m_Request; 1260 m_bnwRequest = sounds.m_Request;
1259 m_bnwSuccess = sounds.m_Success; 1261 m_bnwSuccess = sounds.m_Success;
1260 m_bnwAbort = sounds.m_Abort; 1262 m_bnwAbort = sounds.m_Abort;
1261 1263
1262 m_aclRules = acl.m_rulist; 1264 m_aclRules = acl.m_rulist;
1263 1265
1264 m_lastlogerr.Empty(); 1266 m_lastlogerr.Empty();
1265 } 1267 }
1266} 1268}
1267 1269
1268BOOL CRRQSocket::ConfirmRequest() 1270BOOL CRRQSocket::ConfirmRequest()
1269{ 1271{
1270CConfirmRRQDlg cd(NULL); 1272CConfirmRRQDlg cd(NULL);
1271 cd.m_Daddy=this; 1273 cd.m_Daddy=this;
1272 cd.m_File=m_FileName; 1274 cd.m_File=m_FileName;
1273 cd.m_Host=inet_ntoa(m_Peer.sin_addr); 1275 cd.m_Host=inet_ntoa(m_Peer.sin_addr);
1274 if(cd.DoModal()==IDOK) 1276 if(cd.DoModal()==IDOK)
1275 return TRUE; 1277 return TRUE;
1276 return FALSE; 1278 return FALSE;
1277} 1279}
1278 1280
1279CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) 1281CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
1280 : CXferSocket(daddy,fileName,type,sin) 1282 : CXferSocket(daddy,fileName,type,sin)
1281{ 1283{
1282 state=stateNone; 1284 state=stateNone;
1283 m_ACK=0; 1285 m_ACK=0;
1284 m_LastSlack=0; 1286 m_LastSlack=0;
1285 m_bResume=FALSE; 1287 m_bResume=FALSE;
1286} 1288}
1287 1289
1288BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) 1290BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
1289{ 1291{
1290 if(!CAsyncSocket::Create(0,SOCK_DGRAM)) 1292 if(!CAsyncSocket::Create(0,SOCK_DGRAM))
1291 return FALSE; 1293 return FALSE;
1292 ASSERT(m_Daddy); 1294 ASSERT(m_Daddy);
1293 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); 1295 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
1294 m_Daddy->m_Xfers[m_hSocket]=this; 1296 m_Daddy->m_Xfers[m_hSocket]=this;
1295 UpdateList(); 1297 UpdateList();
1296CString lf; 1298CString lf;
1297 if(!localFile) { 1299 if(!localFile) {
1298 lf = m_FileName; 1300 lf = m_FileName;
1299 TurnSlashes(lf,TRUE); 1301 TurnSlashes(lf,TRUE);
1300 } 1302 }
1301CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf); 1303CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf);
1302 if(!localFile){// This is an incoming request.. 1304 if(!localFile){// This is an incoming request..
1303 if(CheckBadRelativeness(m_FileName)){ 1305 if(CheckBadRelativeness(m_FileName)){
1304 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1306 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1305 return TRUE; 1307 return TRUE;
1306 } 1308 }
1307 BOOL exists; 1309 BOOL exists;
1308 if(!_access((LPCTSTR)fn,0)) 1310 if(!_access((LPCTSTR)fn,0))
1309 m_Rename=exists=TRUE; 1311 m_Rename=exists=TRUE;
1310 else 1312 else
1311 m_Rename=exists=FALSE; 1313 m_Rename=exists=FALSE;
1312 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr); 1314 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr);
1313 if(atar<0) 1315 if(atar<0)
1314 atar=m_Daddy->m_WRQMode; 1316 atar=m_Daddy->m_WRQMode;
1315 switch(atar){ 1317 switch(atar){
1316 case CPumpKINDlg::wrqTakeAll: 1318 case CPumpKINDlg::wrqTakeAll:
1317 if(exists){ 1319 if(exists){
1318 if(!RenameFile(fn)){ 1320 if(!RenameFile(fn)){
1319 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME); 1321 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME);
1320 return TRUE; 1322 return TRUE;
1321 } 1323 }
1322 } 1324 }
1323 break; 1325 break;
1324 case CPumpKINDlg::wrqConfirmIfExists: 1326 case CPumpKINDlg::wrqConfirmIfExists:
1325 if(!exists) 1327 if(!exists)
1326 break; 1328 break;
1327 case CPumpKINDlg::wrqAlwaysConfirm: 1329 case CPumpKINDlg::wrqAlwaysConfirm:
1328 if(exists) 1330 if(exists)
1329 m_bResume=TRUE; 1331 m_bResume=TRUE;
1330 if(ConfirmRequest()){ 1332 if(ConfirmRequest()){
1331 if(m_Rename){ 1333 if(m_Rename){
1332 RenameFile(fn); 1334 RenameFile(fn);
1333 if(SaveAs(fn)) 1335 if(SaveAs(fn))
1334 break; 1336 break;
1335 }else 1337 }else
1336 break; 1338 break;
1337 } 1339 }
1338 default: 1340 default:
1339 TRACE1("Unexpected access target: %d\n",atar); 1341 TRACE1("Unexpected access target: %d\n",atar);
1340 case CPumpKINDlg::wrqDenyAll: 1342 case CPumpKINDlg::wrqDenyAll:
1341 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1343 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1342 return TRUE; 1344 return TRUE;
1343 } 1345 }
1344 } 1346 }
1345CFileException e; 1347CFileException e;
1346 if(!m_File.Open( 1348 if(!m_File.Open(
1347 fn, 1349 fn,
1348 m_bResume 1350 m_bResume
1349 ?(CFile::modeWrite|CFile::shareDenyWrite) 1351 ?(CFile::modeWrite|CFile::shareDenyWrite)
1350 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite), 1352 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite),
1351 &e 1353 &e
1352 )){ 1354 )){
1353 if(localFile){// Outgoing request 1355 if(localFile){// Outgoing request
1354 CString tmp; 1356 CString tmp;
1355 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn); 1357 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn);
1356 m_Daddy->LogLine(tmp); 1358 m_Daddy->LogLine(tmp);
1357 return FALSE; 1359 return FALSE;
1358 }else{ 1360 }else{
1359 Deny(&e); 1361 Deny(&e);
1360 return TRUE; 1362 return TRUE;
1361 } 1363 }
1362 } 1364 }
1363 if(hostName){ 1365 if(hostName){
1364 m_HostName=hostName; 1366 m_HostName=hostName;
1365 1367
1366 CString tmp; 1368 CString tmp;
1367 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName); 1369 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName);
1368 m_Daddy->LogLine(tmp); 1370 m_Daddy->LogLine(tmp);
1369 1371
1370 CString inAddr = hostName; 1372 CString inAddr = hostName;
1371 int at = inAddr.Find('@'); 1373 int at = inAddr.Find('@');
1372 if(at>=0) 1374 if(at>=0)
1373 inAddr=inAddr.Mid(at+1); 1375 inAddr=inAddr.Mid(at+1);
1374 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ 1376 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
1375 ASSERT(!m_wndResolver); 1377 ASSERT(!m_wndResolver);
1376 m_wndResolver = new CResolver(this); 1378 m_wndResolver = new CResolver(this);
1377 ASSERT(m_wndResolver); 1379 ASSERT(m_wndResolver);
1378 return m_wndResolver->Resolve(); 1380 return m_wndResolver->Resolve();
1379 }else{ 1381 }else{
1380 OnHostKnown(); 1382 OnHostKnown();
1381 return TRUE; 1383 return TRUE;
@@ -1750,427 +1752,427 @@ UINT ptr = 0;
1750 while(p){ 1752 while(p){
1751 CString n,v; 1753 CString n,v;
1752 o.GetNextAssoc(p,n,v); 1754 o.GetNextAssoc(p,n,v);
1753 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1755 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1754 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1756 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1755 } 1757 }
1756 } 1758 }
1757} 1759}
1758void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1760void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1759{ 1761{
1760 // MAY BE DANGEROUS! 1762 // MAY BE DANGEROUS!
1761UINT ptr = 0; 1763UINT ptr = 0;
1762 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1764 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1763 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1765 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1764 if(ops){ 1766 if(ops){
1765 tftpOptions& o = *ops; 1767 tftpOptions& o = *ops;
1766 POSITION p = o.GetStartPosition(); 1768 POSITION p = o.GetStartPosition();
1767 while(p){ 1769 while(p){
1768 CString n,v; 1770 CString n,v;
1769 o.GetNextAssoc(p,n,v); 1771 o.GetNextAssoc(p,n,v);
1770 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1772 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1771 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1773 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1772 } 1774 }
1773 } 1775 }
1774} 1776}
1775void tftp::tftpOACK::Set(tftpOptions* ops) 1777void tftp::tftpOACK::Set(tftpOptions* ops)
1776{ 1778{
1777 ASSERT(ops); 1779 ASSERT(ops);
1778UINT ptr = 0; 1780UINT ptr = 0;
1779tftpOptions& o = *ops; 1781tftpOptions& o = *ops;
1780POSITION p = o.GetStartPosition(); 1782POSITION p = o.GetStartPosition();
1781 while(p){ 1783 while(p){
1782 CString n,v; 1784 CString n,v;
1783 o.GetNextAssoc(p,n,v); 1785 o.GetNextAssoc(p,n,v);
1784 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1786 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1785 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1787 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1786 } 1788 }
1787} 1789}
1788 1790
1789void CWRQSocket::OnResolved() 1791void CWRQSocket::OnResolved()
1790{ 1792{
1791 CXferSocket::OnResolved(); 1793 CXferSocket::OnResolved();
1792 OnHostKnown(); 1794 OnHostKnown();
1793} 1795}
1794 1796
1795void CWRQSocket::OnHostKnown() 1797void CWRQSocket::OnHostKnown()
1796{ 1798{
1797 ASSERT(m_Daddy); 1799 ASSERT(m_Daddy);
1798 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort); 1800 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
1799tftp::tftpOptions o; 1801tftp::tftpOptions o;
1800CString v; 1802CString v;
1801 o[tftpoTSize]="0"; 1803 o[tftpoTSize]="0";
1802 if(m__blkSize){ 1804 if(m__blkSize){
1803 v.Format("%u",m__blkSize); 1805 v.Format("%u",m__blkSize);
1804 o[tftpoBSize]=v; 1806 o[tftpoBSize]=v;
1805 } 1807 }
1806 if(m__timeOut){ 1808 if(m__timeOut){
1807 v.Format("%u",m__timeOut); 1809 v.Format("%u",m__timeOut);
1808 o[tftpoTOut]=v; 1810 o[tftpoTOut]=v;
1809 } 1811 }
1810 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o)); 1812 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o));
1811 ASSERT(p); 1813 ASSERT(p);
1812 p->SetOpcode(tftp::opRRQ); 1814 p->SetOpcode(tftp::opRRQ);
1813 p->data.m_RRQ.Set(m_FileName,m_Type,&o); 1815 p->data.m_RRQ.Set(m_FileName,m_Type,&o);
1814 PostTFTP(p,TRUE); 1816 PostTFTP(p,TRUE);
1815 state=stateInit; 1817 state=stateInit;
1816 UpdateList(); 1818 UpdateList();
1817} 1819}
1818 1820
1819void CPumpKINDlg::OnClose() 1821void CPumpKINDlg::OnClose()
1820{ 1822{
1821 OnTrayShowpumpkinwindow(); 1823 OnTrayShowpumpkinwindow();
1822} 1824}
1823 1825
1824void CPumpKINDlg::OnTrayShowpumpkinwindow() 1826void CPumpKINDlg::OnTrayShowpumpkinwindow()
1825{ 1827{
1826 if(IsWindowVisible()){ 1828 if(IsWindowVisible()){
1827 m_bShown=FALSE; 1829 m_bShown=FALSE;
1828 ShowWindow(SW_HIDE); 1830 ShowWindow(SW_HIDE);
1829 }else{ 1831 }else{
1830 m_bShown=TRUE; 1832 m_bShown=TRUE;
1831 ShowWindow(SW_SHOW); 1833 ShowWindow(SW_SHOW);
1832 SetForegroundWindow(); 1834 SetForegroundWindow();
1833 SetFocus(); 1835 SetFocus();
1834 } 1836 }
1835} 1837}
1836 1838
1837void CPumpKINDlg::OnTrayExit() 1839void CPumpKINDlg::OnTrayExit()
1838{ 1840{
1839 OnExit(); 1841 OnExit();
1840} 1842}
1841 1843
1842void CPumpKINDlg::OnTrayAboutpumpkin() 1844void CPumpKINDlg::OnTrayAboutpumpkin()
1843{ 1845{
1844CAboutDlg dlgAbout; 1846CAboutDlg dlgAbout;
1845 dlgAbout.DoModal(); 1847 dlgAbout.DoModal();
1846} 1848}
1847 1849
1848void CPumpKINDlg::OnTrayFetchfile() 1850void CPumpKINDlg::OnTrayFetchfile()
1849{ 1851{
1850 OnGet(); 1852 OnGet();
1851} 1853}
1852 1854
1853void CPumpKINDlg::OnTrayHelp() 1855void CPumpKINDlg::OnTrayHelp()
1854{ 1856{
1855 OnHelp(); 1857 OnHelp();
1856} 1858}
1857 1859
1858void CPumpKINDlg::OnTrayOptions() 1860void CPumpKINDlg::OnTrayOptions()
1859{ 1861{
1860 OnOptions(); 1862 OnOptions();
1861} 1863}
1862 1864
1863void CPumpKINDlg::OnTraySendfile() 1865void CPumpKINDlg::OnTraySendfile()
1864{ 1866{
1865 OnPut(); 1867 OnPut();
1866} 1868}
1867 1869
1868void CPumpKINDlg::LoadSettings() 1870void CPumpKINDlg::LoadSettings()
1869{ 1871{
1870CWinApp *app = AfxGetApp(); 1872CWinApp *app = AfxGetApp();
1871 ASSERT(app); 1873 ASSERT(app);
1872 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen); 1874 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen);
1873 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest); 1875 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest);
1874 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess); 1876 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess);
1875 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort); 1877 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort);
1876 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1878 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1877 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1879 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1880 m_ListenAddress=app->GetProfileString("TFTPSettings","ListenAddress",m_ListenAddress);
1878 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength); 1881 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength);
1879 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1882 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1880 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1883 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1881 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1884 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1882 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1885 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1883 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile); 1886 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile);
1884 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds())); 1887 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()));
1885 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1888 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1886 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds())); 1889 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()));
1887 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1890 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1888 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown); 1891 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown);
1889 if(m_TFTPRoot.IsEmpty()){ 1892 if(m_TFTPRoot.IsEmpty()){
1890 DWORD dL = ::GetCurrentDirectory(0,NULL); 1893 DWORD dL = ::GetCurrentDirectory(0,NULL);
1891 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL))); 1894 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL)));
1892 m_TFTPRoot.ReleaseBuffer(); 1895 m_TFTPRoot.ReleaseBuffer();
1893 } 1896 }
1894 ::SetCurrentDirectory(m_TFTPRoot); 1897 ::SetCurrentDirectory(m_TFTPRoot);
1895 m_aclRules.LoadProfile(app); 1898 m_aclRules.LoadProfile(app);
1896} 1899}
1897 1900
1898void CPumpKINDlg::SaveSettings() 1901void CPumpKINDlg::SaveSettings()
1899{ 1902{
1900CWinApp *app = AfxGetApp(); 1903CWinApp *app = AfxGetApp();
1901 ASSERT(app); 1904 ASSERT(app);
1902 app->WriteProfileInt("TFTPSettings","Listen",m_bListen); 1905 app->WriteProfileInt("TFTPSettings","Listen",m_bListen);
1903 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest); 1906 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest);
1904 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess); 1907 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess);
1905 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort); 1908 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort);
1906 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1909 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1907 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1910 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1911 app->WriteProfileString("TFTPSettings","ListenAddress",m_ListenAddress);
1908 app->WriteProfileInt("UISettings","LogLength",m_LogLength); 1912 app->WriteProfileInt("UISettings","LogLength",m_LogLength);
1909 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1913 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1910 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1914 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1911 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1915 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1912 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1916 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1913 app->WriteProfileString("General","LogFile",m_LogFile); 1917 app->WriteProfileString("General","LogFile",m_LogFile);
1914 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()); 1918 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds());
1915 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1919 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1916 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()); 1920 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds());
1917 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1921 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1918 app->WriteProfileInt("UISettings","Visble",m_bShown); 1922 app->WriteProfileInt("UISettings","Visble",m_bShown);
1919 m_aclRules.SaveProfile(app); 1923 m_aclRules.SaveProfile(app);
1920} 1924}
1921 1925
1922void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 1926void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
1923{ 1927{
1924 CDialog::OnWindowPosChanging(lpwndpos); 1928 CDialog::OnWindowPosChanging(lpwndpos);
1925 if(!m_bExiting){ 1929 if(!m_bExiting){
1926 if(m_bShown){ 1930 if(m_bShown){
1927 lpwndpos->flags&=~SWP_HIDEWINDOW; 1931 lpwndpos->flags&=~SWP_HIDEWINDOW;
1928 lpwndpos->flags|=SWP_SHOWWINDOW; 1932 lpwndpos->flags|=SWP_SHOWWINDOW;
1929 }else{ 1933 }else{
1930 lpwndpos->flags&=~SWP_SHOWWINDOW; 1934 lpwndpos->flags&=~SWP_SHOWWINDOW;
1931 lpwndpos->flags|=SWP_HIDEWINDOW; 1935 lpwndpos->flags|=SWP_HIDEWINDOW;
1932 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu)) 1936 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu))
1933 GetDesktopWindow()->SetForegroundWindow(); 1937 GetDesktopWindow()->SetForegroundWindow();
1934 } 1938 }
1935 } 1939 }
1936} 1940}
1937 1941
1938CString CXferSocket::ApplyRootGently(LPCTSTR fn) 1942CString CXferSocket::ApplyRootGently(LPCTSTR fn)
1939{ 1943{
1940CString f = fn; 1944CString f = fn;
1941CString rv = f; 1945CString rv = f;
1942 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0) 1946 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0)
1943 rv = ApplyRoot(f); 1947 rv = ApplyRoot(f);
1944 return rv; 1948 return rv;
1945} 1949}
1946 1950
1947BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file) 1951BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file)
1948{ 1952{
1949CString tmp = file; 1953CString tmp = file;
1950 if(tmp.IsEmpty()) 1954 if(tmp.IsEmpty())
1951 return FALSE; 1955 return FALSE;
1952 if(tmp.Find("..")>=0) 1956 if(tmp.Find("..")>=0)
1953 return TRUE; 1957 return TRUE;
1954 if(tmp.Find(":")>=0) 1958 if(tmp.Find(":")>=0)
1955 return TRUE; 1959 return TRUE;
1956 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0) 1960 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0)
1957 return TRUE; 1961 return TRUE;
1958 return FALSE; 1962 return FALSE;
1959} 1963}
1960 1964
1961void CAboutDlg::OnKlevernet() 1965void CAboutDlg::OnKlevernet()
1962{ 1966{
1963CString url; 1967CString url;
1964 url.LoadString(IDS_KLEVERNET_URL); 1968 url.LoadString(IDS_KLEVERNET_URL);
1965 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED); 1969 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED);
1966} 1970}
1967 1971
1968BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg) 1972BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg)
1969{ 1973{
1970 // CG: The following block was added by the ToolTips component. 1974 // CG: The following block was added by the ToolTips component.
1971 { 1975 {
1972 // Let the ToolTip process this message. 1976 // Let the ToolTip process this message.
1973 m_tooltip.RelayEvent(pMsg); 1977 m_tooltip.RelayEvent(pMsg);
1974 1978
1975 return CDialog::PreTranslateMessage(pMsg); 1979 return CDialog::PreTranslateMessage(pMsg);
1976 } 1980 }
1977} 1981}
1978 1982
1979void CPumpKINDlg::OnSelchangeLog() 1983void CPumpKINDlg::OnSelchangeLog()
1980{ 1984{
1981int sel = m_Log.GetCurSel(); 1985int sel = m_Log.GetCurSel();
1982 if(sel==LB_ERR){ 1986 if(sel==LB_ERR){
1983 TRACE0("Error retrieving selection\n"); 1987 TRACE0("Error retrieving selection\n");
1984 }else{ 1988 }else{
1985 CTime *t = (CTime*)m_Log.GetItemData(sel); 1989 CTime *t = (CTime*)m_Log.GetItemData(sel);
1986 ASSERT(t); 1990 ASSERT(t);
1987 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log); 1991 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log);
1988 } 1992 }
1989} 1993}
1990 1994
1991void CPumpKINDlg::OnTrayOpenfilesfolder() 1995void CPumpKINDlg::OnTrayOpenfilesfolder()
1992{ 1996{
1993 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT); 1997 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT);
1994} 1998}
1995 1999
1996void CPumpKINDlg::OnDropFiles(HDROP hDropInfo) 2000void CPumpKINDlg::OnDropFiles(HDROP hDropInfo)
1997{ 2001{
1998UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0); 2002UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0);
1999 ASSERT(files); 2003 ASSERT(files);
2000 for(UINT file=0;file<files;file++){ 2004 for(UINT file=0;file<files;file++){
2001 CString theFile; 2005 CString theFile;
2002 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0); 2006 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0);
2003 ASSERT(fileNameLength); 2007 ASSERT(fileNameLength);
2004 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength); 2008 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength);
2005 theFile.ReleaseBuffer(); 2009 theFile.ReleaseBuffer();
2006 // Send it over! 2010 // Send it over!
2007 CRequestDlg crd(NULL); 2011 CRequestDlg crd(NULL);
2008 crd.m_Drop=TRUE; 2012 crd.m_Drop=TRUE;
2009 crd.m_Put=TRUE; 2013 crd.m_Put=TRUE;
2010 crd.m_BSize=m_BlockSize; 2014 crd.m_BSize=m_BlockSize;
2011 crd.m_LocalFile=theFile; 2015 crd.m_LocalFile=theFile;
2012 if(crd.DoModal()==IDOK){ 2016 if(crd.DoModal()==IDOK){
2013 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 2017 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
2014 if(crd.m_BSize) 2018 if(crd.m_BSize)
2015 socket->m__blkSize=crd.m_BSize; 2019 socket->m__blkSize=crd.m_BSize;
2016 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 2020 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
2017 socket->Destroy(); 2021 socket->Destroy();
2018 } 2022 }
2019 } 2023 }
2020 ::DragFinish(hDropInfo); 2024 ::DragFinish(hDropInfo);
2021} 2025}
2022 2026
2023void CPumpKINDlg::OnCancel() 2027void CPumpKINDlg::OnCancel()
2024{ 2028{
2025 OnClose(); 2029 OnClose();
2026} 2030}
2027 2031
2028CPumpKINDlg::~CPumpKINDlg() 2032CPumpKINDlg::~CPumpKINDlg()
2029{ 2033{
2030 delete m_Trayer; 2034 delete m_Trayer;
2031 delete m_Retrier; 2035 delete m_Retrier;
2032} 2036}
2033 2037
2034void CXferSocket::OnRetry() 2038void CXferSocket::OnRetry()
2035{ 2039{
2036 if(!m_Retry){ 2040 if(!m_Retry){
2037 TRACE("Retrying unretriable..\n"); 2041 TRACE("Retrying unretriable..\n");
2038 return; 2042 return;
2039 } 2043 }
2040 TRACE0("Retrying..\n"); 2044 TRACE0("Retrying..\n");
2041 m_bRetry=TRUE; 2045 m_bRetry=TRUE;
2042 PostTFTP(tftp::Copy(m_Retry)); 2046 PostTFTP(tftp::Copy(m_Retry));
2043 m_bRetry=FALSE; 2047 m_bRetry=FALSE;
2044} 2048}
2045 2049
2046tftp* tftp::Copy(tftp *src) 2050tftp* tftp::Copy(tftp *src)
2047{ 2051{
2048 ASSERT(src); 2052 ASSERT(src);
2049 ASSERT(src->length); 2053 ASSERT(src->length);
2050tftp* rv = Allocate(src->length); 2054tftp* rv = Allocate(src->length);
2051 ASSERT(rv); 2055 ASSERT(rv);
2052 memmove(rv,src,tftpSlackSize+src->length); 2056 memmove(rv,src,tftpSlackSize+src->length);
2053 return rv; 2057 return rv;
2054} 2058}
2055 2059
2056void CXferSocket::SetTry(tftp *p) 2060void CXferSocket::SetTry(tftp *p)
2057{ 2061{
2058 if(m_Retry) 2062 if(m_Retry)
2059 delete m_Retry; 2063 delete m_Retry;
2060 m_Retry=p?tftp::Copy(p):NULL; 2064 m_Retry=p?tftp::Copy(p):NULL;
2061} 2065}
2062 2066
2063void CPumpKINDlg::OnHelp() 2067void CPumpKINDlg::OnHelp()
2064{ 2068{
2065 AfxGetApp()->WinHelp(0,HELP_FINDER); 2069 AfxGetApp()->WinHelp(0,HELP_FINDER);
2066} 2070}
2067 2071
2068BOOL CListenSocket::SetListen(BOOL b) { 2072BOOL CListenSocket::SetListen(BOOL b) {
2069 ASSERT(m_Daddy); 2073 ASSERT(m_Daddy);
2070 if(b==m_bListen) 2074 if(b==m_bListen) return TRUE;
2071 return TRUE; 2075 if(!b) {
2072 if(b) {
2073 if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM))
2074 return FALSE;
2075 return m_bListen=TRUE;
2076 }else{
2077 Close(); m_bListen=FALSE; 2076 Close(); m_bListen=FALSE;
2078 return TRUE; 2077 return TRUE;
2079 } 2078 }
2079 return m_bListen=Create(m_Daddy->m_ListenPort,SOCK_DGRAM,
2080 FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT|FD_CONNECT|FD_CLOSE,
2081 m_Daddy->m_ListenAddress.IsEmpty()?NULL:(LPCTSTR)m_Daddy->m_ListenAddress);
2080} 2082}
2081 2083
2082void CPumpKINDlg::OnListening() 2084void CPumpKINDlg::OnListening()
2083{ 2085{
2084 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) { 2086 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) {
2085 TRACE0("Failed to create socket\n"); 2087 TRACE0("Failed to create socket\n");
2086 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2088 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2087 } 2089 }
2088 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2090 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2089 m_bListen=m_Listener.m_bListen; 2091 m_bListen=m_Listener.m_bListen;
2090} 2092}
2091 2093
2092void CPumpKINDlg::OnTrayListen() 2094void CPumpKINDlg::OnTrayListen()
2093{ 2095{
2094 if(!m_Listener.SetListen(!m_Listener.m_bListen)) { 2096 if(!m_Listener.SetListen(!m_Listener.m_bListen)) {
2095 TRACE0("Failed to create socket\n"); 2097 TRACE0("Failed to create socket\n");
2096 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2098 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2097 } 2099 }
2098 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2100 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2099 m_bListen=m_Listener.m_bListen; 2101 m_bListen=m_Listener.m_bListen;
2100} 2102}
2101 2103
2102void CPumpKINDlg::LogLine(LPCTSTR str) 2104void CPumpKINDlg::LogLine(LPCTSTR str)
2103{ 2105{
2104 LogLineToScreen(str); 2106 LogLineToScreen(str);
2105 if(!m_LogFile.IsEmpty()) { 2107 if(!m_LogFile.IsEmpty()) {
2106 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) { 2108 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) {
2107 if(m_lastlogerr!=m_LogFile) { 2109 if(m_lastlogerr!=m_LogFile) {
2108 CString tmp; 2110 CString tmp;
2109 tmp.Format(IDS_LOG_LOGERROR,m_LogFile); 2111 tmp.Format(IDS_LOG_LOGERROR,m_LogFile);
2110 LogLineToScreen(tmp); 2112 LogLineToScreen(tmp);
2111 m_lastlogerr=m_LogFile; 2113 m_lastlogerr=m_LogFile;
2112 } 2114 }
2113 } 2115 }
2114 } 2116 }
2115} 2117}
2116 2118
2117void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 2119void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
2118{ 2120{
2119 CDialog::OnGetMinMaxInfo(lpMMI); 2121 CDialog::OnGetMinMaxInfo(lpMMI);
2120 if(m_MinSize.cx>0 && m_MinSize.cy>0){ 2122 if(m_MinSize.cx>0 && m_MinSize.cy>0){
2121 lpMMI->ptMinTrackSize.x = m_MinSize.cx; 2123 lpMMI->ptMinTrackSize.x = m_MinSize.cx;
2122 lpMMI->ptMinTrackSize.y = m_MinSize.cy; 2124 lpMMI->ptMinTrackSize.y = m_MinSize.cy;
2123 } 2125 }
2124} 2126}
2125 2127
2126void CPumpKINDlg::OnSize(UINT nType, int cx, int cy) 2128void CPumpKINDlg::OnSize(UINT nType, int cx, int cy)
2127{ 2129{
2128 CDialog::OnSize(nType, cx, cy); 2130 CDialog::OnSize(nType, cx, cy);
2129 if(nType==SIZE_RESTORED) 2131 if(nType==SIZE_RESTORED)
2130 RecalcLayout(cx,cy); 2132 RecalcLayout(cx,cy);
2131} 2133}
2132 2134
2133void CPumpKINDlg::RecalcLayout(int,int) 2135void CPumpKINDlg::RecalcLayout(int,int)
2134{ 2136{
2135 CRect wrc; 2137 CRect wrc;
2136 GetClientRect(&wrc); 2138 GetClientRect(&wrc);
2137 AdjustButton(m_GetCtl,wrc); 2139 AdjustButton(m_GetCtl,wrc);
2138 AdjustButton(m_PutCtl,wrc); 2140 AdjustButton(m_PutCtl,wrc);
2139 AdjustButton(m_AbortCtl,wrc); 2141 AdjustButton(m_AbortCtl,wrc);
2140 AdjustButton(m_HelpCtl,wrc); 2142 AdjustButton(m_HelpCtl,wrc);
2141 AdjustButton(m_ExitCtl,wrc); 2143 AdjustButton(m_ExitCtl,wrc);
2142 AdjustButton(m_OptionsCtl,wrc); 2144 AdjustButton(m_OptionsCtl,wrc);
2143 CRect brc; 2145 CRect brc;
2144 m_List.GetWindowRect(&brc); ScreenToClient(&brc); 2146 m_List.GetWindowRect(&brc); ScreenToClient(&brc);
2145 m_List.SetWindowPos( 2147 m_List.SetWindowPos(
2146 0, 2148 0,
2147 brc.left, brc.top, 2149 brc.left, brc.top,
2148 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top, 2150 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top,
2149 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2151 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2150 m_Log.GetWindowRect(&brc); ScreenToClient(&brc); 2152 m_Log.GetWindowRect(&brc); ScreenToClient(&brc);
2151 m_Log.SetWindowPos( 2153 m_Log.SetWindowPos(
2152 0, 2154 0,
2153 brc.left, brc.top, 2155 brc.left, brc.top,
2154 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top, 2156 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top,
2155 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2157 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2156 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc); 2158 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
2157 m_ListenCtl.SetWindowPos( 2159 m_ListenCtl.SetWindowPos(
2158 0, 2160 0,
2159 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen, 2161 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen,
2160 0,0, 2162 0,0,
2161 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2163 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2162 int i = m_Log.GetCount(); 2164 int i = m_Log.GetCount();
2163 if(i!=LB_ERR) 2165 if(i!=LB_ERR)
2164 m_Log.SetCurSel(i-1); 2166 m_Log.SetCurSel(i-1);
2165} 2167}
2166 2168
2167void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc) 2169void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc)
2168{ 2170{
2169 CRect brc; 2171 CRect brc;
2170 w.GetWindowRect(&brc); ScreenToClient(&brc); 2172 w.GetWindowRect(&brc); ScreenToClient(&brc);
2171 w.SetWindowPos( 2173 w.SetWindowPos(
2172 0, 2174 0,
2173 wrc.right-brc.Width()-m_rightGapButtons, brc.top, 2175 wrc.right-brc.Width()-m_rightGapButtons, brc.top,
2174 0, 0, 2176 0, 0,
2175 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2177 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2176} 2178}