Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

The Ultimate TCP/IP Home Page

, 25 Aug 2007
Ultimate TCP-IP is now Open Source
ultimatetcp-ip42_docs.zip
ultimatetcp-ip42_samples.zip
Ultimate TCP-IP
ActiveX
BuildAll
All.dsw
MinDependency_Dlls
MinDependency_EvalDlls
UTDns
dns.bmp
DNS.rgs
DNSPropPage.rgs
icon_fin.ico
UTDns.def
UTDns.dsp
UTDns.dsw
UTDnsps.def
UTFinger
finger.bmp
Finger.rgs
FingerProp.rgs
icon_fin.ico
UTFinger.def
UTFinger.dsp
UTFinger.dsw
UTFingerps.def
UTFingerServ
fingerse.bmp
FingerServ.rgs
FingerServProp.rgs
icon_fin.ico
UTFingerServ.def
UTFingerServ.dsp
UTFingerServ.dsw
UTFingerServps.def
utftp
ftp.bmp
Ftp.rgs
FtpPropPage.rgs
icon_fin.ico
UTFtp.def
UTFtp.dsp
UTFtp.dsw
UTFtpps.def
utftpserv
FtpSercPropPage.rgs
ftpserve.bmp
FtpServer.rgs
FtpServPropPage.rgs
icon_fin.ico
UTFtpServ.def
UTFtpServ.dsp
UTFtpServ.dsw
UTFtpServps.def
UTHistory
history.bmp
History.rgs
HistoryPropPage.rgs
icon1.ico
UTHistory.def
UTHistory.dsp
UTHistory.dsw
UTHistoryps.def
uthttp
http.bmp
Http.rgs
HttpPropPage.rgs
icon_fin.ico
UTHttp.def
UTHttp.dsp
UTHttp.dsw
UTImap4
icon_fin.ico
imap4.bmp
IMAP4.rgs
IMAP4PropPage.rgs
UTImap4.def
UTImap4.dsp
UTImap4.dsw
UTImap4ps.def
UTMail
icon_fin.ico
mail.bmp
Mail.rgs
Mail2.rgs
MailPropPage.rgs
MailPropPage2.rgs
UTMail.def
UTMail.dsp
UTMail.dsw
UTMailps.def
UTMailServ
icon_fin.ico
mailserv.bmp
MailServ.rgs
MailServPropPage.rgs
UTMailServ.def
UTMailServ.dsp
UTMailServ.dsw
UTMailServps.def
UTMsg
icon_fin.ico
message.bmp
Message.rgs
UTMsg.def
UTMsg.dsp
UTMsg.dsw
UTMsgps.def
UTNntp
icon_fin.ico
nntp.bmp
Nntp.rgs
NntpPropPage.rgs
UTNntp.def
UTNntp.dsp
UTNntp.dsw
UTNntpps.def
utping
icon_fin.ico
ping.bmp
Ping.rgs
PingProp.rgs
UTPing.def
UTPing.dsp
UTPing.dsw
UTPingps.def
UTSocket
icon_fin.ico
socket.bmp
Socket.rgs
SocketPropPage.rgs
UTSocket.def
UTSocket.dsp
UTSocket.dsw
UTSocketps.def
Demos
DemoMaster.dsw
MsgMapper
res
mainfram.bmp
MsgMapper.ico
MsgMapperDoc.ico
Toolbar.bmp
Prop2
dns.jpg
DSITools.dsp
finger.jpg
Help
CONTEXT.CDX
Context.CHJ
CONTEXT.DBF
Context.DTO
CONTEXT.FPT
Context.HH
Context.rbh
Context.RTF
DIALOG.CID
DSITools.akw
DSITools.doc
DSITools.err
DSITools.hh
DSITOOLS.HLP
DSITools.hpj
DSITools.hpr
DSITools.hpt
DSITools.kkw
DSITools.rbh
DSITools.rtf
icon1.ico
icon2.ico
ping.jpg
Prop2.dsp
Prop2.dsw
SPLSHNetTools.BMP
tracert.jpg
whois.jpg
QuickMailer
icon1.ico
properties.GIF
QuickMailer.dsp
QuickMailer.dsw
small2.ico
SplashQM.BMP
Examples
Client
ASP
headline.gif
smallogo.gif
MFC
Imap4
IMAPClient.dsp
IMAPClient.dsw
res
IMAPClient.ico
IMAPClientDoc.ico
Toolbar.bmp
Nntp
NNTPclient.dsp
NNTPclient.dsw
res
Filecopy.avi
Findcomp.avi
NNTPclient.ico
SDK
DNS
Data.ico
DNSClient.dsp
DNSClient.dsw
Finger
FingerClient.dsp
FingerClient.dsw
icon1.ico
Ftp
FTPClient.dsp
FTPClient.dsw
FTPClient.vcproj.CODEPROJECT.Nish.user
FTPClient.vcproj.vspscc
icon1.ico
History
icon1.ico
log.dsp
log.dsw
Http
HTTPClient.dsp
HTTPClient.dsw
icon1.ico
Mail
icon1.ico
test.dsp
test.dsw
MX Lookup
Data.ico
MXLookup.dsp
MXLookup.dsw
Ping
Ping_c.dsp
Ping_c.dsw
UDP
Monitor
Monitor.dsp
Monitor.dsw
Trace
Trace.dsp
Trace.dsw
VisualBasic
Dns
DNSTest.frm
DNSTest.vbp
DNSTest.vbw
icon1.ico
Finger
FingerTest.frm
FingerTest.vbp
FingerTest.vbw
Ftp
FtpTest.frm
FtpTest.frx
FtpTest.vbp
FtpTest.vbw
icon1.ico
History
HistoryTest.frm
HistoryTest.frx
HistoryTest.vbp
HistoryTest.vbw
icon1.ico
Http
HttpTest.frm
HttpTest.frx
HttpTest.vbp
HttpTest.vbw
icon1.ico
Imap4
icon1.ico
IMAP4Test.frm
IMAP4Test.frx
IMAP4Test.SUP
IMAP4Test.vbp
IMAP4Test.vbw
Mail
DecodedMessage.frm
DecodedMessage.frx
icon1.ico
MailTest.frm
MailTest.frx
MailTest.vbp
MailTest.vbw
MartsMail
AutoHelp.bas
Bld.bmp
bullet1.bmp
Clip01.ico
COPY.BMP
CUT.BMP
Form1.frm
frmAbout.frm
frmAbout.frx
frmMain.frm
frmMain.frx
frmSmtp.frm
frmSmtp.frx
icon1.ico
Itl.bmp
Mail01a.ico
Mail03.ico
Mail16b.ico
MailClient.vbp
MailClient.vbw
PASTE.BMP
Print.bmp
Progress.frm
Progress.frx
SAVE.BMP
ServerInfo.frm
ServerInfo.frx
Undrln.bmp
Nntp
icon1.ico
NntpTest.frm
NntpTest.frx
NntpTest.vbp
NntpTest.vbw
PostNDecode.frm
Ping
icon1.ico
PingTest.frm
PingTest.frx
PingTest.vbp
PingTest.vbw
Search.avi
Socket
icon1.ico
SEARCH.AVI
SocketTest.frm
SocketTest.frx
SocketTest.vbp
SocketTest.vbw
UDPSocket
UDPTest.vbp
UDPTest.vbw
UdptestMain.frm
UdptestMain.frx
Master.dsw
Server
ASP
MFC
SampleServer
icon1.ico
res
Sample_S.clw
Sample_S.dsp
SDK
AccessControlServerDemo
AccessControlServerDemo.dsp
icon1.ico
Finger
fing_s.dsp
icon1.ico
Ftp
ftp_s.dsp
icon1.ico
Http
HTTP_s.dsp
icon1.ico
Mail
icon1.ico
server.dsp
server.dsw
SPLASHMlS.BMP
VisualBasic
Finger
FingerServTest.frm
FingerServTest.frx
FingerServTest.vbp
FingerServTest.vbw
Ftp
FTPServTest.frm
FTPServTest.frx
FTPServTest.vbp
FTPServTest.vbw
Http
HTTPServerTest.frm
HTTPServerTest.frx
HttpServerTest.vbp
HttpServerTest.vbw
Mail
AdministratorForm.frm
AdministratorForm.frx
MailServerTest.frm
MailServerTest.frx
MailServerTest.vbp
MailServerTest.vbw
service
Service.dsp
test.mak
svrtest
client.mak
SVRTest.dsp
Security
Examples
Client
Echo
EchoClient.dsp
EchoClient.dsw
EchoClientS.dsp
FTPs
client.dsp
client.dsw
FtpClientS.dsp
icon1.ico
Https
client.dsp
client.dsw
HttpClientS.dsp
icon1.ico
Imap4s
IMAPClient.dsp
IMAPClient.dsw
IMAPClientS.dsp
res
IMAPClient.ico
IMAPClientDoc.ico
Toolbar.bmp
Mail
icon1.ico
icon2.ico
MailClientS.dsp
test.dsp
test.dsw
MasterS.dsw
Server
Echo
EchoServer.dsp
EchoServer.dsw
EchoServerS.dsp
FTPs
FTPs.dsp
FTPs.dsw
FtpServerS.dsp
icon1.ico
Https
HttpServerS.dsp
HTTP_s.dsp
HTTP_s.dsw
icon1.ico
Mail
icon1.ico
MailServerS.dsp
server.dsp
server.dsw
SPLASHMlS.BMP
Test_Del
Test_Del.dsp
Test_Del.dsw
Util
CertManager
CertManager.dsp
CertManager.dsw
ultimatetcp-ip42_src.zip
Include
Include
Lib
TestCert.pfx
Res
certif.bmp
certif_m.bmp
icon_cer_l.ico
icon_cer_s.ico
key.bmp
location.bmp
location_m.bmp
location_s.bmp
location_s_m.bmp
store.bmp
store_m.bmp
SecureServers
Source
UTSecureLayer
UTSecureLayer.dsp
UTSecureLayer.dsw
Servers
source
// ==================================================================
//  class:  CUT_DataManager, CUT_UserManager, CUT_UserInfo
//  struct: CUT_QUEFileHandleList
//  File:   fileman.h
//  
//  Purpose:
//
//  Declaration of mail server file and user utility classes
//
// ==================================================================
// Ultimate TCP/IP v4.2
// This software along with its related components, documentation and files ("The Libraries")
// is � 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is
// governed by a software license agreement ("Agreement").  Copies of the Agreement are
// available at The Code Project (www.codeproject.com), as part of the package you downloaded
// to obtain this file, or directly from our office.  For a copy of the license governing
// this software, you may contact us at legalaffairs@codeproject.com, or by calling 416-849-8900.
// ==================================================================
 
