/*
 *            Copyright (c) 1998-2000 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: fservapi.h
 *         Version: 1.00
 *   Original Date: 28-Jul-1999
 *	    Author: 
 *	  Language: Ansi C
 * Compile Options: 
 * Compile defines: 
 *	 Libraries: 
 *    Link Options: 
 *
 *    Entry Points: 
 *
 * Description.
 * =======================================================================
 * This file defines the function prototypes of the NET+ARM
 * FTP Server Application Programming Interface.
 *                                                                        
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 * LZ   08/04/00   Added MKD, RMD, DELE support.
 * PMJ  09/22/00   Removed FSHandleToControlSocket from the public interface.
 * LZ   06/27/01   Added FSTimeout() to change the inactivity timeout
 * PMJ  10/08/01   Removed FSRegisterValidation() in place of System Access Database.
 * JZW  03/19/03   Added new typedefs to allow callbacks functions to be declared
 *                 as types. This will facilitate the use of comments and
 *                 function prototypes in documentation generation
 * JZW 03/31/03    Added functional prototypes for all "register" functions
 * JZW 12/15/04	   Added a new function prototype fs_RegisterAdditionalCmd, allows users
 *                 to register commands. New error codes added to support this call
 *                 autodoc updates made
 *
 *
 */
#ifndef _FSERVAPI_H
#define _FSERVAPI_H

#include <sysAccess.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define FS_NOT_DEFINED (-1)

#define FS_MAXUSERLEN      (NASYSACC_STRLEN_USERNAME)

/**
 * ftp server error codes
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 * 
 * @name ftpsvr_err_code    "ftp server error codes"
 *
 * @param NAFTPS_CONTINUE                   Transfer the sector with the most dirty blocks.
 * @param NAFTPS_SUCCESS                 Transfer a randomly selected sector with dirty blocks.
 * @param NAFTPS_GENERROR                 Enable sector erase tracking.                          
 * @param NAFTPS_NOMEMSNDBUF               Enable the background sector compacting thread.
 * @param NAFTPS_NOMEMRCVBUF
 * @param NAFTPS_NOREUSE
 * @param NAFTPS_NOBIND
 * @param NAFTPS_LINGFAIL
 * @param NAFTPS_NOSETMSL
 * @param NAFTPS_FILESYSTEMERR
 * @param NAFTPS_NOFUNCTION				During registration, a null callback function was supplied
 * @param NAFTPS_NOCMD					During registration, a null command was supplied
 * @param NAFTPS_CMDTOOLONG				During registration, the command supplied was too long
 * @param NAFTPS_TABLEFULL				During registration, more than 10 commands were attempted to be registered
 *
 * @return "" "See each FTP server API for specific return values"
 */


#define NAFTPS_CONTINUE			 1
#define NAFTPS_SUCCESS           0
#define NAFTPS_GENERROR          -1
#define NAFTPS_NOMEMSNDBUF       -2
#define NAFTPS_NOMEMRCVBUF       -3
#define NAFTPS_NOREUSE           -4
#define NAFTPS_NOBIND            -5
#define NAFTPS_LINGFAIL          -6
#define NAFTPS_NOSETMSL          -7
#define NAFTPS_FILESYSTEMERR     -8

#define NAFTPS_NOFUNCTION        -9
#define NAFTPS_NOCMD             -10
#define NAFTPS_CMDTOOLONG        -11
#define NAFTPS_TABLEFULL         -12

int FSInitialize (int numusers);

void FSProperties (char *name, int priority, int sysstack, int arg1, int arg2, int arg3);

/*
 * new typedefs
 */


/**
 * User command callback function type to handle FTP commands which include
 * RETR, LIST, NLST, CWD, MKD, RMD, DELE, PWD, CDUP, RNFR, and RNTO commands
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 * 
 * @param fsParameters 		Pointer to a NULL-terminated string that contains command parameters
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 *
 * @return "" "See each FTP server API for specific return values"
 */

typedef int (* fsFunctionCmd_t)(char * fsParameters, unsigned long handle);

/**
 * User close callback function type to notify user the connection is terminated
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 * 
 * @param fsParameters 		Pointer to a NULL-terminated string that contains command parameters
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 *
 * @return "" "See each FTP server API for specific return values"
 */

