/******************************************************************************* * * Copyright (c) 2000, Tortuga Technologies Pty Ltd. All rights reserved. * * This is unpublished proprietary source code of Tortuga Technologies. * The copyright notice above does not evidence any actual or intended * publication of such source code. * ******************************************************************************* * * Filename: $Id: injun.h,v 1.1 2002/04/22 10:10:10 jill Exp $ * * Description: Contains the interface definitions to the application server. * * History: * -------- * $Log: injun.h,v $ * Revision 1.1 2002/04/22 10:10:10 jill * Initial import * * Revision 1.1.1.1 2000/02/18 06:41:34 graham * initial import * ******************************************************************************/ #ifndef _INJUN_H #define _INJUN_H /* standard includes */ #include "machdeps.h" /* defines any machine dependencies */ #include #include #include #include /****************************************************************************** * * definitions * ******************************************************************************/ #define OK 0 #define FAIL -1 #define ZERO 0 #ifndef INFTIM #define INFTIM -1 /* poll() infinity */ #endif #define BIGBUF (BUFSIZ * 2) /* some utility buffer sizes */ #define MEDBUF (BUFSIZ * 1) #define SMLBUF (BUFSIZ / 2) #define TNYBUF (BUFSIZ / 4) /****************************************************************************** * * defines the page_type parameter for injun_add_page() * * PT_FUNCTION - adding a function to dynamically serve the page * PT_STATIC - adding a statically defined page * PT_DYNAMIC - adding a dynamically allocated page * ******************************************************************************/ #define PT_FUNCTION 0 #define PT_STATIC 1 #define PT_DYNAMIC 2 /****************************************************************************** * * defines the fdtype parameter for routine injun_add_handler() * * FD_SOCK - file descriptor we're handling is a socket * FD_FILE - file descriptor is a file * ******************************************************************************/ #define FD_SOCK 0 #define FD_FILE 1 #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * * the following structures define the arguments that are passed to the * routines (socket handlers) that process the incoming requests. * ******************************************************************************/ struct sock_args_s { int connection; /* file descriptor to read/write on */ void *tree; /* web tree to search */ void *userData; /* user data relevant to this request */ struct sockaddr_in addr; /* incoming address structure */ int addr_len; /* length of incoming address structure */ }; struct file_args_s { int bytes; /* file descriptor to read/write on */ void *buffer; /* web tree to search */ void *userData; /* user data relevant to this request */ }; struct thread_args_s { /* master structure that is passed */ int fdtype; union _u_args { struct file_args_s f_args; struct sock_args_s s_args; } u; }; /****************************************************************************** * * the following structures define the arguments that are passed to the * routines (web page handlers) that serve the web pages. * ******************************************************************************/ struct argv_s { /* variable length args for the web page */ char *attr; /* routines */ char *value; }; struct request_args_s { int argc; struct argv_s argv[1]; }; struct webcb_args_s { int fd; /* socket to write page on */ char *buffer; /* full request as read in from browser */ int buffer_len; char *request; /* request (string) with parameters */ char *index; /* web page name or index (string) */ char *ip; /* incoming ip address in x.x.x.x format */ int port; /* incoming port number */ char *hname; /* incoming resolved domain name */ struct request_args_s *args; /* argument list array */ void *tree; void *userData; }; /****************************************************************************** * * the following structures define the web page handler (callback) function * and the actual web page itself. * ******************************************************************************/ struct _web_page; typedef void (*callback_t)( struct _web_page *page, struct webcb_args_s *args ); typedef struct _web_page { char *page_index; /* page ie. "/injun/index.html" */ char *page_mime_type; /* mime type ie. "text/html" */ callback_t page_handler; /* callback (maybe NULL) */ char *template_data; /* static page data */ int template_data_len; /* length of static page data */ char *page_data; /* dynamic page data (allocated) */ int page_data_len; /* length of dynamic data */ int page_hits; /* number of hits accumulated */ } web_page_t; /****************************************************************************** * * data which has been declared globally here can be used by the modules. * ******************************************************************************/ extern char pname[SMLBUF]; /* name of this injun */ extern char version[SMLBUF]; /* version of the injun running */ extern int tcp_port; /* configured port */ extern int tcp_outstanding_requests; /* configured requests */ extern int default_socket; /* socket configured by injun */ extern void *default_tree; /* tree configured by injun */ extern void *addr_cache; /* address to name cache */ extern pthread_t pmain; /* main thread id */ extern boolean_t serving_the_public; /* are we running ? */ extern boolean_t initialize_tree; /* do we configure a tree ? */ extern time_t up; /* uptime of this injun */ extern boolean_t safety_mode; /* is the admini module loaded */ extern boolean_t resolve_addresses; /* should we resolve addresses */ extern boolean_t use_cache; /* and use a cache */ /****************************************************************************** * * Prototypes * ******************************************************************************/ /******************************************************************************* * * Unit: injun_add_header() * * Description: Adds an html header onto an html page * * Notes: the memory returned must be free'd by the caller * this will not work with framesets * * Synopsis: char *body = "

Hello World !

\n"; * char *page = NULL; * * int status = injun_add_header( body, * "Page Title", * B_TRUE, * "stylesheet.css", * NULL, * &page ); * * if ( status == FAIL ) * ... * free( page ); * * Parameters: page_in - address of page on which to add header * title - title to add into the header * cachable - B_TRUE if this page may be cached * external_stylesheet - stylesheet url (can be null) * internal_style - an internal style (can be null) * page_out - page including new header * * Returns: OK - header added and page returned * FAIL - out of memory * ******************************************************************************/ int injun_add_header( char *page_in, char *title, boolean_t cachable, char *external_stylesheet, char *internal_style, char **page_out ); /******************************************************************************* * * Unit: injun_add_footer() * * Description: Adds an html footer onto an html page * * Notes: the memory returned must be free'd by the caller * this will not work with framesets * * Synopsis: char *body = "