#ifndef CUT_DataManagerInclude
#define CUT_DataManagerInclude

class CUT_MailServer;
class CUT_UserInfo;
class CUT_QUEFileHandle;

#include <time.h>
#include <UT_CriticalSection.h>



// suppress level 4 warnings generated by STL - Transitional for VC6 support
#pragma warning ( push, 3 )	
#pragma warning (disable : 4018)
#include <vector>
#pragma warning (pop)
#pragma warning ( push, 3 )		
#include <list>
#pragma warning (pop)



using namespace std ;

typedef list<CUT_UserInfo>      USER_LIST;          // User information list
typedef list<CUT_QUEFileHandle> QUEUE_FILE_LIST;    // Queue file handles list
typedef vector<long>            LONG_VECTOR;        // Long vector


#define     MAX_USER_NAME_LENGTH    100

// ===================================
//  User information class
// ===================================
class CUT_UserInfo {
public:

    _TCHAR  szUserName[MAX_USER_NAME_LENGTH + 1];   // User name
    _TCHAR  szPassword[MAX_USER_NAME_LENGTH + 1];   // User password
    _TCHAR	szMailDir[MAX_PATH+1];                  // User mail directory

    CUT_TStringList  listEmailAddresses;             // List of e-mail addresses

    LONG_VECTOR     vcFileList;                     // List of Files IDs
    LONG_VECTOR     vcFileDeleteList;               // List of Deleted Files IDs
    LONG_VECTOR     vcFileSizeList;                 // List of Files lengths
    int             nFileListLength;                // Number of files in the list
    BOOL            bOpenFlag;                      // If TRUE user is opened
    long            nID;                            // User ID

public:

    // Default constructor
    CUT_UserInfo() : nID(-1), bOpenFlag(FALSE), nFileListLength(0)
    {
        szUserName[0] = szPassword[0] = 0;
    }

};


// ===================================
//  Linked list item of open files and their names
// ===================================
class CUT_QUEFileHandle {
public:
    long    m_lHandle;                              // File handle
    _TCHAR    m_szFileName[MAX_PATH + 1];         // File name

    // Default constructor
    CUT_QUEFileHandle() : m_lHandle(0)
    {
        m_szFileName[0] = 0;
    }

    // Constructor
    CUT_QUEFileHandle(long lHandle, LPCTSTR szFileName) : m_lHandle(lHandle)
    {
#pragma warning(disable : 4996)
        _tcsncpy(m_szFileName, szFileName, MAX_PATH);
        m_szFileName[MAX_PATH] = 0;
#pragma warning(default : 4996)
    }

};


// ===================================
//  Data manager class
// ===================================
class CUT_DataManager {

protected:
    CUT_MailServer          *m_ptrMailServer;       // Pointer to the Mail Server class
    QUEUE_FILE_LIST         m_listFileHandle;       // Queue file handles list
    CUT_InitCriticalSection	m_criticalSection;      // Critical section
    
protected:

    // Adds a file handle and name to a linked list
    virtual void    Que_AddFileHandle(long handle,LPCTSTR fileName);

    // Returns a filename from its handle
    virtual LPCTSTR  Que_GetFileName(long handle);

    // Removes the given handle from the file handle linked list
    virtual void    Que_RemoveFileHandle(long handle);

public:

