/*
 *            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: http_awsapi.h
 *         Version: 1.00
 *   Original Date:  23-Aug-2000
 *	    Author: 
 *	  Language: Ansi C
 * Compile Options: 
 * Compile defines: 
 *	 Libraries: 
 *    Link Options: 
 *
 *    Entry Points: 
 *
 * Description.
 * =======================================================================
 * This file defines the function prototypes of the NET+ARM
 * Advanced Web Server Application Programming Interface.
 *                                                                        
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 * PMJ  10/08/01   Removed RpHSSetRealm() in place of System Access Database.
 * JZW  03/19/03   Added new typedef to facilitate the use of comments as
 *                 documentation input
 * ESUN 06/18/03   Added HS_SERVER_PARAMETER structure and prototype of
 *                 NAHSStartServer().
 * JZW  11/7/03    Added functional prototype for function RpGetConnectionInformation
 * JZW  11/10/03   Functional prototype of RpHSGetServerData was missplaced, fixed
 *                 added autodoc header for the function
 * JZW  01/16/03   Added manifest constants and types to support ssl support in call
 *                 to NAHSStartServer
 *
 *
 */

#ifndef _HTTP_AWSAPI_H_
#define _HTTP_AWSAPI_H_
#ifdef __cplusplus
extern "C"
{
#endif

#include <time.h>
#include <Npttypes.h>
#include "AsExtern.h"

#define HS_SERVER_PARAMETER_VERSION_100 0
#define LENGTH_HS_SERVER_PARAMETER_VERSION_0_STRUCTURE 196 /* standard, no parameters */
#define LENGTH_HS_SERVER_PARAMETER_VERSION_1_STRUCTURE 228 /* parameters to SSL */


#define INVALID_STRUCTURE_LENGTH       -2

/*Please do not change this constant. Or it will crash the system*/
#define Maxlength                      128 
/* new type for passing ssl information into the web server */

/** 
 * The following structure is used to configure secure AWS or HTTP server's parameters
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.1
 *
 * @param cipher_list           cipher list to use for configuring ssl
 * @param cipher_list_len       length of the cipher list
 * @param certificate           certificate to use for configuring ssl
 * @param certificate_len       length of the certificate
 * @param key                   key to use for configuring ssl
 * @param key_len               length of the key
 * @param secure_only           ??
 * @see @link HS_SERVER_PARAMETER
 * @see @link Param_Secure_t
 *
 */
typedef struct
{
    unsigned char * cipher_list;
    int cipher_list_len;
    char * certificate;
    int certificate_len;
    char * key;
    int key_len;
    char secure_only;
} Param_Secure_t;

/* The following structure is used to configure AWS or HTTP server's parameters
   Lengthofstructure      --Length of this structure. Must be valid number(0 is ok for the initial version)
                            or server is not started and INVALID_STRUCTURE_LENGTH returned
   deviceName             --product device name.Customers can configure this as they like.
                            For example, "Netsilicon Web Server" for netsilicon Inc.
   connections            --concurrent connection number. default is 6 for passive connections.
   persistent_timeout     --connection max idle time (seconds). During this period of time if no new
                            request comes, connection is closed.
   session_timeout        --max session time (seconds)without meed for relogin since login. after 
                            this time, relogin needed.
   port                   --server port. default 80.
   ServerStartDate        --server start date, default 8/26/2001.
   Server_thread_name     --Server's thread name, default as "HSV".
   Server_thread_priority --Server's thread priority, default 16.
   Server_thread_sysstack --Server's thread system stack, default 4096.
   Server_thread_usrstack --Server's thread user stack, default 2048.
   PageNotFoundErrorPage  --Error page object pointer for url not found.
   ServerBusyErrorPage    --Error page object pointer for the request page is
                            used by others.
   DigestUnsupportedErrorPage  --Error page object pointer for client(browser) not support digest.
   AccessNotAllowedErrorPage   --Error page object pointer for login failure.
   FilesystemErrorPage    --Error page object pointer for file system operation wrong.
   InputTooLargeErrorPage --Error page object pointer for post larger data >4096 bytes.
   CopyRightPage          --Error page object pointer for displaying copy right.
   UnexpectedMultipartErrorPage--Error page object pointer for wrong fMimeDataType(not eRpDataTypeFormMultipart)
                                 of the object when upload file.
*/

/** 
 * The following structure is used to configure AWS or HTTP server's parameters
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.0
 *
 * @param Lengthofstructure     Length of this structure. Must be valid number(0 is ok for the initial version)
 *                         		or server is not started and INVALID_STRUCTURE_LENGTH returned
 * @param deviceName            product device name.Customers can configure this as they like.
 *                        		For example, "Netsilicon Web Server" for netsilicon Inc.
 * @param thePagenameReturnTo   thePagenameReturnTo is the string displayed in the link. You can change it 
 *                              as "Home Page".
 * @param theUrlReturnTo        is the page url from the error page return to. The default is the last
 *                              page to navigate to the request page. If theUrlReturnTo is initialized to "",
 *                              the default page is returned to. theUrlReturnTo length is limited to 256 bytes,
 *                              if larger than that, the server may be crashed.
 * @param errorPageLinkStart    is the begining part of the link string <A HREF=" (default). You can
 *                              put many atrributes in this link, such as <A TYPE="video/mpeg" HREF=\".
 * @param connections           Concurrent connection number. default is 6 for passive connections.
 * @param persistent_timeout    Connection max idle time (seconds). During this period of time if no new
 *                          	request comes, connection is closed.
 * @param session_timeout       Max session time (seconds)without meed for relogin since login. after 
 *                          	this time, relogin needed.
 * @param port                  Server port. default 80.
 * @param ServerStartDate       Server start date, default 8/26/2001.
 * @param Server_thread_name    Server's thread name, default as "HSV".
 * @param Server_thread_priority 	Server's thread priority, default 16.
 * @param Server_thread_sysstack 	Server's thread system stack, default 4096.
 * @param Server_thread_usrstack 	Server's thread user stack, default 2048.
 * @param PageNotFoundErrorPage  	Error page object pointer for url not found.
 * @param ServerBusyErrorPage    	Error page object pointer for the request page is
 *                          		used by others.
 * @param DigestUnsupportedErrorPage  	Error page object pointer for client(browser) not support digest.
 * @param AccessNotAllowedErrorPage   	Error page object pointer for login failure.
 * @param FilesystemErrorPage    		Error page object pointer for file system operation wrong.
 * @param InputTooLargeErrorPage 		Error page object pointer for post larger data >4096 bytes.
 * @param CopyRightPage          		Error page object pointer for displaying copy right.
 * @param UnexpectedMultipartErrorPage	Error page object pointer for wrong fMimeDataType(not eRpDataTypeFormMultipart)
 *                               		of the object when upload file.
 * @param SSL_ParametersP		Parameters used by the ssl-enabled web server
 */
typedef struct{    
    WORD32    Lengthofstructure;   
    char      deviceName[Maxlength];
    char      thePagenameReturnTo[Maxlength];
    char      theUrlReturnTo[Maxlength];
    char      errorPageLinkStart[Maxlength];
    WORD32    connections;  
    WORD32    persistent_timeout;   
    WORD32    session_timeout;  
    WORD32    port;    
    struct tm ServerStartDate;
    char      Server_thread_name[64];
    WORD32    Server_thread_priority;
    WORD32    Server_thread_sysstack;
    WORD32    Server_thread_usrstack;
    rpObjectDescriptionPtr PageNotFoundErrorPage;
    rpObjectDescriptionPtr ServerBusyErrorPage;
    rpObjectDescriptionPtr DigestUnsupportedErrorPage;
    rpObjectDescriptionPtr AccessNotAllowedErrorPage;
    rpObjectDescriptionPtr FilesystemErrorPage;
    rpObjectDescriptionPtr InputTooLargeErrorPage;
    rpObjectDescriptionPtr CopyRightPage;
    rpObjectDescriptionPtr UnexpectedMultipartErrorPage;
    Param_Secure_t *SSL_ParametersP;
    
} HS_SERVER_PARAMETER;

/** 
 * The following structure is used to configure secure AWS or HTTP server's parameters
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.1
 *
 * @param WebServerParams       Parameters specific to configuring the web server
 * @param SecurityParams        Parameters specific to setting up ssl
 *
 * @see @link HS_SERVER_PARAMETER
 * @see @link Param_Secure_t
 *
 */
typedef struct {
    HS_SERVER_PARAMETER WebServerParams;
    Param_Secure_t      SecurityParams;
} RpHsSecureParams_t;


/*
 * int  NAHSStartServer( HS_SERVER_PARAMETER server_parameters)
 *
 * This routine starts the Web server task with configurable server parameters.  
 *
 * External API Routine
 *
 *
 * PARAMETERS
 *
 *    server_parameters    server parameter structure contains connections, port,
 *                         persistent time, ......
 * RETURNS
 *
 *    <0     The HTTP server was not started due to an error.
 *     0     The server was successfully started.
 *
 */

int  NAHSStartServer( HS_SERVER_PARAMETER server_parameters);


    
/*
 * int RpHSStartServer (void)
 *
 * This routine starts the Web server task.  
 *
 * External API Routine
 *
 * RETURNS
 *
 *    <0     The HTTP server was not started due to an error.
 *     0     The server was successfully started.
 *
 */

int RpHSStartServer (void);

/**
 * Gives an application program access to the ip address and the port of the
 * http client who is on the other end of an http socket
 *
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.0
 *
 * @param	theTaskDataPtr		pointer to the internal web server data structure
 * @param	RemoteIP                pointer to the peer's IP address (filled in by function)
 * @param       RemotePort              pointer to the users ip port (filled in by function)
 *
 * @return  -1    When theTaskDataPtr parameter is NULL
 * @return  -2    When RemoteIP is NULL
 * @return  -3    When RemotePort is NULL
 * @return   0    On success
 */



int RpGetConnectionInformation(void * theTaskDataPtr, unsigned long * RemoteIP, unsigned short * RemotePort);

/*
 * Gives an application program access to the advanced web server's internal data
 * structure. This is used by a number of pbuilder callback routines
 *
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.0
 *
 * @return  Pointer to the internal data structure  Returned as a *void. Structure
 *                                  is not directly accessible by an application
 */

void * RpHSGetServerData(void);

/**
 * User callback function to set security access for the request URL 
 *
 * @external
 * @category HTTP_Basic_Server
 * @since 6.0
 *
 * @param handle  Value to be passed as a "handle" parameter to other HTTP server API calls
 * @param URLp    Pointer to the URL of the Web page being accessed
 */


typedef void (* hsFunctionSecurity_t)(unsigned long handle, char * URLp);


/**
 * User callback function to search the request URL
 *
 * @external
 * @category HTTP_Basic_Server
 * @since 6.0
 *
 * @param handle  Value to be passed as a "handle" parameter to other HTTP server API calls
 * @param URLp    Pointer to the URL of the Web page being accessed
 */
typedef void (* hsFunctionSearch_t)(unsigned long handle, char * URLp);


/**
 * User callback to allow a realm to be set as not challenged
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.0
 *
 * @param realms  Value to be passed as a "handle" parameter to other HTTP server API calls
 * @param nochallenge    0 to shutoff anything else sets realms to no challenge state
 *
 * @return 0    successful
 * @return -1   bad parameter passed in
 */
int NASetRealmChallenge( unsigned int realms, unsigned int nochallenge);

/**
 * Allows user program to delete the currently authentiated user
 *
 * @external
 * @category HTTP_Advanced_Server
 * @since 6.0
 *
 * @param theTaskDataPtr  Pointer to the internal web server data structure
 * @param theIndexValuesPtr    Not used
 *
 */
void RpDeleteCurrentUser(void * theTaskDataPtr, Signed16Ptr theIndexValuesPtr);

void NAHttpResetOnDisconnect(unsigned int enable);

#ifdef __cplusplus
}
#endif
  
#endif