typedef int (* fsFunctionClose_t)(char * fsParameters, unsigned long handle);
/**
 * User store callback function type to handle STOR command
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 * 
 * @param fsFromClient		Pointer to the data sent by the FTP client to the server
 * @param fsDataLength		Length of the data  
 * @param fsParameters		Pointer to a NULL-terminated string that contains command parameters
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 *
 * @return "" "See each FTP server API for specific return values"
 */
typedef int (* fsFunctionStor_t)(char * fsFromClient, int fsDataLength, char * fsParameters, unsigned long handle);

/**
 * User system callback function type to handle SYST command
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 * 
 * @param fsParameters		Pointer to a NULL-terminated string that contains command parameters
 * @param fsUserData		Pointer to a 256-character buffer that holds the information
 *				returned by the user application. The server returns this information
 *				to the requesting client.
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 *
 * @return "" "See each FTP server API for specific return values"
 */
typedef int (* fsFunctionSyst_t)(char * fsParameters, char * fsUserData, unsigned long handle);

/**
 * User validate callback function type to validate username and password
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 *
 * @param fsUserName		Pointer to the username supplied by the requesting FTP client.
 * @param fsPassword		Pointer to the expected password. The user application callback
 *				routine supplies the expected password in the 32-byte string array
 *
 * @return "" "See each FTP server API for specific return values"
 */
typedef int (* fsFunctionValidate_t)(char * fsUserName, char * fsPassword);

/**
 * User directory callback function type to handle PWD command
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 *
 * @param fsParameters 		Pointer to a NULL-terminated string that contains command parameters
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 * @param buffer			Pointer to memory which will contain a NULL-terminated string for
 *							the present working directory.
 *
 * @return "" "See each FTP server API for specific return values"
 */
typedef int (* fsFunctionPwd_t)(char * fsParameters, unsigned long handle, char * buffer);

/**
 * User new command Callback function type to handle any customized commands 
 * that customer supports
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 *
 * @param handle			Identifier for FTP connection which is required for all FTP server API
 * @param command			Pointer to a NULL-terminated string that contains command 
 * @param argu		 		Pointer to a NULL-terminated string that contains command parameters
 * @param access_level		User login security access level	
 *
 * @return "" "The return value is currently not used."
 *
 * @note This definition is being depricated
 * @see @link NAgetSysAccess
 */
typedef int (* fsFunctionNewCmd_t)(unsigned long handle, char * command, char * argu, unsigned int access_level);

/**
 * User new command Callback function type to handle any customized commands 
 * that customer supports
 *
 * @external
 * @category FTP_Server
 * @since 6.0
 *
 * @param handle			Identifier for FTP connection which is required for all FTP server API 
 * @param argu		 		Pointer to a NULL-terminated string that contains command parameters
 * @param access_level		User login security access level	
 *
 * @return "" "The return value is currently not used."
 *
 * @see @link NAgetSysAccess
 */

typedef int (* fsFuncNewCmd_t)(unsigned long handle, char * argu, unsigned int access_level);

int fs_RegisterAdditionalCmd(fsFuncNewCmd_t fs_New_Cmd, char * fsCmdName);

int FSRegisterRETR (fsFunctionCmd_t);

int FSRegisterSTOR (fsFunctionStor_t);

int FSSequenceNumber (unsigned long handle);

int FSStartServer ();

char *FSUserName (unsigned long handle);

int FSRegisterSYST (fsFunctionSyst_t);

int FSRegisterLIST (fsFunctionCmd_t);

int FSRegisterNLST (fsFunctionCmd_t);

int FSRegisterCWD (fsFunctionCmd_t);

int FSRegisterControlClose (fsFunctionClose_t);

int FSRegisterDataClose (fsFunctionClose_t);

int FSHandleToSocket (unsigned long);

int FSRegisterMKD (fsFunctionCmd_t);

int FSRegisterRMD (fsFunctionCmd_t);

int FSRegisterDELE (fsFunctionCmd_t);

int FSRegisterPWD (fsFunctionPwd_t);

int FSRegisterCDUP (fsFunctionCmd_t);

int FSRegisterRNFR(fsFunctionCmd_t);

int FSRegisterRNTO(fsFunctionCmd_t);


int FSTimeout(unsigned long);

#ifdef __cplusplus
}
#endif

#endif /* _FSERVAPI_H */
