/*
 *            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: root.c
 *         Version: 1.00
 *   Original Date: 08/23/99	
 *          Author: Paul Jacobson
 *        Language: Ansi C
 * Compile Options: 
 * Compile defines: 
 *       Libraries: 
 *    Link Options: 
 *
 *    Entry Points: applicationStart(), applicationTcpDown()
 *
 * Description.
 * =======================================================================
 * applicationStart() is the entry point for user applications.  This
 * This function will be called after the kernel has started and the
 * TCP/IP stack has loaded.  applicationTcpDown() is called periodically
 * after the kernel has started while the system is waiting for the
 * TCP/IP stack to start.  
 *                                                                        
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 *
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tx_api.h>
#include <http_awsapi.h>
#include <sysAccess.h>
#include "appconf.h"
#include "server.h"     /*  For username/password */




/*
 *
 *  Function: void applicationTcpDown (void)
 *
 *  Description:
 *
 *      This routine will be called by the NET+OS root thread once every 
 *      clock tick while it is waiting for the TCP/IP stack to come up.  
 *      This function can increment a counter everytime it's called to 
 *      keep track of how long we've been waiting for the stack to start.
 *      If we've been waiting too long, then this function can do something
 *      to handle the error.  
 *
 *      This function will not be called once the stack has started.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void applicationTcpDown (void)

{
    static int ticksPassed = 0;

    ticksPassed++;
/*
 * Code to handle error condition if the stack doesn't come up goes here.
 */
}




/*
 *
 *  Function: void applicationStart (void)
 *
 *  Description:
 *
 *      This routine is responsible for starting the user application.  It should 
 *      create any threads or other resources the application needs.
 *
 *      ThreadX, the NET+OS device drivers, and the TCP/IP stack will be running
 *      when this function is called.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void applicationStart (void)
{
    HS_SERVER_PARAMETER appParams;
    int result;

    printf ("Start the AWS Web Server Sample Application.\n");

    naHSDefaultSetting(&appParams);

    appParams.ServerStartDate.tm_mday       = 3;
    appParams.ServerStartDate.tm_mon        = 11;
    appParams.ServerStartDate.tm_year       = 2006;
    appParams.connections                   = 6;
    appParams.persistent_timeout            = (60 * 3);
    appParams.session_timeout               = (60 * 5);
    appParams.http_buffer_size              = 8096;


    /*  Insecure account Netsilicon password sysadm can be used anywhere to access HTTP Realm 1 and FTP */
    NAsetSysAccess (NASYSACC_ADD, APP_USERNAME, APP_PASSWORD, NASYSACC_LEVEL_HTTP_R1 | NASYSACC_LEVEL_RW, NULL);

    /*  Secure account Safe can only be used through the Secure Gateway -- this account's password will never be exposed!   */
    NAsetSysAccess (NASYSACC_ADD, "safe", "netsilicon", NASYSACC_LEVEL_HTTP_R1 | NASYSACC_LEVEL_RW, NULL);

    result = NAHSStartServer(appParams);
    if (result != 0)
    {
        printf("root: NAHSStartServer failure[%d].\n", result);
        return;
    }
}


