Restored from previous forum. Originally posted by Kendrel.
 i would like to code a hook dll for servu (an ftp server), but iam having (shame on me) problems to convert it. most problem for me seems to be the char array inside the structure... i dunno how to convert this in purebasic.  
i will post the full source (it is not that much), and would be very glad if someone could convert it, but converting the structures would be a good start aswell... thx in advance...
here comes the header file
// WULOG.H
// =======
//
//   WU_FTP logfile format DLL for use with Serv-U v2.2 and higher.
//   Code can be found in WULOG.CPP.
//
#ifndef WULOGH                          // avoid multiple inclusion
#define WULOGH
using namespace std;                    // to use standard lib identifiers
// Serv-U event definitions
// a copy of the list found in the Serv-U manual
#define EVNT_None	    0		// none
#define EVNT_IPName	    1		// symbolic IP name available
#define EVNT_Connect	    2		// connection was made
#define EVNT_Close	    3		// closed connection
#define EVNT_BouncedIP	    4		// bounced client because of IP address
#define EVNT_TooMany	    5		// bounced user because there are too many
#define EVNT_WrongPass	    6		// too many times wrong password
#define EVNT_TimeOut	    7		// connection timed out
#define EVNT_Login	    8		// use logged in
#define EVNT_StartUp	    9		// start upload of file
#define EVNT_EndUp	   10		// successfull upload of file
#define EVNT_StartDown     11           // start of download of file
#define EVNT_EndDown	   12           // successfull download of file
#define EVNT_AbortUp	   13		// aborted upload
#define EVNT_AbortDown	   14		// aborted download
#define EVNT_Rename	   15		// renamed file/dir
#define EVNT_DelFile	   16		// deleted file
#define EVNT_DelDir 	   17		// deleted dir
#define EVNT_ChgDir	   18		// changed working directory
#define EVNT_MakeDir	   19		// created directory
// Serv-U event hook definitions
#define EVNT_HookDown	  100		// hook for file downloads
#define EVNT_HookUp	  101		// hook for file uploads
#define EVNT_HookAppend   102		// hook for append file upload
#define EVNT_HookUnique	  103		// hook for unique name upload
#define EVNT_HookRename	  104		// hook for rename file/dir
#define EVNT_HookDelFile  105		// hook for delete file
#define EVNT_HookDelDir	  106		// hook for delete dir
#define EVNT_HookMkd	  107		// hook for make directory
#define EVNT_HookRmd	  108		// hook for remove directory
// Serv-U sub-event codes
#define SEVNT_None	    0		// no sub-event
#define SEVNT_ErrWrite	    1		// problem writing to disk
#define SEVNT_ErrRead	    2		// problem reading from disk
#define SEVNT_ErrQuota	    3		// insufficient disk quota
#define SEVNT_ErrTOut	    4		// packet timed out
#define SEVNT_ErrAbort	    5		// user aborted transfer
#define SEVNT_ErrUnknown    6		// unknown error
#define SEVNT_ErrClose	    7		// data connection closed unexpectedly
// return codes for hooks
#define REVNT_None	    0		// nothing
#define REVNT_Proceed	    1		// let event pass
#define REVNT_Abort	    2		// stop event
#define REVNT_Suspend	    3		// suspend event until decision is made
// event information structure for communications with DLL's
struct RFTPEventStr {
  // event info
  DWORD Event;				// event type
  DWORD SubEvent;			// sub-event type
  // user info
  DWORD SessionID;			// unique ID of the FTP session
  char User[40];			// user name
  char ClientIP[16];			// IP number of client
  char LocalIP[16];			// IP number the client connected to
  // event attributes
  DWORD Duration;			// duration of events
  DWORD Size;				// size of object (ie. file)
  // hook info
  HWND hWindow;				// window handle to post decision to
  UINT Message;				// message to post
  char* pReplyText;			// pointer to text to send to user
  // scratch pad area
  char AuxOne[512];			// auxiliary area one
  char AuxTwo[512];			// auxiliary area two
};
// user info structure to keep track of sessions
struct RUserInfoStr {
  DWORD SessionID;                      // session ID
  string IPName;                        // IP name of user (if available)
  string AnonPass;                      // anonymous password used to log in (for anonymous users)
};
// some definitions to make life easier
typedef RSimpleList LSTUINFO;                     // simple linked list of user info structures
#define EXPORT  extern "C" __declspec (dllexport)               // exported functions declaration header
#define MAXPATH 300                                             // maximum path length, used for declaring long strings
// text constants
#define INIFILE         "wulog.ini"                             // .ini file name
#define INISECTION      "LOG"                                   // .ini file section header used
#define INILOGFILE      "FileName"                              // .ini file logfile line
// function definitions
EXPORT WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc);
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB);  
void LoadIniFile(HINSTANCE hInst);                      // process .ini file
void LogLine(RFTPEventStr* pEventStruc);                // log line to logfile
#endif
and here is the main code:
// FILTERDLL.CPP
// =============
//
//   WU_FTP log file format DLL for use with Serv-U v2.2a and higher.
//   Enables Serv-U users to create log files in WU_FTP file format.
//   The logging settings are read from a file named WULOG.INI.
//   Syntax for that file is (example):
//
//      ********** WULOG.INI ********
//
//              [LOG]
//              FileName=c:\serv-u\wulog.txt
//
//      *****************************
//
//             Author: Rob Beckers
//               Date: 11-JUL-97
//      Last revision: 11-JUL-97
//        Revision nr: 1
//
//   Revision history:
//
#include 
#include 
#include                      // needed for STL strings
#include                        // use standard template lib strings, not Borland's
#include 
#include 
#pragma hdrstop                         // to make Borland compiler stop including pre-compiled header files
#include "list.h"                       // used here for simple list management
#include "wulog.h"
// Global variable definitions
LSTUINFO UserList;                      // list of current user info structures
char LogFile[MAXPATH];                  // full path/name of file to log to
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB)
// ******
// Comparison operator for user info structures.
// Is used by the simple list routines.
// ******
{
  // equality means the session ID's are the same
  return(ArgA.SessionID==ArgB.SessionID);
}
void LoadIniFile(HINSTANCE hInstance)
// ******
// Load .ini file variables
// ******
{
  char IniFile[MAXPATH];                // full path of .ini file
  // only initialize once
  static bool Once=FALSE;
  if (Once) return;                     // already initialized
  Once=true;                            // this is first time, remember 
  // construct full path of .ini file
  GetModuleFileName(hInstance,IniFile,MAXPATH);
  char* pEnd=strrchr(IniFile,'\\');	// strip .dll file name
  if (pEnd) pEnd[1]='\0';
  strcat(IniFile,INIFILE);              // create full path .ini name
  // get log file name
  GetPrivateProfileString(INISECTION,INILOGFILE,"",LogFile,MAXPATH,IniFile);
}
void LogLine(RFTPEventStr* pEventStruc)
// ******
// Log a line to the logfile.
//
// Parameter: pInfoStruc = pointer to event information
// ******
{
  // some bullet proofing
  if (LogFile[0]=='\0') return;         // only if we have a logfile
  RUserInfoStr UserInfo;
  UserInfo.SessionID=pEventStruc->SessionID;
  if (!UserList.Find(UserInfo)) return; // only if we have info on this user
  // create time stamp
  char CurTime[40];
  time_t Count=time(NULL);
  strcpy(CurTime,ctime(&Count));
  CurTime[24]='\0';                     // get rid of newline at end
  // log transfer to file
  FILE* hFile=fopen(LogFile,"a+t");     // append to file
  if (!hFile) return;                   // problem writing to file
  char Direction='o';                   // direction flag
  if (pEventStruc->Event==EVNT_EndUp) Direction='i';
  char Access='a';                      // access flag
  char User[512];                       // user name or anonymous 'password'
  if (stricmp(pEventStruc->User,"anonymous")) {
    Access='r';
    strcpy(User,pEventStruc->User);
  }
  else strcpy(User,UserInfo.AnonPass.c_str());
  fprintf(hFile,"%s %lu %s %lu %s b _ %c %c %s FTP 0 *\n",
    CurTime,pEventStruc->Duration/1000L,UserInfo.IPName.c_str(),pEventStruc->Size,
    pEventStruc->AuxOne,Direction,Access,User);
  fclose(hFile);  
}
WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc)
// ******
// Event (hook) handler.
// ******
{
  RUserInfoStr UserInfo;
  // disect event
  switch (pEventStruc->Event) {
    // new user connects to server
    case EVNT_Connect:
      UserInfo.SessionID=pEventStruc->SessionID;
      UserInfo.IPName=pEventStruc->ClientIP;
      UserList.Add(UserInfo);           // add new user to list of users
      break;
    // user disconnects from server
    case EVNT_Close:
      UserInfo.SessionID=pEventStruc->SessionID;
      UserList.Remove(UserInfo);        // remove user info from list
      break;
    // received symbolic IP name info
    case EVNT_IPName:
      UserInfo.SessionID=pEventStruc->SessionID;
      if (UserList.Find(UserInfo)) {    // add IP name to structure in list
        UserList.GetCurItemPoint()->IPName=pEventStruc->AuxOne;
      }
      break;
    // catch anonymous' passwords
    case EVNT_Login:
      if (!stricmp(pEventStruc->User,"anonymous")) {
        UserInfo.SessionID=pEventStruc->SessionID;
        if (UserList.Find(UserInfo)) {  // add 'password' to structure in list
          UserList.GetCurItemPoint()->AnonPass=pEventStruc->AuxOne;
        }
      }
      break;
    // log file transfers
    case EVNT_EndUp:
    case EVNT_EndDown:
      LogLine(pEventStruc);             // log to file
      break;
  }
  return(REVNT_None);
}
BOOL WINAPI DllEntryPoint(HINSTANCE hInstance,DWORD fdwReason,PVOID /*pvReserved*/)
// ******
// Window's DLL entry point.
// Used for initializing list of names-to-block.
// ******
{
  switch (fdwReason) {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
      LoadIniFile(hInstance);           // load .ini file info
      break;
  }
  return(TRUE);                         // signal success to Windows
}
			
			
									
									
						need help to convert some c code pls...
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Kendrel.
i have made it meanwhile, and i can catch these char (byte) arrays now, but i dont know if it is the best solution... please have a look at my code...
#EVNT_None = 0 ; none
#EVNT_IPName = 1 ; symbolic IP name available
#EVNT_Connect = 2 ; connection was made
#EVNT_Close = 3 ; closed connection
#EVNT_BouncedIP = 4 ; bounced client because of IP address
#EVNT_TooMany = 5 ; bounced user because there are too many
#EVNT_WrongPass = 6 ; too many times wrong password
#EVNT_TimeOut = 7 ; connection timed out
#EVNT_Login = 8 ; use logged in
#EVNT_StartUp = 9 ; start upload of file
#EVNT_EndUp = 10; successful upload of file
#EVNT_StartDown = 11; start of download of file
#EVNT_EndDown = 12 ; successful download of file
#EVNT_AbortUp = 13 ; aborted upload
#EVNT_AbortDown = 14 ; aborted download
#EVNT_Rename = 15 ; renamed file/dir
#EVNT_DelFile = 16 ; deleted file
#EVNT_DelDir = 17 ; deleted dir
#EVNT_ChgDir = 18 ; changed working directory
#EVNT_MakeDir = 19 ; created directory
#EVNT_ProgUp = 20 ; progress of upload
#EVNT_ProgDown = 21 ; progress of download
#EVNT_Maintenance = 22 ; user switching To maintenance mode
; The ‘SubEvent’ codes are:
#SEVNT_None = 0 ; no sub-event
#SEVNT_ErrWrite = 1 ; problem writing To disk
#SEVNT_ErrRead = 2 ; problem reading from disk
#SEVNT_ErrQuota = 3 ; insufficient disk quota
#SEVNT_ErrTOut = 4 ; packet timed out
#SEVNT_ErrAbort = 5 ; user aborted transfer
#SENVT_ErrUnknown = 6 ; unknown error
#SEVNT_ErrClose = 7 ; Data connection closed unexpectedly
#SEVNT_System = 8 ; switching To SYSTEM maintenance mode
#SEVNT_Group = 9 ; switching To GROUP maintenance mode
#SEVNT_Domain = 10 ; switching To DOMAIN maintenance mode
#SEVNT_ReadOnly = 11 ; user switching To READ-ONLY maintenance mode
; The ‘Event’ codes used For hooked events are:
#EVNT_HookDown = 100 ; hook For file downloads
#EVNT_HookUp = 101 ; hook For file uploads
#EVNT_HookAppend = 102 ; hook For append file upload
#EVNT_HookUnique = 103 ; hook For unique name upload
#EVNT_HookRename = 104 ; hook For rename file/dir
#EVNT_HookDelFile = 105 ; hook For delete file
#EVNT_HookDelDir = 106 ; hook For delete dir
#EVNT_HookMkd = 107 ; hook For make directory
#EVNT_HookSite = 108 ; hook For the SITE command
#EVNT_HookChgDir = 109 ; hook For change dir command
#EVNT_HookCommand = 110 ; hook For raw FTP command
#EVNT_HookReply = 111 ; hook For raw FTP reply
Structure RFTPEventStr
; event info
Event.l ; event code
SubEvent.l ; sub-event code
;user info
SessionID.l; unique ID of the FTP session
User.b[40] ; user name
ClientIP.b[16] ; IP number of client
LocalIP.b[16] ; IP number the client connected to
; event attributes
Duration.l ; duration of events (in ms)
Size.l ; size of object (i.e. transferred)
; hook info
hWindow.l ; window handle to post decision to
Message.l ; message to post
pReplyText.l ; pointer to text to send to user
; scratch pad area
AuxOne.b[512] ; auxiliary area one
AuxTwo.b[512] ; auxiliary area two
EndStructure
ProcedureDLL AttachProcess(Instance)
NewList user.RFTPEventStr()
EndProcedure
ProcedureDLL DetachProcess(Instance)
ResetList(User())
EndProcedure
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
ProcedureDLL.w HandleEventHook (*pEventStruc.RFTPEventStr)
AddElement(user())
For i=0 To 16
user()\ClientIP=*pEventStruc\ClientIP
Next i
Buffer$ = PeekS(@user()\ClientIP[0],16)
MessageRequester(Buffer$,Buffer$, #MB_ICONINFORMATION)
EndProcedure
i am using a loop, but i wonder if this is the right solution and iam not sure if there is a better way to do that...
thx for your time,
kendrel
			
			
									
									
						i have made it meanwhile, and i can catch these char (byte) arrays now, but i dont know if it is the best solution... please have a look at my code...
#EVNT_None = 0 ; none
#EVNT_IPName = 1 ; symbolic IP name available
#EVNT_Connect = 2 ; connection was made
#EVNT_Close = 3 ; closed connection
#EVNT_BouncedIP = 4 ; bounced client because of IP address
#EVNT_TooMany = 5 ; bounced user because there are too many
#EVNT_WrongPass = 6 ; too many times wrong password
#EVNT_TimeOut = 7 ; connection timed out
#EVNT_Login = 8 ; use logged in
#EVNT_StartUp = 9 ; start upload of file
#EVNT_EndUp = 10; successful upload of file
#EVNT_StartDown = 11; start of download of file
#EVNT_EndDown = 12 ; successful download of file
#EVNT_AbortUp = 13 ; aborted upload
#EVNT_AbortDown = 14 ; aborted download
#EVNT_Rename = 15 ; renamed file/dir
#EVNT_DelFile = 16 ; deleted file
#EVNT_DelDir = 17 ; deleted dir
#EVNT_ChgDir = 18 ; changed working directory
#EVNT_MakeDir = 19 ; created directory
#EVNT_ProgUp = 20 ; progress of upload
#EVNT_ProgDown = 21 ; progress of download
#EVNT_Maintenance = 22 ; user switching To maintenance mode
; The ‘SubEvent’ codes are:
#SEVNT_None = 0 ; no sub-event
#SEVNT_ErrWrite = 1 ; problem writing To disk
#SEVNT_ErrRead = 2 ; problem reading from disk
#SEVNT_ErrQuota = 3 ; insufficient disk quota
#SEVNT_ErrTOut = 4 ; packet timed out
#SEVNT_ErrAbort = 5 ; user aborted transfer
#SENVT_ErrUnknown = 6 ; unknown error
#SEVNT_ErrClose = 7 ; Data connection closed unexpectedly
#SEVNT_System = 8 ; switching To SYSTEM maintenance mode
#SEVNT_Group = 9 ; switching To GROUP maintenance mode
#SEVNT_Domain = 10 ; switching To DOMAIN maintenance mode
#SEVNT_ReadOnly = 11 ; user switching To READ-ONLY maintenance mode
; The ‘Event’ codes used For hooked events are:
#EVNT_HookDown = 100 ; hook For file downloads
#EVNT_HookUp = 101 ; hook For file uploads
#EVNT_HookAppend = 102 ; hook For append file upload
#EVNT_HookUnique = 103 ; hook For unique name upload
#EVNT_HookRename = 104 ; hook For rename file/dir
#EVNT_HookDelFile = 105 ; hook For delete file
#EVNT_HookDelDir = 106 ; hook For delete dir
#EVNT_HookMkd = 107 ; hook For make directory
#EVNT_HookSite = 108 ; hook For the SITE command
#EVNT_HookChgDir = 109 ; hook For change dir command
#EVNT_HookCommand = 110 ; hook For raw FTP command
#EVNT_HookReply = 111 ; hook For raw FTP reply
Structure RFTPEventStr
; event info
Event.l ; event code
SubEvent.l ; sub-event code
;user info
SessionID.l; unique ID of the FTP session
User.b[40] ; user name
ClientIP.b[16] ; IP number of client
LocalIP.b[16] ; IP number the client connected to
; event attributes
Duration.l ; duration of events (in ms)
Size.l ; size of object (i.e. transferred)
; hook info
hWindow.l ; window handle to post decision to
Message.l ; message to post
pReplyText.l ; pointer to text to send to user
; scratch pad area
AuxOne.b[512] ; auxiliary area one
AuxTwo.b[512] ; auxiliary area two
EndStructure
ProcedureDLL AttachProcess(Instance)
NewList user.RFTPEventStr()
EndProcedure
ProcedureDLL DetachProcess(Instance)
ResetList(User())
EndProcedure
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
ProcedureDLL.w HandleEventHook (*pEventStruc.RFTPEventStr)
AddElement(user())
For i=0 To 16
user()\ClientIP=*pEventStruc\ClientIP
Next i
Buffer$ = PeekS(@user()\ClientIP[0],16)
MessageRequester(Buffer$,Buffer$, #MB_ICONINFORMATION)
EndProcedure
i am using a loop, but i wonder if this is the right solution and iam not sure if there is a better way to do that...
thx for your time,
kendrel