Hello World !

\n"; * char *page = NULL; * * int status = injun_add_footer( body, &page ); * * if ( status == FAIL ) * ... * free( page ); * * Parameters: page_in - address of page on which to add footer * page_out - page including new footer * * Returns: OK - footer added and page returned * FAIL - out of memory * ******************************************************************************/ int injun_add_footer( char *page_in, char **page_out ); /******************************************************************************* * * Unit: injun_add_page(() * * Description: Adds the page to the default web tree hierarchy * * Notes: * * Parameters: index - index/name of page ie, "/injun/index.html" * mime_type - type of page "text/html" * length - size of page (in bytes) * page_data - address of start of data * page_type - PT_STATIC (static web page, not malloc'd) * PT_DYNAMIC (web page allocated by malloc) * PT_FUNCTION (web page is generated by handler) * handler - callback routine to serve the page (can be NULL) * * Globals: default_tree - the default web tree * * Returns: OK - web page added to tree * FAIL - failed to add page to tree * ******************************************************************************/ int injun_add_page( char *index, char *type, int length, char *page_data, int page_type, void *handler ); /******************************************************************************* * * Unit: injun_remove_page() * * Description: removes a page from the default tree and deletes it * * Notes: this routine will free any dynamic memory allocated * * Parameters: index - index/name of page ( eg, "/example/example.html" ) * * Globals: default_tree - the default web tree * * Returns: OK - page removed * FAIL - couldn't find page in tree * ******************************************************************************/ int injun_remove_page( char *index ); /****************************************************************************** * * Unit: injun_add_handler() * * Description: Adds a socket, web tree and search callback to Injun * * Notes: This routine adds the socket into the poll() loop of the * injun server. Once activity is detected the callback is * invoked with the tree and userData parameters as arguments. * * Parameters: fd - socket to add into pool() loop * fdtype - FD_SOCK - descriptor is a socket * FD_FILE - descriptor is a file * callback - function to search tree for requested web page * tree - tree to search for web page * userData - userData to pass to callback * * Returns: B_TRUE - socket and data added successfully * B_FALSE - poll() structure is full * ******************************************************************************/ int injun_add_handler( int fd, int fdtype, void *callback, void *tree, void *userData ); /****************************************************************************** * * Unit: injun_remove_handler() * * Description: Removes a socket, web tree and search callback from Injun * * Notes: This routine removes the socket from the poll() loop of the * injun server. It matches on the file descriptor only (this * should be unique!) * * Parameters: fd - descriptor to remove from pool() loop * cb - not used * tree - not used * userData - not used * * Returns: B_TRUE - socket and data removed successfully * B_FALSE - couldn't find the structures to remove ! * ******************************************************************************/ int injun_remove_handler( int fd, void *cb, void *tree, void *userData ); /******************************************************************************* * * Unit: injun_add_timeout() * * Description: Adds in a callback procedure and user data that will * be invoked after the specified number of milliseconds. * * Notes: the timeout is removed from the queue before execution. * the routine is defined as void timeout( void *userData ); * * Parameters: msec - number of milliseconds after which to invoke the callback * callback - function to call * userData - arguments to give to the callback function * * Returns: OK - callback has been queued * FAIL - failed to add callback * ******************************************************************************/ int injun_add_timeout( unsigned long msec, void *callback, void *userData ); /******************************************************************************* * * Unit: injun_remove_timeout() * * Description: Removes a callback from the queue. * * Notes: this routine failing does not indicate an error, eg, the timeout * may have been executed and removed from the queue. * * Parameters: callback - function to remove (mandatory) * userData - arguments (mandatory) * tim - scheduled time of execution (may be NULL) * * Returns: OK - callback has been removed * FAIL - failed to remove callback * ******************************************************************************/ int injun_remove_timeout( void *callback, void *userData, struct timeval *tim ); /******************************************************************************* * * Unit: injun_register_application() * * Description: Used to register an application with injun for integration * into the injun module environment * * Notes: This routine should be called by the initialisation routine * * Parameters: name -- name of application ( eg. "upsd" ) * home -- home page url ( eg. "/upsd/index.html" ) * desc -- description ( eg. "ups monitoring daemon" ) * * Returns: OK -- Application was registered * FAIL -- Invalid registration * ******************************************************************************/ int injun_register_application( char *name, char *home, char *desc ); /******************************************************************************* * * Unit: injun_deregister_application() * * Description: Used to un-register an application from injun * * Notes: This routine should be called by the deletion routine * * Parameters: name -- name of application ( eg. "upsd" ) * * Returns: OK -- Application was unregistered * FAIL -- Invalid registration * ******************************************************************************/ int injun_deregister_application( char *name ); /******************************************************************************* * * Unit: injun_serve_header() * * Description: routine to serve an http header * * Parameters: fd - socket to write (serve) on * type - mime content (eg. "text/html") * length - content length (can be null) * * Returns: None * ******************************************************************************/ void injun_serve_header( int fd, char *type, int length ); /******************************************************************************* * * Unit: injun_default_page_handler() * * Description: default routine to serve the simple web page object * * Parameters: page - web page object reference * args - arguments that brought us here (see below) * * struct webcb_args_s { * int fd; - socket to write page on * char *buffer; - full request as read in from browser * int buffer_len; * char *request; - request with parameters * char *index; - web page name (index) * struct request_args_s *args; - argument list array * void *tree; * void *userData; * }; * * Returns: None * ******************************************************************************/ void injun_default_page_handler( web_page_t *page, struct webcb_args_s *args ); #ifdef __cplusplus } #endif #endif /* _INJUN_EXPORT_H */