/*
 *            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/10/03    Added functional prototype for function RpGetConnectionInformation
 * JZW  12/5/03     Added functional prototype for RpDeleteCurrentUser and NASetRealmChallenge
 * JZW  01/16/03   Added manifest constants and types to support ssl support in call
 *                 to NAHSStartServer
 * JZW  03/19/04   Changes made to structure HS_SERVER_PARAMETER to
 *                 support configurable error pages
 * MLC  02/09/07   Added server_header to the HS_SERVER_PARAMETER structure.
 *
 *
 */

#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

/* These definitions are used to indicate any modification 
 * on the HS_SERVER_PARAMETER structure.
 * Do not change these values!
 */
#define LENGTH_HS_SERVER_PARAMETER_VERSION_0_STRUCTURE 	196 /* std no parameters */
#define LENGTH_HS_SERVER_PARAMETER_VERSION_1_STRUCTURE 	228 /* no ssl parameters */

#define HS_SERVER_NAME_SIZE			 	64

#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 */

/*ad*
 * The following structure is used to configure secure AWS or HTTP server's parameters
 *
 * @external
 * @category Web_Servers:Advanced_Web_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           Not used.
 * @see @link HS_SERVER_PARAMETER
 * @see @link Param_Secure_t
 *
*ad*/
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;

/*ad*
 * The following structure is used to configure secure AWS or HTTP server's parameters
 * in conjunction with the certificate database. 
 *
 * @external
 * @category Web_Servers:Advanced_Web_Server
 * @since 6.3
 *
 * @param cipher_list           cipher list to use for configuring ssl
 * @param cipher_list_len       length of the cipher list
 * @param cert_db_handle        handle to the certificate database
 * @param secure_only           only HTTPS will be allowed.
 * @see @link HS_SERVER_PARAMETER
 *
*ad*/
typedef struct
{
    unsigned char * cipher_list;
    int cipher_list_len;
    void * cert_db_handle;
    char secure_only;
} NaSecureParams_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.
*/

/*ad*
 * The following structure is used to configure AWS or HTTP server's parameters
 *
 * @external
 * @category Web_Servers:Advanced_Web_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 on the default error page. Note that 
 *                              this is also the name of the PageBuilder HTML Referer Tag.  Thus if this parameter
 *								is overwritten, then the RpHtmlReferer comment tag will not function as described.
 *                              Instead, this overwritten value will be displayed in all uses of the RpHtmlReferer
 *								comment tag.  The default is "Last Page" and has a limit of 256 bytes.  To continue
 *								using the default server value, use the empty string.
 * @param theUrlReturnTo        is the thePagenameReturnTo URL link (see above).  The default uses the HTTP header
 *                              Referer field, which is used to get to the prior page.  The theUrlReturnTo length 
 * 								is limited to 256 bytes.  To continue using the default server value, use the empty
 *                              string.
 * @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 http_buffer_size       Size of memory in bytes to be allocated for preparing 
 *                              HTTP headers and receiving form data from the browser.
 * @param server_header                 Pointer to Server header to be returned in the response header.
 *                                      The default Server header is Allegro-Software-RomPager with the version number.
*ad*/
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[HS_SERVER_NAME_SIZE];
    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;
    WORD32    http_buffer_size;
    char      * server_header;
} HS_SERVER_PARAMETER;



/*ad*
 * The following structure is used to configure secure AWS or HTTP server's parameters
 *
 * @external
 * @category Web_Servers:Advanced_Web_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
 *
*ad*/
typedef struct {
    HS_SERVER_PARAMETER WebServerParams;
    Param_Secure_t      SecurityParams;
} RpHsSecureParams_t;

/*ad*
 * The following structure is used to configure secure AWS or HTTP server's parameters
 * to be used in conjunction with the certificate database.
 *
 * @external
 * @category Web_Servers:Advanced_Web_Server
 * @since 6.3
 *
 * @param WebServerParams       Parameters specific to configuring the web server
 * @param SecurityParams        Parameters specific to setting up ssl
 *
 * @see @link HS_SERVER_PARAMETER
 * @see @link NaSecureParams_t
 *
*ad*/
typedef struct {
    HS_SERVER_PARAMETER WebServerParams;
    NaSecureParams_t    SecurityParams;
} NaRpHsSecureParams_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);

/*ad*
 * 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 Web_Servers:Advanced_Web_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
*ad*/



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

void * RpHSGetServerData(void);

/*ad*
 * User callback function to set security access for the request URL 
 *
 * @external
 * @category Web_Servers:Basic_Web_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
*ad*/
typedef void (* hsFunctionSecurity_t)(unsigned long handle, char * URLp);


/*ad*
 * User callback function to search the request URL
 *
 * @external
 * @category Web_Servers:Basic_Web_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
*ad*/
typedef void (* hsFunctionSearch_t)(unsigned long handle, char * URLp);


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

void NAHttpResetOnDisconnect(unsigned int enable);

void naHSDefaultSetting (HS_SERVER_PARAMETER * server_data);

#ifdef __cplusplus
}
#endif
  
#endif


