Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1638 lines
64 KiB

  1. /* file: ossHelp.cpp */
  2. #include "mbftpch.h"
  3. #include "mbftper.h"
  4. #include "osshelp.hpp"
  5. #include "strutil.h"
  6. #include <imcsapp.h>
  7. static int nInvalidNameCount = 0;
  8. static char szProshareError[] = "ProshareError#"; /*Localization OK*/
  9. static char szNonStandardCompression[] = "NonStandardCompression"; /*Localization OK*/
  10. LONG CreateFileHeader(LPSTR pFileHeader, WORD pduType, ASNMBFTPDU* GenericPDUStruct);
  11. typedef struct
  12. {
  13. unsigned Second : 5;
  14. unsigned Minute : 6;
  15. unsigned Hour : 5;
  16. } _DOS_Time;
  17. typedef struct
  18. {
  19. unsigned Day : 5;
  20. unsigned Month : 4;
  21. unsigned Year : 7;
  22. } _DOS_Date;
  23. void GenericPDU::FreeMCSBuffer ()
  24. {
  25. if (m_lpEncodedBuffer != NULL)
  26. {
  27. m_pAppletSession->FreeSendDataBuffer((void *) m_lpEncodedBuffer);
  28. m_lpEncodedBuffer = NULL;
  29. }
  30. }
  31. GenericPDU::~GenericPDU()
  32. {
  33. if (m_pAppletSession != NULL)
  34. {
  35. FreeMCSBuffer();
  36. }
  37. else
  38. {
  39. delete m_lpEncodedBuffer;
  40. m_lpEncodedBuffer = NULL;
  41. }
  42. }
  43. FileOfferPDU::FileOfferPDU(LPCSTR lpszFileName, MBFTFILEHANDLE iFileHandle,
  44. LONG FileSize,time_t FileDateTime,
  45. ChannelID wChannelID,BOOL bAcknowledge,int RosterInstance,
  46. unsigned CompressionFlags,
  47. LPCSTR lpszCompressionFormat,
  48. int v42bisP1,
  49. int v42bisP2) : GenericPDU()
  50. {
  51. if(lpszFileName)
  52. {
  53. lstrcpyn(m_szFileName,lpszFileName,sizeof(m_szFileName));
  54. }
  55. else
  56. {
  57. lstrcpy(m_szFileName,"");
  58. }
  59. m_FileHandle = iFileHandle;
  60. m_FileSize = FileSize;
  61. m_FileDateTime = FileDateTime;
  62. m_DataChannelID = wChannelID;
  63. m_bAcknowledge = bAcknowledge;
  64. m_RosterInstance = RosterInstance;
  65. m_CompressionFlags = CompressionFlags;
  66. m_v42bisP1 = v42bisP1;
  67. m_v42bisP2 = v42bisP2;
  68. if(lpszCompressionFormat)
  69. {
  70. lstrcpyn(m_szCompressionFormat,lpszCompressionFormat,sizeof(m_szCompressionFormat));
  71. }
  72. else
  73. {
  74. lstrcpy(m_szCompressionFormat,"");
  75. }
  76. }
  77. unsigned long DecodeTimeDate(GeneralizedTime & ASNDateTime)
  78. {
  79. _DOS_Time DecodeTime;
  80. _DOS_Date DecodeDate;
  81. if(ASNDateTime.utc)
  82. {
  83. //GMDateTime.tm_year = ASNDateTime.year;
  84. DecodeDate.Year = ASNDateTime.year - 80;
  85. }
  86. else
  87. {
  88. }
  89. DecodeDate.Month = ASNDateTime.month;
  90. DecodeDate.Day = ASNDateTime.day;
  91. DecodeTime.Hour = ASNDateTime.hour;
  92. DecodeTime.Minute = ASNDateTime.minute;
  93. DecodeTime.Second = ASNDateTime.second / 2;
  94. //DecodeTime.tm_isdst = -1; //Make best guess about daylight savings...
  95. unsigned * Time, * Date;
  96. Time = (unsigned *)&DecodeTime;
  97. Date = (unsigned *)&DecodeDate;
  98. return(MAKELONG(*Time,*Date));
  99. }
  100. BOOL FileOfferPDU::Encode(void)
  101. {
  102. ASNMBFTPDU GenericPDUStruct;
  103. ASNFilename_Attribute_ FileName;
  104. BOOL bReturn = FALSE;
  105. //struct tm * lpGMDateTime;
  106. ClearStruct(&GenericPDUStruct);
  107. ClearStruct(&FileName);
  108. GenericPDUStruct.choice = ASNfile_OfferPDU_chosen;
  109. FileName.value = m_szFileName;
  110. //lpGMDateTime = localtime(&m_FileDateTime);
  111. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNfilesize = m_FileSize;
  112. unsigned Date = HIWORD(m_FileDateTime);
  113. unsigned Time = LOWORD(m_FileDateTime);
  114. _DOS_Date * lpDate = (_DOS_Date *)&Date;
  115. _DOS_Time * lpTime = (_DOS_Time *)&Time;
  116. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.year = lpDate->Year + 80;
  117. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.month = lpDate->Month;
  118. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.day = lpDate->Day;
  119. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.hour = lpTime->Hour;
  120. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.minute = lpTime->Minute;
  121. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.second = lpTime->Second * 2;
  122. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNdate_and_time_of_creation.utc = TRUE;
  123. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.bit_mask |= ASNfilename_present;
  124. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.bit_mask |= ASNdate_and_time_of_creation_present;
  125. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.bit_mask |= ASNfilesize_present;
  126. GenericPDUStruct.u.ASNfile_OfferPDU.file_header.ASNfilename = &FileName;
  127. GenericPDUStruct.u.ASNfile_OfferPDU.file_handle = (ASNHandle)m_FileHandle;
  128. GenericPDUStruct.u.ASNfile_OfferPDU.data_channel_id = m_DataChannelID;
  129. GenericPDUStruct.u.ASNfile_OfferPDU.ack_flag = (ossBoolean)m_bAcknowledge;
  130. if(m_CompressionFlags & _MBFT_FILE_COMPRESSED)
  131. {
  132. if(m_CompressionFlags & _MBFT_STANDARD_COMPRESSSION)
  133. {
  134. GenericPDUStruct.u.ASNfile_OfferPDU.bit_mask |= ASNFile_OfferPDU_compression_specifier_present;
  135. GenericPDUStruct.u.ASNfile_OfferPDU.ASNFile_OfferPDU_compression_specifier.choice = ASNv42bis_parameters_chosen;
  136. GenericPDUStruct.u.ASNfile_OfferPDU.ASNFile_OfferPDU_compression_specifier.u.ASNv42bis_parameters.p1 = (unsigned short)m_v42bisP1;
  137. GenericPDUStruct.u.ASNfile_OfferPDU.ASNFile_OfferPDU_compression_specifier.u.ASNv42bis_parameters.p2 = (unsigned short)m_v42bisP2;
  138. }
  139. }
  140. //Specifying a non standard compression format is simply too complex and not worth the effort
  141. if(m_RosterInstance)
  142. {
  143. GenericPDUStruct.u.ASNfile_OfferPDU.bit_mask |= ASNroster_instance_present;
  144. GenericPDUStruct.u.ASNfile_OfferPDU.ASNroster_instance = (unsigned short)m_RosterInstance;
  145. }
  146. // Get the needed size for the fileHeader
  147. LONG fileOfferPDUSize = CreateFileHeader(NULL, T127_FILE_OFFER << 8, &GenericPDUStruct);
  148. DBG_SAVE_FILE_LINE
  149. m_lpEncodedBuffer = new char[fileOfferPDUSize];
  150. if(m_lpEncodedBuffer)
  151. {
  152. m_lEncodedDataLength = CreateFileHeader(m_lpEncodedBuffer, (T127_FILE_OFFER << 8 | ASNroster_instance_present << 2), &GenericPDUStruct);
  153. bReturn = TRUE;
  154. }
  155. return(bReturn);
  156. }
  157. FileAcceptPDU::FileAcceptPDU(MBFTFILEHANDLE iFileHandle) : GenericPDU()
  158. {
  159. m_FileHandle = iFileHandle;
  160. }
  161. BOOL FileAcceptPDU::Encode(void)
  162. {
  163. m_lEncodedDataLength = sizeof(T127_FILE_PDU_HEADER);
  164. DBG_SAVE_FILE_LINE
  165. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  166. if (NULL != m_lpEncodedBuffer)
  167. {
  168. T127_FILE_PDU_HEADER* pBuff = (T127_FILE_PDU_HEADER*)m_lpEncodedBuffer;
  169. pBuff->pduType = T127_FILE_ACCEPT;
  170. pBuff->fileHandle = SWAPWORD(m_FileHandle);
  171. return TRUE;
  172. }
  173. return FALSE;
  174. }
  175. FileRejectPDU::FileRejectPDU(MBFTFILEHANDLE iFileHandle) : GenericPDU()
  176. {
  177. m_FileHandle = iFileHandle;
  178. }
  179. BOOL FileRejectPDU::Encode(void)
  180. {
  181. m_lEncodedDataLength = sizeof(T127_FILE_ERROR_HEADER);
  182. DBG_SAVE_FILE_LINE
  183. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  184. if (NULL != m_lpEncodedBuffer)
  185. {
  186. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)m_lpEncodedBuffer;
  187. pBuff->PDUHeader.pduType = T127_FILE_REJECT;
  188. pBuff->PDUHeader.fileHandle = SWAPWORD(m_FileHandle);
  189. pBuff->errorCode = (ASNfile_not_required << 4);
  190. return(TRUE);
  191. }
  192. return FALSE;
  193. }
  194. FileAbortPDU::FileAbortPDU(ChannelID wDataChannelID,
  195. ChannelID wTransmitterID,
  196. MBFTFILEHANDLE iFileHandle) : GenericPDU()
  197. {
  198. m_DataChannelID = wDataChannelID;
  199. m_TransmitterID = wTransmitterID;
  200. m_FileHandle = iFileHandle;
  201. }
  202. BOOL FileAbortPDU::Encode(void)
  203. {
  204. m_lEncodedDataLength = sizeof(T127_FILE_ABORT_PDU);
  205. DBG_SAVE_FILE_LINE
  206. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  207. if (NULL != m_lpEncodedBuffer)
  208. {
  209. T127_FILE_ABORT_PDU* pBuff = (T127_FILE_ABORT_PDU*)m_lpEncodedBuffer;
  210. pBuff->pduType_PresentFields = T127_FILE_ABORT |
  211. (WORD)((ASNdata_channel_id_present |
  212. ASNtransmitter_user_id_present |
  213. ASNFile_AbortPDU_file_handle_present |
  214. ASNreason_unspecified) << 10) ;
  215. pBuff->dataChannel = SWAPWORD(m_DataChannelID - 1);
  216. pBuff->transmitterUserId = SWAPWORD(m_TransmitterID - MIN_ASNDynamicChannelID);
  217. pBuff->fileHandle = SWAPWORD(m_FileHandle);
  218. return(TRUE);
  219. }
  220. return FALSE;
  221. }
  222. FileStartPDU::FileStartPDU(
  223. LPCSTR lpszEncodedDataBuffer,
  224. LPCSTR lpszFileName, MBFTFILEHANDLE iFileHandle,
  225. LONG FileSize,time_t FileDateTime,
  226. LPCSTR lpszDataBuffer,int iDataLength,
  227. BOOL bIsEOF,
  228. unsigned CompressionFlags,
  229. LPCSTR lpszCompressionFormat,
  230. int v42bisP1,
  231. int v42bisP2,
  232. IT120AppletSession *pAppletSession)
  233. :
  234. GenericPDU()
  235. {
  236. m_pAppletSession = pAppletSession;
  237. if(lpszFileName)
  238. {
  239. lstrcpyn(m_szFileName,lpszFileName,sizeof(m_szFileName));
  240. }
  241. else
  242. {
  243. lstrcpy(m_szFileName,"");
  244. }
  245. m_FileHandle = iFileHandle;
  246. m_FileSize = FileSize;
  247. m_FileDateTime = FileDateTime;
  248. m_lpszDataBuffer= lpszDataBuffer;
  249. m_bIsEOF = bIsEOF;
  250. m_DataLength = iDataLength;
  251. m_lpEncodedBuffer = (LPSTR)lpszEncodedDataBuffer;
  252. m_CompressionFlags = CompressionFlags;
  253. if(lpszCompressionFormat)
  254. {
  255. lstrcpyn(m_szCompressionFormat,lpszCompressionFormat,sizeof(m_szCompressionFormat));
  256. }
  257. else
  258. {
  259. lstrcpy(m_szCompressionFormat,"");
  260. }
  261. m_v42bisP1 = v42bisP1;
  262. m_v42bisP2 = v42bisP2;
  263. }
  264. BOOL FileStartPDU::Encode(void)
  265. {
  266. ASNMBFTPDU GenericPDUStruct;
  267. ASNFilename_Attribute_ FileName;
  268. BOOL bReturn = FALSE;
  269. ClearStruct(&GenericPDUStruct);
  270. ClearStruct(&FileName);
  271. GenericPDUStruct.choice = ASNfile_StartPDU_chosen;
  272. FileName.value = m_szFileName;
  273. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNfilesize = m_FileSize;
  274. //struct tm * lpGMDateTime = localtime(&m_FileDateTime);
  275. unsigned Date = HIWORD(m_FileDateTime);
  276. unsigned Time = LOWORD(m_FileDateTime);
  277. _DOS_Date * lpDate = (_DOS_Date *)&Date;
  278. _DOS_Time * lpTime = (_DOS_Time *)&Time;
  279. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.year = lpDate->Year + 80;
  280. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.month = lpDate->Month;
  281. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.day = lpDate->Day;
  282. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.hour = lpTime->Hour;
  283. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.minute = lpTime->Minute;
  284. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.second = lpTime->Second * 2;
  285. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNdate_and_time_of_creation.utc = TRUE;
  286. GenericPDUStruct.u.ASNfile_StartPDU.file_header.bit_mask |= ASNfilename_present;
  287. GenericPDUStruct.u.ASNfile_StartPDU.file_header.bit_mask |= ASNdate_and_time_of_creation_present;
  288. GenericPDUStruct.u.ASNfile_StartPDU.file_header.bit_mask |= ASNfilesize_present;
  289. GenericPDUStruct.u.ASNfile_StartPDU.file_header.ASNfilename = &FileName;
  290. GenericPDUStruct.u.ASNfile_StartPDU.file_handle = (ASNHandle)m_FileHandle;
  291. GenericPDUStruct.u.ASNfile_StartPDU.eof_flag = (ossBoolean)m_bIsEOF;
  292. GenericPDUStruct.u.ASNfile_StartPDU.data.length = (unsigned)m_DataLength;
  293. GenericPDUStruct.u.ASNfile_StartPDU.data.value = (unsigned char FAR *)m_lpszDataBuffer;
  294. if(m_CompressionFlags & _MBFT_FILE_COMPRESSED)
  295. {
  296. if(m_CompressionFlags & _MBFT_STANDARD_COMPRESSSION)
  297. {
  298. GenericPDUStruct.u.ASNfile_StartPDU.bit_mask |= ASNFile_StartPDU_compression_specifier_present;
  299. GenericPDUStruct.u.ASNfile_StartPDU.ASNFile_StartPDU_compression_specifier.choice = ASNv42bis_parameters_chosen;
  300. GenericPDUStruct.u.ASNfile_StartPDU.ASNFile_StartPDU_compression_specifier.u.ASNv42bis_parameters.p1 = (unsigned short)m_v42bisP1;
  301. GenericPDUStruct.u.ASNfile_StartPDU.ASNFile_StartPDU_compression_specifier.u.ASNv42bis_parameters.p2 = (unsigned short)m_v42bisP2;
  302. }
  303. }
  304. //Specifying a non standard compression format is simply too complex!!!
  305. LPSTR pBuff = (LPSTR)GetDataBuffer();
  306. m_lpEncodedBuffer = pBuff;
  307. m_lEncodedDataLength = CreateFileHeader(pBuff, T127_FILE_START << 8, &GenericPDUStruct);
  308. pBuff += m_lEncodedDataLength;
  309. m_lEncodedDataLength += m_DataLength + sizeof(T127_FILE_START_DATA_BLOCK_HEADER);
  310. ((T127_FILE_START_DATA_BLOCK_HEADER*)pBuff)->EOFFlag = m_bIsEOF << 7;
  311. ((T127_FILE_START_DATA_BLOCK_HEADER*)pBuff)->CompressionFormat = 1;
  312. ((T127_FILE_START_DATA_BLOCK_HEADER*)pBuff)->FileDataSize = SWAPWORD((unsigned)m_DataLength); // File size in bytes
  313. bReturn = TRUE;
  314. return(bReturn);
  315. }
  316. FileDataPDU::FileDataPDU(
  317. LPCSTR lpszEncodedDataBuffer,
  318. MBFTFILEHANDLE iFileHandle,LPCSTR lpszDataBuffer,
  319. int iDataLength,
  320. BOOL bIsEOF,BOOL bAbort,
  321. IT120AppletSession *pAppletSession)
  322. :
  323. GenericPDU(pAppletSession, (LPSTR)lpszEncodedDataBuffer),
  324. m_FileHandle (iFileHandle),
  325. m_lpszDataBuffer (lpszDataBuffer),
  326. m_bIsEOF (bIsEOF),
  327. m_DataLength (iDataLength),
  328. m_bAbort (bAbort)
  329. {
  330. }
  331. BOOL FileDataPDU::Encode(void)
  332. {
  333. m_lpEncodedBuffer = (LPSTR)GetDataBuffer();
  334. if(m_lpEncodedBuffer)
  335. { T127_FILE_DATA_HEADER* pBuff = (T127_FILE_DATA_HEADER*)m_lpEncodedBuffer;
  336. pBuff->PDUHeader.pduType = T127_FILE_DATA;
  337. pBuff->PDUHeader.fileHandle = SWAPWORD(m_FileHandle);
  338. pBuff->DataHeader.EOFFlag = (m_bIsEOF << 7) | (m_bAbort << 6);
  339. pBuff->DataHeader.FileDataSize = SWAPWORD((unsigned)m_DataLength);
  340. }
  341. m_lEncodedDataLength = m_DataLength + sizeof(T127_FILE_DATA_HEADER);
  342. return (TRUE);
  343. }
  344. PrivateChannelInvitePDU::PrivateChannelInvitePDU(ChannelID wControlChannelID,
  345. ChannelID wDataChannelID,
  346. BOOL bIsBroadcast) : GenericPDU()
  347. {
  348. m_ControlChannelID = wControlChannelID;
  349. m_DataChannelID = wDataChannelID;
  350. m_bIsBroadcast = bIsBroadcast;
  351. }
  352. BOOL PrivateChannelInvitePDU::Encode(void)
  353. {
  354. BOOL bReturn = FALSE;
  355. if(m_ControlChannelID >= MIN_ASNDynamicChannelID &&
  356. m_ControlChannelID <= MAX_ASNDynamicChannelID &&
  357. m_DataChannelID >= MIN_ASNDynamicChannelID &&
  358. m_DataChannelID <= MAX_ASNDynamicChannelID)
  359. {
  360. m_lEncodedDataLength = sizeof(T127_PRIVATE_CHANNEL_INVITE);
  361. DBG_SAVE_FILE_LINE
  362. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  363. if (NULL != m_lpEncodedBuffer)
  364. {
  365. T127_PRIVATE_CHANNEL_INVITE * pBuff = (T127_PRIVATE_CHANNEL_INVITE *)&m_lpEncodedBuffer[0];
  366. pBuff->pduType = T127_PRIVATE_CHANNEL_JOIN_INVITE;
  367. pBuff->ControlChannel = SWAPWORD(m_ControlChannelID - MIN_ASNDynamicChannelID);
  368. pBuff->DataChannel = SWAPWORD(m_DataChannelID - MIN_ASNDynamicChannelID);
  369. pBuff->EncodingMode = 0; // Encoding for acknowledge mode (FALSE) = 0
  370. // Encoding for broadcast mode (TRUE) = 0x80 10000000b
  371. bReturn = TRUE;
  372. }
  373. }
  374. return(bReturn);
  375. }
  376. PrivateChannelResponsePDU::PrivateChannelResponsePDU(ChannelID wControlChannelID,
  377. BOOL bJoinedChannel) : GenericPDU()
  378. {
  379. m_ControlChannelID = wControlChannelID;
  380. m_bJoinedChannel = bJoinedChannel;
  381. }
  382. BOOL PrivateChannelResponsePDU::Encode(void)
  383. {
  384. m_lEncodedDataLength = sizeof(T127_FILE_ERROR_HEADER);
  385. DBG_SAVE_FILE_LINE
  386. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  387. if (NULL != m_lpEncodedBuffer)
  388. {
  389. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)m_lpEncodedBuffer;
  390. pBuff->PDUHeader.pduType = T127_FILE_REJECT;
  391. pBuff->PDUHeader.fileHandle = SWAPWORD(m_ControlChannelID - MIN_ASNDynamicChannelID);
  392. pBuff->errorCode = m_bJoinedChannel ?
  393. static_cast<BYTE>(ASNPrivate_Channel_Join_ResponsePDU_result_successful << 5) :
  394. static_cast<BYTE>(ASNinvitation_rejected << 5);
  395. return(TRUE);
  396. }
  397. return FALSE;
  398. }
  399. NonStandardPDU::NonStandardPDU(LPCSTR lpszEncodedDataBuffer,
  400. LPCSTR lpszKey,LPVOID lpBuffer,
  401. unsigned BufferLength,
  402. IT120AppletSession *pAppletSession)
  403. :
  404. GenericPDU()
  405. {
  406. m_pAppletSession = pAppletSession;
  407. m_lpEncodedBuffer = (LPSTR)lpszEncodedDataBuffer;
  408. m_szKey = lpszKey;
  409. m_lpBuffer = lpBuffer;
  410. m_BufferLength = BufferLength;
  411. }
  412. BOOL NonStandardPDU::Encode(void)
  413. {
  414. BOOL bReturn = FALSE;
  415. BYTE nonStandardPDUlenght = lstrlen(m_szKey) + 1;
  416. m_lEncodedDataLength = nonStandardPDUlenght + m_BufferLength + 4;
  417. DBG_SAVE_FILE_LINE
  418. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  419. if (NULL != m_lpEncodedBuffer)
  420. {
  421. LPSTR pBuff = m_lpEncodedBuffer;
  422. if(m_lpEncodedBuffer)
  423. {
  424. *pBuff++ = T127_MBFT_NONSTANDARD | ASNh221NonStandard_chosen;
  425. *pBuff++ = (BYTE)((nonStandardPDUlenght - 4) << 1);
  426. memcpy(pBuff,m_szKey,nonStandardPDUlenght);
  427. pBuff += nonStandardPDUlenght;
  428. if(m_BufferLength > 0x7F)
  429. {
  430. *pBuff++ = LOBYTE(m_BufferLength) & 0x80; // List of fields
  431. }
  432. *pBuff++ = (m_BufferLength &0x7F);
  433. memcpy(pBuff,m_lpBuffer,m_BufferLength);
  434. bReturn = TRUE;
  435. }
  436. }
  437. return(bReturn);
  438. }
  439. FileErrorPDU::FileErrorPDU(unsigned iFileHandle,int ErrorType,int ErrorCode)
  440. {
  441. m_FileHandle = iFileHandle;
  442. m_ErrorType = ErrorType;
  443. m_ErrorCode = ErrorCode;
  444. }
  445. BOOL FileErrorPDU::Encode(void)
  446. {
  447. BYTE sizeOfErrorID = GetLengthFieldSize(m_ErrorCode);
  448. m_lEncodedDataLength = sizeof(T127_FILE_ERROR_HEADER) + sizeOfErrorID;
  449. DBG_SAVE_FILE_LINE
  450. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  451. if (NULL != m_lpEncodedBuffer)
  452. {
  453. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)m_lpEncodedBuffer;
  454. pBuff->PDUHeader.pduType = T127_FILE_ERROR |(ASNFile_ErrorPDU_file_handle_present >> 6);
  455. pBuff->PDUHeader.fileHandle = SWAPWORD(m_FileHandle);
  456. pBuff->errorCode = ((m_ErrorType == MBFT_INFORMATIVE_ERROR) ?
  457. ASNinformative :
  458. (m_ErrorType == MBFT_PERMANENT_ERROR) ?
  459. ASNpermanent_error : ASNtransient_error) << 5;
  460. return(TRUE);
  461. }
  462. return FALSE;
  463. }
  464. MBFTPDUType GenericPDU::DecodePDU
  465. (
  466. LPSTR lpEncodedBuffer,
  467. LONG lBufferSize,
  468. class GenericPDU **lplpGenericPDU,
  469. LPCSTR *lpDecodedPDU,
  470. UserID MBFTUserID,
  471. IT120AppletSession *pAppletSession
  472. )
  473. {
  474. MBFTPDUType ReturnPDUType = EnumUnknownPDU;
  475. int PDUNumber = ASNMBFTPDU_PDU;
  476. LPSTR lpDecodedBuffer = NULL;
  477. *lplpGenericPDU = NULL;
  478. // Filter the pdu, they are allways in 8 increments 0x0,0x8,0x10....
  479. if(lpEncodedBuffer)
  480. {
  481. switch((BYTE)*lpEncodedBuffer & 0xF8)
  482. {
  483. case T127_FILE_DATA:
  484. {
  485. TRACE("DecodePDU: T127_FILE_DATA");
  486. T127_FILE_DATA_HEADER* pBuff = (T127_FILE_DATA_HEADER*)lpEncodedBuffer;
  487. DBG_SAVE_FILE_LINE
  488. *lplpGenericPDU = new FileDataPDU( lpEncodedBuffer,
  489. SWAPWORD(pBuff->PDUHeader.fileHandle),
  490. (LPCSTR)lpEncodedBuffer + sizeof(T127_FILE_DATA_HEADER),
  491. SWAPWORD(pBuff->DataHeader.FileDataSize),
  492. pBuff->DataHeader.EOFFlag & 0x80 ? TRUE : FALSE,
  493. pBuff->DataHeader.EOFFlag & 0x40 ? TRUE : FALSE,
  494. pAppletSession);
  495. ReturnPDUType = EnumFileDataPDU;
  496. }
  497. break;
  498. case T127_FILE_ACCEPT:
  499. {
  500. TRACE("DecodePDU: T127_FILE_ACCEPT");
  501. T127_FILE_PDU_HEADER* pBuff = (T127_FILE_PDU_HEADER*)lpEncodedBuffer;
  502. DBG_SAVE_FILE_LINE
  503. *lplpGenericPDU = new FileAcceptPDU(SWAPWORD(pBuff->fileHandle));
  504. ReturnPDUType = EnumFileAcceptPDU;
  505. }
  506. break;
  507. case T127_FILE_REJECT:
  508. {
  509. TRACE("DecodePDU: T127_FILE_REJECT");
  510. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)lpEncodedBuffer;
  511. DBG_SAVE_FILE_LINE
  512. *lplpGenericPDU = new FileRejectPDU(SWAPWORD(pBuff->PDUHeader.fileHandle));
  513. ReturnPDUType = EnumFileRejectPDU;
  514. }
  515. break;
  516. case T127_FILE_DENY:
  517. {
  518. TRACE("DecodePDU: T127_FILE_DENY");
  519. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)lpEncodedBuffer;
  520. DBG_SAVE_FILE_LINE
  521. *lplpGenericPDU = new FileDenyPDU(SWAPWORD(pBuff->PDUHeader.fileHandle), pBuff->errorCode >> 4);
  522. ReturnPDUType = EnumFileDenyPDU;
  523. }
  524. break;
  525. case T127_FILE_ERROR:
  526. {
  527. TRACE("DecodePDU: T127_FILE_ERROR");
  528. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)lpEncodedBuffer;
  529. int ErrorType = (pBuff->errorCode >> 5 == ASNpermanent_error) ?
  530. MBFT_PERMANENT_ERROR :
  531. (pBuff->errorCode >> 5 == ASNtransient_error) ?
  532. MBFT_TRANSIENT_ERROR : MBFT_INFORMATIVE_ERROR;
  533. DBG_SAVE_FILE_LINE
  534. *lplpGenericPDU = new FileErrorPDU(SWAPWORD(pBuff->PDUHeader.fileHandle), ErrorType, NULL);
  535. ReturnPDUType = EnumFileErrorPDU;
  536. }
  537. break;
  538. case T127_FILE_ABORT:
  539. {
  540. TRACE("DecodePDU: T127_FILE_ABORT");
  541. T127_FILE_ABORT_PDU* pBuff = (T127_FILE_ABORT_PDU*)lpEncodedBuffer;
  542. DBG_SAVE_FILE_LINE
  543. *lplpGenericPDU = new FileAbortPDU(SWAPWORD(pBuff->dataChannel) + 1,
  544. SWAPWORD(pBuff->transmitterUserId)+ MIN_ASNDynamicChannelID,
  545. SWAPWORD(pBuff->fileHandle));
  546. ReturnPDUType = EnumFileAbortPDU;
  547. }
  548. break;
  549. case T127_MBFT_NONSTANDARD:
  550. {
  551. TRACE("DecodePDU: T127_MBFT_NONSTANDARD");
  552. LPSTR pBuff = lpEncodedBuffer + 1;
  553. unsigned int KeyLength = (((BYTE)*pBuff++) >> 1) + 4;
  554. LPCSTR lpszKey = pBuff;
  555. pBuff += KeyLength;
  556. unsigned int Length = 0;
  557. if((BYTE)*pBuff & 0x80)
  558. {
  559. Length = (*pBuff++ & 0x7F) << 8; // List of fields
  560. }
  561. Length += *pBuff++;
  562. DBG_SAVE_FILE_LINE
  563. *lplpGenericPDU = new NonStandardPDU(lpEncodedBuffer,lpszKey,pBuff,Length, pAppletSession);
  564. ReturnPDUType = EnumNonStandardPDU;
  565. }
  566. break;
  567. case T127_FILE_OFFER:
  568. {
  569. TRACE("DecodePDU: T127_FILE_OFFER");
  570. BYTE lpszFileName[2*MAX_PATH];
  571. LONG FileSize = 0;
  572. unsigned long FileDateTime = (unsigned long)-1;
  573. T127_FILE_OFFER_PDU * pFileOfferPDU = (T127_FILE_OFFER_PDU * )GetFileInfo(lpEncodedBuffer, &lpszFileName[0], &FileSize, &FileDateTime);
  574. DBG_SAVE_FILE_LINE
  575. *lplpGenericPDU = new FileOfferPDU( (LPCSTR)lpszFileName,
  576. SWAPWORD(pFileOfferPDU->FileHandle),
  577. FileSize,
  578. FileDateTime,
  579. SWAPWORD(pFileOfferPDU->ChannelID) + 1,
  580. pFileOfferPDU->AckFlag ? TRUE : FALSE,
  581. SWAPWORD(pFileOfferPDU->RosterInstance),
  582. 0, // CompressionFlags,
  583. NULL,// lpszCompressionFormat,
  584. 0, // v42bisP1,
  585. 0); // v42bisP2
  586. ReturnPDUType = EnumFileOfferPDU;
  587. }
  588. break;
  589. case T127_FILE_START:
  590. {
  591. TRACE("DecodePDU: T127_FILE_START");
  592. BYTE lpszFileName[2*MAX_PATH];
  593. LONG FileSize = 0;
  594. unsigned long FileDateTime = (unsigned long)-1;
  595. BYTE * pBuff = GetFileInfo(lpEncodedBuffer, &lpszFileName[0], &FileSize, &FileDateTime);
  596. T127_FILE_START_PDU * pFileStartPDU = (T127_FILE_START_PDU * ) pBuff;
  597. T127_FILE_START_DATA_BLOCK_HEADER *pFileDataHeader = (T127_FILE_START_DATA_BLOCK_HEADER*)(pBuff + sizeof(T127_FILE_START_PDU));
  598. DBG_SAVE_FILE_LINE
  599. *lplpGenericPDU = new FileStartPDU(lpEncodedBuffer,
  600. (LPCSTR)lpszFileName,
  601. SWAPWORD(pFileStartPDU->FileHandle),
  602. FileSize,
  603. FileDateTime,
  604. (LPCSTR)pBuff + sizeof(T127_FILE_START_PDU)+sizeof(T127_FILE_START_DATA_BLOCK_HEADER),
  605. SWAPWORD(pFileDataHeader->FileDataSize),
  606. pFileDataHeader->EOFFlag ? TRUE : FALSE,
  607. 0, // CompressionFlags,
  608. NULL,// lpszCompressionFormat,
  609. 0, // v42bisP1,
  610. 0,
  611. pAppletSession); // v42bisP2
  612. ReturnPDUType = EnumFileStartPDU;
  613. }
  614. break;
  615. case T127_FILE_REQUEST:
  616. {
  617. TRACE("DecodePDU: T127_FILE_REQUEST");
  618. BYTE lpszFileName[2*MAX_PATH];
  619. LONG FileSize = 0;
  620. unsigned long FileDateTime = (unsigned long)-1;
  621. BYTE * pBuff = GetFileInfo(lpEncodedBuffer, &lpszFileName[0], &FileSize, &FileDateTime);
  622. T127_FILE_OFFER_PDU * pFileRequestPDU = (T127_FILE_OFFER_PDU * ) pBuff;
  623. DBG_SAVE_FILE_LINE
  624. *lplpGenericPDU = new FileRequestPDU(NULL,
  625. SWAPWORD(pFileRequestPDU->ChannelID) + 1,
  626. SWAPWORD(pFileRequestPDU->FileHandle));
  627. ReturnPDUType = EnumFileRequestPDU;
  628. }
  629. break;
  630. case T127_DIRECTORY_REQUEST:
  631. {
  632. TRACE("DecodePDU: T127_FILE_REQUEST");
  633. LPCSTR lpszPathName = NULL;
  634. DBG_SAVE_FILE_LINE
  635. *lplpGenericPDU = new DirectoryRequestPDU(lpszPathName);
  636. ReturnPDUType = EnumDirectoryRequestPDU;
  637. }
  638. break;
  639. case T127_MBFT_PRIVILEGE_ASSIGN:
  640. {
  641. TRACE("DecodePDU: T127_MBFT_PRIVILEGE_ASSIGN");
  642. T127_PRIVILEGE_REQUEST_PDU *pBuff = (T127_PRIVILEGE_REQUEST_PDU*)lpEncodedBuffer;
  643. unsigned PrivilegeWord = 0;
  644. int Index;
  645. for(Index = 0;Index < pBuff->nPrivileges; Index++)
  646. {
  647. if(!(Index & 0x01))
  648. {
  649. PrivilegeWord <<=4;
  650. PrivilegeWord |= ((pBuff->privileges[Index >> 1] & 0xF0) >> 4);
  651. }
  652. else
  653. {
  654. PrivilegeWord |= (pBuff->privileges[Index >> 1] & 0x0F);
  655. }
  656. }
  657. DBG_SAVE_FILE_LINE
  658. *lplpGenericPDU = new PrivilegeAssignPDU(PrivilegeWord);
  659. ReturnPDUType = EnumPrivilegeAssignPDU;
  660. }
  661. break;
  662. case T127_PRIVATE_CHANNEL_JOIN_INVITE:
  663. {
  664. TRACE("DecodePDU: T127_PRIVATE_CHANNEL_JOIN_INVITE");
  665. T127_PRIVATE_CHANNEL_INVITE * pBuff = (T127_PRIVATE_CHANNEL_INVITE *)lpEncodedBuffer;
  666. DBG_SAVE_FILE_LINE
  667. *lplpGenericPDU = new PrivateChannelInvitePDU( SWAPWORD(pBuff->ControlChannel) + MIN_ASNDynamicChannelID,
  668. SWAPWORD(pBuff->DataChannel) + MIN_ASNDynamicChannelID,
  669. pBuff->EncodingMode);
  670. ReturnPDUType = EnumPrivateChannelInvitePDU;
  671. }
  672. break;
  673. case T127_PRIVATE_CHANNEL_JOIN_RESPONSE:
  674. {
  675. TRACE("DecodePDU: T127_PRIVATE_CHANNEL_JOIN_RESPONSE");
  676. T127_PRIVATE_CHANNEL_RESPONSE* pBuff = (T127_PRIVATE_CHANNEL_RESPONSE*)lpEncodedBuffer;
  677. DBG_SAVE_FILE_LINE
  678. *lplpGenericPDU = new PrivateChannelResponsePDU(SWAPWORD(pBuff->ControlChannel) + MIN_ASNDynamicChannelID,
  679. pBuff->Response >> 5 == ASNPrivate_Channel_Join_ResponsePDU_result_successful);
  680. ReturnPDUType = EnumPrivateChannelResponsePDU;
  681. }
  682. break;
  683. case T127_DIRECTORY_RESPONSE:
  684. case T127_MBFT_PRIVILEGE_REQUEST:
  685. default:
  686. TRACE("WARNING DecodePDU: Unknown PDU");
  687. break;
  688. }
  689. }
  690. return(ReturnPDUType);
  691. }
  692. BOOL FileErrorPDU::ExtractErrorCode(LPCSTR lpszString,
  693. int iLength,
  694. int * lpAPIErrorCode)
  695. {
  696. BOOL bCodeExtracted = FALSE;
  697. if(iLength > sizeof(szProshareError))
  698. {
  699. if(!_fmemcmp(lpszString,szProshareError,sizeof(szProshareError) - 1))
  700. {
  701. bCodeExtracted = TRUE;
  702. *lpAPIErrorCode = (int) DecimalStringToUINT(&lpszString[sizeof(szProshareError) - 1]);
  703. }
  704. }
  705. return(bCodeExtracted);
  706. }
  707. BOOL FileErrorPDU::XlatErrorCode(int * lpAPIErrorCode,int * lpMBFTErrorCode,
  708. BOOL bXlatToAPI)
  709. {
  710. BOOL bMatchFound = FALSE;
  711. static struct
  712. {
  713. ASNErrorID iMBFTErrorCode;
  714. MBFT_ERROR_CODE iAPIErrorCode;
  715. } ErrorXlat[] = {
  716. /*{ASNno_reason, iMBFT_UNKNOWN_ERROR},*/
  717. {ASNresponder_error, iMBFT_UNKNOWN_ERROR},
  718. {ASNsystem_shutdown, iMBFT_UNKNOWN_ERROR},
  719. {ASNbft_management_problem, iMBFT_UNKNOWN_ERROR},
  720. {ASNbft_management_bad_account, iMBFT_UNKNOWN_ERROR},
  721. {ASNbft_management_security_not_passed, iMBFT_UNKNOWN_ERROR},
  722. {ASNdelay_may_be_encountered, iMBFT_UNKNOWN_ERROR},
  723. {ASNinitiator_error, iMBFT_UNKNOWN_ERROR},
  724. {ASNsubsequent_error, iMBFT_UNKNOWN_ERROR},
  725. {ASNtemporal_insufficiency_of_resources, iMBFT_UNKNOWN_ERROR},
  726. {ASNaccess_request_violates_VFS_security, iMBFT_UNKNOWN_ERROR},
  727. {ASNaccess_request_violates_local_security, iMBFT_UNKNOWN_ERROR},
  728. {ASNconflicting_parameter_values, iMBFT_UNKNOWN_ERROR},
  729. {ASNunsupported_parameter_values, iMBFT_UNKNOWN_ERROR},
  730. {ASNmandatory_parameter_not_set, iMBFT_UNKNOWN_ERROR},
  731. {ASNunsupported_parameter, iMBFT_UNKNOWN_ERROR},
  732. {ASNduplicated_parameter, iMBFT_UNKNOWN_ERROR},
  733. {ASNillegal_parameter_type, iMBFT_UNKNOWN_ERROR},
  734. {ASNunsupported_parameter_types, iMBFT_UNKNOWN_ERROR},
  735. {ASNbft_protocol_error, iMBFT_UNKNOWN_ERROR},
  736. {ASNbft_protocol_error_procedure_error, iMBFT_UNKNOWN_ERROR},
  737. /*{ASNbft_protocol_error_functional_unit_err, iMBFT_UNKNOWN_ERROR},*/
  738. {ASNbft_protocol_error_corruption_error, iMBFT_UNKNOWN_ERROR},
  739. {ASNlower_layer_failure, iMBFT_UNKNOWN_ERROR},
  740. {ASNtimeout, iMBFT_UNKNOWN_ERROR},
  741. {ASNbad_account, iMBFT_UNKNOWN_ERROR},
  742. {ASNinvalid_filestore_password, iMBFT_UNKNOWN_ERROR},
  743. {ASNfilename_not_found, iMBFT_UNKNOWN_ERROR},
  744. {ASNinitial_attributes_not_possible, iMBFT_UNKNOWN_ERROR},
  745. {ASNbad_attribute_name, iMBFT_UNKNOWN_ERROR},
  746. {ASNnon_existent_file, iMBFT_UNKNOWN_ERROR},
  747. {ASNfile_already_exists, iMBFT_UNKNOWN_ERROR},
  748. {ASNfile_cannot_be_created, iMBFT_FILE_ACCESS_DENIED},
  749. {ASNfile_busy, iMBFT_FILE_SHARING_VIOLATION},
  750. {ASNfile_not_available, iMBFT_FILE_SHARING_VIOLATION},
  751. {ASNfilename_truncated, iMBFT_UNKNOWN_ERROR},
  752. {ASNinitial_attributes_altered, iMBFT_UNKNOWN_ERROR},
  753. {ASNambiguous_file_specification, iMBFT_UNKNOWN_ERROR},
  754. {ASNattribute_non_existent, iMBFT_UNKNOWN_ERROR},
  755. {ASNattribute_not_supported, iMBFT_UNKNOWN_ERROR},
  756. {ASNbad_attribute_value, iMBFT_UNKNOWN_ERROR},
  757. {ASNattribute_partially_supported, iMBFT_UNKNOWN_ERROR},
  758. {ASNbad_data_element_type, iMBFT_UNKNOWN_ERROR},
  759. {ASNoperation_not_available, iMBFT_UNKNOWN_ERROR},
  760. {ASNoperation_not_supported, iMBFT_UNKNOWN_ERROR},
  761. {ASNoperation_inconsistent, iMBFT_UNKNOWN_ERROR},
  762. {ASNbad_write, iMBFT_FILE_IO_ERROR},
  763. {ASNbad_read, iMBFT_FILE_IO_ERROR},
  764. {ASNlocal_failure, iMBFT_UNKNOWN_ERROR},
  765. {ASNlocal_failure_filespace_exhausted, iMBFT_INSUFFICIENT_DISK_SPACE},
  766. {ASNlocal_failure_data_corrupted, iMBFT_UNKNOWN_ERROR},
  767. {ASNlocal_failure_device_failure, iMBFT_UNKNOWN_ERROR},
  768. {ASNfuture_filesize_increased, iMBFT_UNKNOWN_ERROR}};
  769. int Index;
  770. for(Index = 0;Index < (sizeof(ErrorXlat) / sizeof(ErrorXlat[0]));Index++)
  771. {
  772. if(bXlatToAPI)
  773. {
  774. if(ErrorXlat[Index].iMBFTErrorCode == *lpMBFTErrorCode)
  775. {
  776. *lpAPIErrorCode = ErrorXlat[Index].iAPIErrorCode;
  777. bMatchFound = TRUE;
  778. }
  779. }
  780. else
  781. {
  782. if(ErrorXlat[Index].iAPIErrorCode == *lpAPIErrorCode)
  783. {
  784. *lpMBFTErrorCode = ErrorXlat[Index].iMBFTErrorCode;
  785. bMatchFound = TRUE;
  786. }
  787. }
  788. if(bMatchFound)
  789. {
  790. break;
  791. }
  792. }
  793. if(!bMatchFound)
  794. {
  795. if(!bXlatToAPI)
  796. {
  797. *lpMBFTErrorCode = ASNno_reason;
  798. }
  799. }
  800. return(bMatchFound);
  801. }
  802. FileRequestPDU::FileRequestPDU(LPCSTR lpszFileName,ChannelID wDataChannelID,
  803. unsigned uRequestHandle)
  804. {
  805. if(lpszFileName)
  806. {
  807. lstrcpyn(m_szFileName,lpszFileName,sizeof(m_szFileName));
  808. }
  809. else
  810. {
  811. lstrcpy(m_szFileName,"");
  812. }
  813. m_DataChannelID = wDataChannelID;
  814. m_uRequestHandle = uRequestHandle;
  815. }
  816. BOOL FileRequestPDU::Encode(void)
  817. {
  818. TRACE("*** WARNING (OSSHELP): Attempt to call unimplemented FileRequestPDU::Encode***\n");
  819. return(FALSE);
  820. }
  821. FileDenyPDU::FileDenyPDU(unsigned uRequestHandle,unsigned uReason)
  822. {
  823. m_uRequestHandle = uRequestHandle;
  824. m_uReason = uReason;
  825. }
  826. BOOL FileDenyPDU::Encode(void)
  827. {
  828. m_lEncodedDataLength = sizeof(T127_FILE_ERROR_HEADER);
  829. DBG_SAVE_FILE_LINE
  830. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  831. if (NULL != m_lpEncodedBuffer)
  832. {
  833. T127_FILE_ERROR_HEADER* pBuff = (T127_FILE_ERROR_HEADER*)m_lpEncodedBuffer;
  834. pBuff->PDUHeader.pduType = T127_FILE_REJECT;
  835. pBuff->PDUHeader.fileHandle = SWAPWORD(m_uRequestHandle);
  836. pBuff->errorCode = m_uReason ?
  837. static_cast<BYTE>((ASN_enum2)m_uReason << 4) :
  838. static_cast<BYTE>(ASNFile_DenyPDU_reason_unspecified << 4);
  839. return(TRUE);
  840. }
  841. return FALSE;
  842. }
  843. DirectoryRequestPDU::DirectoryRequestPDU(LPCSTR lpszPathName)
  844. {
  845. if(lpszPathName)
  846. {
  847. lstrcpyn(m_szPathName,lpszPathName,sizeof(m_szPathName));
  848. }
  849. else
  850. {
  851. lstrcpy(m_szPathName,"");
  852. }
  853. }
  854. BOOL DirectoryRequestPDU::Encode(void)
  855. {
  856. TRACE("*** WARNING (OSSHELP): Attempt to call unimplemented DirectoryRequestPDU::Encode***\n");
  857. return(FALSE);
  858. }
  859. DirectoryResponsePDU::DirectoryResponsePDU(unsigned uResult)
  860. {
  861. m_uResult = uResult;
  862. }
  863. BOOL DirectoryResponsePDU::Encode(void)
  864. {
  865. m_lEncodedDataLength = sizeof(BYTE)*2;
  866. DBG_SAVE_FILE_LINE
  867. m_lpEncodedBuffer = new char[m_lEncodedDataLength];
  868. if (NULL != m_lpEncodedBuffer)
  869. {
  870. m_lpEncodedBuffer[0] = T127_DIRECTORY_RESPONSE;
  871. m_lpEncodedBuffer[1] = m_uResult << 6;
  872. return(TRUE);
  873. }
  874. return FALSE;
  875. }
  876. PrivilegeRequestPDU::PrivilegeRequestPDU(unsigned wPrivilege)
  877. {
  878. m_PrivilegeWord = wPrivilege;
  879. }
  880. BOOL PrivilegeRequestPDU::Encode(void)
  881. {
  882. struct
  883. {
  884. MBFTPrivilege iMBFTPrivilege;
  885. ASNMBFTPrivilege iASNPrivilege;
  886. } static PrivilegeArray[] = {{EnumFileTransfer,ASNfile_transmit_privilege},
  887. {EnumFileRequest,ASNfile_request_privilege},
  888. {EnumPrivateChannel,ASNcreate_private_privilege},
  889. {EnumPriority,ASNmedium_priority_privilege},
  890. {EnumAbort,ASNabort_privilege},
  891. {EnumNonStandard,ASNnonstandard_privilege}};
  892. int Index;
  893. BYTE nPrivileges = 0;
  894. T127_PRIVILEGE_REQUEST_PDU * pBuff;
  895. BYTE privilege;
  896. DBG_SAVE_FILE_LINE
  897. m_lpEncodedBuffer = new char[sizeof(T127_PRIVILEGE_REQUEST_PDU)];
  898. if (NULL != m_lpEncodedBuffer)
  899. {
  900. pBuff = (T127_PRIVILEGE_REQUEST_PDU*)m_lpEncodedBuffer;
  901. for(Index = 0;Index < sizeof(PrivilegeArray) / sizeof(PrivilegeArray[0]);
  902. Index++)
  903. {
  904. if(m_PrivilegeWord & PrivilegeArray[Index].iMBFTPrivilege)
  905. {
  906. privilege = PrivilegeArray[Index].iASNPrivilege;
  907. if(!(nPrivileges & 0x01))
  908. {
  909. pBuff->privileges[nPrivileges >> 1] = 0;
  910. privilege <<=4;
  911. }
  912. pBuff->privileges[(nPrivileges >> 1)] |= privilege;
  913. nPrivileges++;
  914. }
  915. }
  916. pBuff->pduType = T127_MBFT_PRIVILEGE_REQUEST;
  917. pBuff->nPrivileges = nPrivileges;
  918. m_lEncodedDataLength = (LONG)(2 * sizeof(BYTE) +
  919. ((nPrivileges >> 1) * sizeof(BYTE)) +
  920. ((nPrivileges & 0x1) ? 1 : 0));
  921. return(TRUE);
  922. }
  923. return FALSE;
  924. }
  925. PrivilegeAssignPDU::PrivilegeAssignPDU(unsigned wPrivilege,UserID MBFTUserID)
  926. {
  927. m_PrivilegeWord = wPrivilege;
  928. m_MBFTUserID = MBFTUserID;
  929. }
  930. BOOL PrivilegeAssignPDU::Encode(void)
  931. {
  932. TRACE("*** WARNING (OSSHELP): Attempt to call unimplemented PrivilegeRequestPDU::Encode***\n");
  933. return(FALSE);
  934. }
  935. BOOL PrivilegeAssignPDU::XlatPrivilegeCode(unsigned iPrivilegeCode,unsigned * lpMBFTCode)
  936. {
  937. BOOL bReturn = FALSE;
  938. struct
  939. {
  940. MBFTPrivilege iMBFTPrivilege;
  941. ASNMBFTPrivilege iASNPrivilege;
  942. } static PrivilegeArray[] = {{EnumFileTransfer,ASNfile_transmit_privilege},
  943. {EnumFileRequest,ASNfile_request_privilege},
  944. {EnumPrivateChannel,ASNcreate_private_privilege},
  945. {EnumPriority,ASNmedium_priority_privilege},
  946. {EnumAbort,ASNabort_privilege},
  947. {EnumNonStandard,ASNnonstandard_privilege}};
  948. int Index;
  949. for(Index = 0;Index < sizeof(PrivilegeArray) / sizeof(PrivilegeArray[0]);
  950. Index++)
  951. {
  952. if((unsigned)PrivilegeArray[Index].iASNPrivilege == iPrivilegeCode)
  953. {
  954. *lpMBFTCode = PrivilegeArray[Index].iMBFTPrivilege;
  955. bReturn = TRUE;
  956. break;
  957. }
  958. }
  959. return(bReturn);
  960. }
  961. unsigned PrivilegeAssignPDU::ConstructPrivilegeWord(LPVOID lpPrivilegeStruct,
  962. ChannelID MBFTUserID)
  963. {
  964. struct ASNMBFT_Privilege_AssignPDU::ASN_setof5 * lpNextSet = (struct ASNMBFT_Privilege_AssignPDU::ASN_setof5 *)lpPrivilegeStruct;
  965. struct ASNMBFT_Privilege_AssignPDU::ASN_setof5::temptag::ASN_setof4 * lpNextPrivilege;
  966. unsigned Temp,wPrivilegeWord;
  967. wPrivilegeWord = 0;
  968. while(lpNextSet)
  969. {
  970. if(lpNextSet->value.mbftID == MBFTUserID)
  971. {
  972. lpNextPrivilege = lpNextSet->value.mbft_privilege;
  973. while(lpNextPrivilege)
  974. {
  975. Temp = 0;
  976. XlatPrivilegeCode(lpNextPrivilege->value,&Temp);
  977. wPrivilegeWord |= Temp;
  978. lpNextPrivilege = lpNextPrivilege->next;
  979. }
  980. break;
  981. }
  982. lpNextSet = lpNextSet->next;
  983. }
  984. return(wPrivilegeWord);
  985. }
  986. FileEndAcknowledgePDU::FileEndAcknowledgePDU(int iFileHandle)
  987. {
  988. m_FileHandle = iFileHandle;
  989. }
  990. BOOL FileEndAcknowledgePDU::Encode(void)
  991. {
  992. TRACE("OSSHELP: Invalid attempt to encode FileEndAcknowledgePDU\n");
  993. return(FALSE);
  994. }
  995. ChannelLeavePDU::ChannelLeavePDU(ChannelID wControlChannelID,int iErrorCode)
  996. {
  997. m_ChannelID = wControlChannelID;
  998. m_ErrorCode = iErrorCode;
  999. }
  1000. BOOL ChannelLeavePDU::Encode(void)
  1001. {
  1002. TRACE("OSSHELP:Invalid attempt to encode ChannelLeavePDU\n");
  1003. return(FALSE);
  1004. }
  1005. BYTE GetLengthFieldSize (ULONG length)
  1006. {
  1007. BYTE size = 0;
  1008. BOOL bLastBitSet = FALSE;
  1009. do
  1010. {
  1011. bLastBitSet = ((BYTE)length & 0x80 ? TRUE : FALSE);
  1012. size++;
  1013. }while(length >>=8);
  1014. if(bLastBitSet)
  1015. {
  1016. size++;
  1017. }
  1018. return (size);
  1019. }
  1020. BYTE * GetFirstField (BYTE * pBuff, WORD * bufferLength)
  1021. {
  1022. BYTE * pFirstField = NULL;
  1023. WORD fieldSize;
  1024. BYTE * pBuffStart = pBuff;
  1025. BYTE numberOfItems = *pBuff++;
  1026. while(numberOfItems --)
  1027. {
  1028. fieldSize = *pBuff++;
  1029. if(fieldSize & 0x80)
  1030. {
  1031. fieldSize = ((fieldSize & 0x7F) << 8) + *pBuff++;
  1032. }
  1033. if(!pFirstField)
  1034. {
  1035. pFirstField = pBuff;
  1036. }
  1037. pBuff += fieldSize;
  1038. }
  1039. *bufferLength = (WORD)(pBuff - pBuffStart);
  1040. return ( pFirstField);
  1041. }
  1042. VOID SetLengthField(BYTE * pBuff, BYTE sizeOfLength, ULONG lengthOfField)
  1043. {
  1044. *pBuff = sizeOfLength;
  1045. pBuff += sizeOfLength;
  1046. while(sizeOfLength--)
  1047. {
  1048. *pBuff-- = LOBYTE(lengthOfField);
  1049. lengthOfField >>=8;
  1050. }
  1051. }
  1052. VOID GetFileHeaderSize (FILE_HEADER_INFO* fileHeader)
  1053. {
  1054. // File Size
  1055. fileHeader->nBytesForFileSize = GetLengthFieldSize(fileHeader->fileSize);
  1056. // File Name
  1057. fileHeader->fileNameSize = lstrlen(fileHeader->fileName);
  1058. // Pdu Size
  1059. fileHeader->pduSize = 1 + // PDU type
  1060. 4 + // File Header bitmask
  1061. ((fileHeader->fileNameSize) > 0x7F ? 2 : 1) + // Number of bytes needed to express the size of the file name
  1062. 1 + // File name size, if the file name is size is > 0x80, use the first four bits of the previous byte
  1063. fileHeader->fileNameSize +
  1064. 1 + // Size of data time info
  1065. 15 + // yyyymmddhhmmss[utc]
  1066. 1 + // number of bytes to hold filesize
  1067. fileHeader->nBytesForFileSize + // file size
  1068. (fileHeader->pduType == T127_FILE_START ? sizeof(T127_FILE_START_PDU) : sizeof(T127_FILE_OFFER_PDU) );
  1069. }
  1070. #define DEFAULT_LOCALE_LANGAUGE (MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US))
  1071. BOOL IsEnglishLocale(void)
  1072. {
  1073. TCHAR szTemp[16];
  1074. TCHAR szLang[16];
  1075. ::LoadString(g_hDllInst, IDS_LANGNAME, szLang, 16);
  1076. if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
  1077. LOCALE_ILANGUAGE, szTemp, 16))
  1078. {
  1079. // Compare with Englist language
  1080. return (!_StrCmpN(szLang, szTemp, 4));
  1081. }
  1082. return FALSE;
  1083. }
  1084. BOOL HasDBCSCharacter(LPSTR pszStr)
  1085. {
  1086. while (*pszStr)
  1087. {
  1088. if (IsDBCSLeadByte((BYTE)*pszStr))
  1089. return TRUE;
  1090. pszStr = ::CharNext(pszStr);
  1091. }
  1092. return FALSE;
  1093. }
  1094. BYTE* GetFileInfo (LPSTR lpEncodedBuffer, BYTE * lpszFileName, LONG * FileSize, ULONG* FileDateTime )
  1095. {
  1096. WORD fieldSize;
  1097. BYTE * pFields;
  1098. DWORD presentFields;
  1099. T127_FILE_OFFER_PRESENT_FIELDS * ppresentFields;
  1100. pFields = (BYTE*)(lpEncodedBuffer + 1);
  1101. // Present fields
  1102. presentFields = *pFields++ << 24;
  1103. presentFields |= *pFields++ << 16;
  1104. presentFields |= *pFields++ << 8;
  1105. presentFields |= *pFields++;
  1106. if(*lpEncodedBuffer == T127_FILE_START)
  1107. {
  1108. presentFields >>=4;
  1109. }
  1110. ppresentFields = (T127_FILE_OFFER_PRESENT_FIELDS *)&presentFields;
  1111. // Skip version
  1112. if ((*ppresentFields).wASNprotocol_version_present)
  1113. {
  1114. pFields += 2;
  1115. }
  1116. // Get the File Name
  1117. if ((*ppresentFields).wASNfilename_present)
  1118. {
  1119. BYTE * pOldField = pFields;
  1120. BYTE * pFileName = GetFirstField(pFields, &fieldSize);
  1121. BYTE fileNameSize = fieldSize - (BYTE)(pFileName - pOldField);
  1122. memcpy (lpszFileName, pFileName, fileNameSize);
  1123. lpszFileName[fileNameSize] = 0;
  1124. pFields += fieldSize;
  1125. }
  1126. // Skip actions
  1127. if ((*ppresentFields).wASNpermitted_actions_present)
  1128. {
  1129. pFields += 2;
  1130. }
  1131. // Skip contents
  1132. if ((*ppresentFields).wASNcontents_type_present)
  1133. {
  1134. pFields += 4;
  1135. }
  1136. // Get time of Creation
  1137. if ((*ppresentFields).wASNdate_and_time_of_creation_present)
  1138. {
  1139. GeneralizedTime ASNDateTime;
  1140. BYTE dateTime [SIZE_OF_DATE_TIME_STRING + 1];
  1141. memcpy(dateTime,pFields, SIZE_OF_DATE_TIME_STRING + 1);
  1142. // Get UTC
  1143. fieldSize = *pFields;
  1144. if(fieldSize == SIZE_OF_DATE_TIME_STRING + 1)
  1145. {
  1146. ASNDateTime.utc = TRUE;
  1147. dateTime[fieldSize] = 0;
  1148. }
  1149. // Null terminate the date,time
  1150. ASNDateTime.second = (short)DecimalStringToUINT((LPCTSTR)&dateTime[13]);
  1151. dateTime[13] = 0;
  1152. ASNDateTime.minute = (short)DecimalStringToUINT((LPCTSTR)&dateTime[11]);
  1153. dateTime[11] = 0;
  1154. ASNDateTime.hour = (short)DecimalStringToUINT((LPCTSTR)&dateTime[9]);
  1155. dateTime[9] = 0;
  1156. ASNDateTime.day = (short)DecimalStringToUINT((LPCTSTR)&dateTime[7]);
  1157. dateTime[7] = 0;
  1158. ASNDateTime.month = (short)DecimalStringToUINT((LPCTSTR)&dateTime[5]);
  1159. dateTime[5] = 0;
  1160. ASNDateTime.year = (short)DecimalStringToUINT((LPCTSTR)&dateTime[1]);
  1161. *FileDateTime = DecodeTimeDate(ASNDateTime);
  1162. pFields += fieldSize + 1;
  1163. }
  1164. // Skip time of last modification
  1165. if ((*ppresentFields).wASNdate_and_time_of_last_modification_present)
  1166. {
  1167. fieldSize = *pFields++;
  1168. pFields += fieldSize;
  1169. }
  1170. // Skip time of last read access
  1171. if ((*ppresentFields).wASNdate_and_time_of_last_read_access_present)
  1172. {
  1173. fieldSize = *pFields++;
  1174. pFields += fieldSize;
  1175. }
  1176. // Get File Size
  1177. if((*ppresentFields).wASNfilesize_present)
  1178. {
  1179. fieldSize = *pFields++;
  1180. while(fieldSize--)
  1181. {
  1182. *FileSize <<= 8;
  1183. *FileSize += LOBYTE(*pFields++);
  1184. }
  1185. }
  1186. // Skip Future File Size
  1187. if((*ppresentFields).wASNfuture_filesize_present)
  1188. {
  1189. fieldSize = *pFields++;
  1190. pFields += fieldSize;
  1191. }
  1192. // Skip ASNaccess_control_present
  1193. if((*ppresentFields).wASNaccess_control_present)
  1194. {
  1195. GetFirstField(pFields, &fieldSize);
  1196. pFields += fieldSize;
  1197. }
  1198. // Skip private use itemns
  1199. if((*ppresentFields).wASNprivate_use_present)
  1200. {
  1201. if(*pFields & ASNdirect_reference_present)
  1202. { pFields++;
  1203. pFields += *pFields + 1;
  1204. }
  1205. if(*pFields & ASNindirect_reference_present)
  1206. { pFields++;
  1207. pFields += *pFields + 1;
  1208. }
  1209. }
  1210. // Skip ASNstructure_present
  1211. if((*ppresentFields).wASNstructure_present)
  1212. {
  1213. fieldSize = *pFields++;
  1214. pFields += fieldSize;
  1215. }
  1216. // Skip ASNapplication_reference_present
  1217. if((*ppresentFields).wASNapplication_reference_present)
  1218. {
  1219. GetFirstField(pFields, &fieldSize);
  1220. pFields += fieldSize;
  1221. }
  1222. // Skip ASNmachine_present
  1223. if((*ppresentFields).wASNmachine_present)
  1224. {
  1225. GetFirstField(pFields, &fieldSize);
  1226. pFields += fieldSize;
  1227. }
  1228. // Skip ASNoperating_system_present
  1229. if((*ppresentFields).wASNoperating_system_present)
  1230. {
  1231. fieldSize = *pFields++;
  1232. pFields += fieldSize;
  1233. }
  1234. // Skip ASNrecipient_present
  1235. if((*ppresentFields).wASNrecipient_present)
  1236. {
  1237. GetFirstField(pFields, &fieldSize);
  1238. pFields += fieldSize;
  1239. }
  1240. // Skip ASNcharacter_set_present
  1241. if((*ppresentFields).wASNcharacter_set_present)
  1242. {
  1243. fieldSize = *pFields++;
  1244. pFields += fieldSize;
  1245. }
  1246. // Skip ASNcompression_present
  1247. if((*ppresentFields).wASNcompression_present)
  1248. {
  1249. GetFirstField(pFields, &fieldSize);
  1250. pFields += fieldSize;
  1251. }
  1252. // Skip ASNenvironment_present
  1253. if((*ppresentFields).wASNenvironment_present)
  1254. {
  1255. GetFirstField(pFields, &fieldSize);
  1256. pFields += fieldSize;
  1257. }
  1258. // Skip pathname
  1259. if((*ppresentFields).wASNFileHeader_pathname_present)
  1260. {
  1261. GetFirstField(pFields, &fieldSize);
  1262. pFields += fieldSize;
  1263. }
  1264. // Skip ASNuser_visible_string_present
  1265. if((*ppresentFields).wASNuser_visible_string_present)
  1266. {
  1267. GetFirstField(pFields, &fieldSize);
  1268. pFields += fieldSize;
  1269. }
  1270. return pFields;
  1271. }
  1272. LONG CreateFileHeader(LPSTR pFileHeader, WORD pduType, ASNMBFTPDU* GenericPDUStruct)
  1273. {
  1274. FILE_HEADER_INFO fileHeaderInfo;
  1275. fileHeaderInfo.fileName = (((((*GenericPDUStruct).u).ASNfile_StartPDU).file_header).ASNfilename)->value;
  1276. fileHeaderInfo.fileSize = ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNfilesize;
  1277. fileHeaderInfo.pduType = HIBYTE(pduType);
  1278. GetFileHeaderSize(&fileHeaderInfo);
  1279. //
  1280. // If we don't have a pointer to return the header, just return the size
  1281. //
  1282. if(pFileHeader == NULL)
  1283. {
  1284. return(fileHeaderInfo.pduSize);
  1285. }
  1286. MBFT_ERROR_CODE iErrorCode = iMBFT_OK;
  1287. MBFT_ERROR_TYPES iErrorType = MBFT_TRANSIENT_ERROR;
  1288. LPSTR pFileOfferPDU = pFileHeader;
  1289. // PDU Type
  1290. *pFileOfferPDU++ = HIBYTE(pduType);
  1291. DWORD fieldsInHeader = filename_present|date_and_time_of_creation_present|filesize_present;
  1292. if(HIBYTE(pduType) == T127_FILE_START)
  1293. {
  1294. fieldsInHeader <<=4;
  1295. }
  1296. // Swap Dword
  1297. fieldsInHeader = ((fieldsInHeader & 0xFF000000) >> 24) +
  1298. ((fieldsInHeader & 0x00FF0000) >> 8) +
  1299. ((fieldsInHeader & 0x0000FF00) << 8) +
  1300. ((fieldsInHeader & 0x000000FF) << 24) |
  1301. LOBYTE(pduType);
  1302. // Present Fields in file header
  1303. ((T127_FILE_HEADER*)pFileOfferPDU)->presentFields = fieldsInHeader;
  1304. pFileOfferPDU +=sizeof(DWORD);
  1305. // File Name
  1306. *pFileOfferPDU++ = 0x01;
  1307. if(fileHeaderInfo.fileNameSize > 0x7F)
  1308. {
  1309. *pFileOfferPDU++ = 0x80 | HIBYTE(fileHeaderInfo.fileNameSize);
  1310. *pFileOfferPDU++ = LOBYTE(fileHeaderInfo.fileNameSize);
  1311. }
  1312. else
  1313. {
  1314. *pFileOfferPDU++ = (BYTE)fileHeaderInfo.fileNameSize;
  1315. }
  1316. lstrcpy((CHAR*)pFileOfferPDU, fileHeaderInfo.fileName);
  1317. pFileOfferPDU += fileHeaderInfo.fileNameSize;
  1318. // Date and time
  1319. *pFileOfferPDU++ = SIZE_OF_DATE_TIME_STRING + 1;
  1320. wsprintf((CHAR*)pFileOfferPDU, "%04d%02d%02d%02d%02d%02d",
  1321. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.year,
  1322. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.month,
  1323. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.day,
  1324. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.hour,
  1325. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.minute,
  1326. ((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_header).ASNdate_and_time_of_creation.second);
  1327. ASSERT(SIZE_OF_DATE_TIME_STRING == lstrlen(pFileOfferPDU));
  1328. pFileOfferPDU += SIZE_OF_DATE_TIME_STRING;
  1329. *pFileOfferPDU++ = 90; // Base year
  1330. // File size
  1331. SetLengthField((BYTE*)pFileOfferPDU, fileHeaderInfo.nBytesForFileSize, fileHeaderInfo.fileSize);
  1332. pFileOfferPDU += fileHeaderInfo.nBytesForFileSize + sizeof(BYTE);
  1333. if(HIBYTE(pduType) == T127_FILE_START)
  1334. {
  1335. ((T127_FILE_START_PDU*)pFileOfferPDU)->FileHandle = SWAPWORD((((*GenericPDUStruct).u).ASNfile_StartPDU).file_handle);
  1336. }
  1337. else
  1338. {
  1339. ((T127_FILE_OFFER_PDU*)pFileOfferPDU)->RosterInstance = SWAPWORD((((*GenericPDUStruct).u).ASNfile_OfferPDU).ASNroster_instance);
  1340. ((T127_FILE_OFFER_PDU*)pFileOfferPDU)->ChannelID = SWAPWORD((((*GenericPDUStruct).u).ASNfile_OfferPDU).data_channel_id - 1);
  1341. ((T127_FILE_OFFER_PDU*)pFileOfferPDU)->FileHandle = SWAPWORD((((*GenericPDUStruct).u).ASNfile_OfferPDU).file_handle);
  1342. ((T127_FILE_OFFER_PDU*)pFileOfferPDU)->AckFlag = 0x80;
  1343. }
  1344. return(fileHeaderInfo.pduSize);
  1345. }