    // Constructor/Destructor
    CUT_DataManager(CUT_MailServer &ptrMailServer);
    virtual ~CUT_DataManager();

    // Opens a file from the QUE
    virtual long    Que_OpenFile();

    // Creates a new file for writing to in the QUE
    virtual long    Que_CreateFile();

    // Closes an open QUE file
    virtual int     Que_CloseFile(long fileHandle,BOOLEAN deleteFlag = FALSE);

    // Reads bytes from the given file
    virtual int     Que_ReadFile(long fileHandle,LPBYTE buf,int bufLen);

    // Reads the header information from the given file.
    // Header information includes, to, from, write time, retry count, 
    // and if the mail is being returned
    virtual int     Que_ReadFileHeader(long fileHandle,LPSTR to,int maxToLen,LPSTR from,
                            int maxFromLen,time_t* tm,DWORD *numRetries,DWORD * returnMail);

    // Writes the given data to an open QUE file
    virtual int     Que_WriteFile(long fileHandle,LPBYTE buf,int bufLen);

    // Writes a file header to a QUE file.
    // Header items include to, form, retry count and if the mail is being returned
    virtual int     Que_WriteFileHeader(long fileHandle,LPCSTR to,LPCSTR from, DWORD numRetries,DWORD returnMail);
    virtual int     Que_WriteFileHeader(long fileHandle,DWORD numRetries,DWORD returnMail);

    // Copies a QUE file to another QUE file but changes the TO: name to the given name
    virtual int     Que_CarbonCopyFile(long origFileHandle,LPCSTR toAddr);

};


// ===================================
//  User manager class
// ===================================
class CUT_UserManager {

protected:
    CUT_MailServer      *m_ptrMailServer;       // Pointer to the Mail Server class
    USER_LIST           m_userList;             // User information list
    CUT_InitCriticalSection m_criticalSection;	// Critical section
    BOOL                bUserInfoChanged;       // TRUE if the user info have been changed

public:

    // Constructor/Destructor
    CUT_UserManager(CUT_MailServer &ptrMailServer);
    virtual ~CUT_UserManager();

    // Loads/Save users settings from the registry
    virtual int     LoadUserInfo(LPCTSTR subKey);
    virtual int     SaveUserInfo(LPCTSTR subKey);

    // Opens/Close the given users account
    virtual long    User_OpenUser(LPCTSTR user,LPCTSTR password);
    virtual long    User_CloseUser(long userHandle);

    // Adds new user to the list
    virtual int     User_Add(LPCTSTR lpszName, LPCTSTR szPassword, CUT_TStringList &MailAddresses);
    virtual int     User_Add(LPCTSTR lpszName, LPCTSTR szPassword, LPCTSTR MailAddress);

    // Delete user from the list
    virtual int     User_Delete(LPCTSTR lpszName);

    // Modify user from the list
    virtual int     User_Modify(LPCTSTR lpszName, LPCTSTR lpszNewName, LPCTSTR lpszNewPassword, CUT_TStringList *listNewAddresses);
    
    // Returns number of users in the list
    virtual int     User_GetCount();

    // Returns number of users in the list
    virtual CUT_UserInfo * User_GetUser(int index);

    // Returns the number of files available in the the users email box
    virtual int     User_GetFileCount(long userHandle);
    
    // Returns the file ID and size of a file in the users email box
    virtual long    User_GetFileSize(long userHandle,int index);
    virtual long    User_GetFileID(long userHandle,int index);
    
    // Opens a file in the users email box
    virtual long    User_OpenFile(long userHandle,int index);

    // Creates a new file for writing in a USER email box
    virtual long    User_CreateUserFile(LPCTSTR emailAddress);

    // Reads/Writes bytes from the open USER file
    virtual int     User_ReadFile(long fileHandle,LPBYTE buf,int bufLen);
    virtual int     User_WriteFile(long fileHandle,LPBYTE buf,int bufLen);

    // Closes an open USER file
    virtual int     User_CloseFile(long fileHandle);

    // Puts the given file into the delete list
    virtual int     User_DeleteFile(long userHandle,int index);

    // Clears all user files from the delete list
    virtual int     User_ResetDelete(long userHandle);

    // Returns a list of available files in a users account
    virtual int     User_GetFileList(CUT_UserInfo *info);

    // Deletes all the files found the the USER delete file list
    virtual int     User_DeleteAllFiles(CUT_UserInfo *info);

    // Gets free user mail directory name
    virtual int     User_GetFreeMailDir(CUT_UserInfo &info);

    // Checks if the file marked for deletion
    virtual BOOL    User_IsFileDeleted(long userHandle, int nFileIndex);
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
 
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

371 members


| Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid