/* C file: C:\netos\src\examples\nahttp\html2C\url.c created
 by NET+Work Web to C Utility on Wednesday, November 29, 2000 11:40:16 */


#include <string.h>
#include "hservapi.h"

/* @! Begin Function Prototypes */
extern void Send_function_4 (unsigned long);
extern void Send_function_0 (unsigned long);
extern void Post_formreply (unsigned long);
extern void Send_function_1 (unsigned long);
extern void Send_function_3 (unsigned long);
/* @! End Function Prototypes   */

typedef void (*SendFn)(unsigned long handle);
typedef void (*HSTypeFnHtml)(unsigned long);
typedef void (*HSTypeFnBinary)(unsigned long, int);

#define	Unprotected	(0x0000)
#define Realm1     (0x0001)
#define Realm2     (Realm1 << 1)
#define Realm3     (Realm2 << 1)
#define Realm4     (Realm3 << 1)
#define Realm5     (Realm4 << 1)
#define Realm6     (Realm5 << 1)
#define Realm7     (Realm6 << 1)
#define Realm8     (Realm7 << 1)

#define AllRealms  (0xFF)

#define REALM1     0
#define REALM2     1
#define REALM3     2
#define REALM4     3
#define REALM5     4
#define REALM6     5
#define REALM7     6
#define REALM8     7

typedef struct {
    char*          url;
    unsigned       html;       /* use HSTypeHtml if 1 */
    SendFn         fun;        /* Send_Function_XXX or Post_XXX */
    void           (*hstype)();/* HSType function to call */
    int            len;        /* size of binary data */
    unsigned short realm;     /* security realm */
} URLTableEntry;

/* Warning: each entry MUST be on the same line */
/* @! Begin of Table for all URLs */
URLTableEntry URLTable[] = {
"/formreply.htm", 1, Send_function_4, (HSTypeFnHtml)HSTypeHtml, 0, Unprotected,
"/netarm1.htm", 1, Send_function_0, (HSTypeFnHtml)HSTypeHtml, 0, Unprotected,
"/formreply", 1, Post_formreply, (HSTypeFnHtml)HSTypeHtml, 0, Unprotected,
"/netarm2.htm", 1, Send_function_1, (HSTypeFnHtml)HSTypeHtml, 0, Realm1,
"/Images/netsilicon.gif", 0, Send_function_3, (HSTypeFnBinary)HSTypeGif, 5132, Unprotected,
"/", 1, Send_function_0, (HSTypeFnHtml)HSTypeHtml, 0, Unprotected,
NULL  /* last entry MUST be NULL */
};
/* @! End of Table for all URLs   */

/* @! Begin search URL function  */
/*
 * AppSearchURL
 *
 * This is an application URL search routine.
 * It will also send data back to the browser.
 *
 */
void AppSearchURL (unsigned long handle, char *URLp)
{
    int i=0;
    while (URLTable[i].url) {
       if (strcmp(URLTable[i].url, URLp) == 0)
       {
           (*URLTable[i].fun) (handle);
           goto lexit;
       }
       i++;
    }
lexit:
    return;
}  /* @! End search URL function    */

/* @! Begin pre-process function */
/*
 * AppPreprocessURL
 *
 * This routine does all the pre-processing for the application's pages.
 *
 */
void AppPreprocessURL (unsigned long handle, char *URLp)
{
    int i=0;
    while ( URLTable[i].url ) {
        if ( strcmp(URLTable[i].url, URLp) == 0)
        {
           HSPageAuthenticate (handle, URLTable[i].realm);
           if (URLTable[i].html)
              (*URLTable[i].hstype) (handle);
           else
              (*URLTable[i].hstype) (handle, URLTable[i].len);
           goto lexit;
        }
        i++;
    }
    /* put your own pre-processing here: */
lexit:
    return;
}  /* @! End pre-process function   */

/* @! Begin pure search URL function  */
/*
 * SearchURL
 *
 * This is an application URL search routine.
 * Returns 1 if the url is found, 0 otherwise.
 *
 */
int SearchURL (unsigned long handle, char *URLp)
{
    int i=0;
    while (URLTable[i].url) {
       if (strcmp(URLTable[i].url, URLp) == 0)
       {
           return 1;
       }
       i++;
    }

    return 0;
}  /* @! End pure search URL function    */

/* @! Begin of Setup Security Table */
/*
 * HSInitSecurityTable
 *
 * This will be called once when the web server starts. 
 * You should setup realm's user/password here.
 *
 */
int HSInitSecurityTable ()
{
/* @! Begin of HSSetRealm calls */
    HSSetRealm (REALM1, "OurRealm", "Netsilicon", "sysadm");
/* @! End   of HSSetRealm calls */
    return 0;
}  /* @! End   of Setup Security Table */

