| iMatix home page
| << | < | > | >>
SMT Logo SMT
Version 2.81

 

smthttp_init

#include "smtdefn.h"
int smthttp_init (char *p_rootdir,      /*  Document root directory          */
                  char *p_cgidir)       /*  CGI binary directory             */

Synopsis

Initialises the HTTP agent. Returns 0 if initialised okay, -1 if there was an error. The HTTP agent manages a HTTP service on port 80 (+ ip_portbase). Sends errors and information messages to the SMTOPER agent.

Source Code - (smthttp.c)

{
    AGENT  *agent;                      /*  Handle for our agent             */
    THREAD *thread;                     /*  Handle to various threads        */
#   include "smthttp.i"                 /*  Include dialog interpreter       */

    /*                      Method name      Event value     Priority        */
    /*  Shutdown event comes from Kernel                                     */
    method declare (agent, "SHUTDOWN",       shutdown_event, SMT_PRIORITY_MAX);

    /*  Reply events from socket agent                                       */
    method declare (agent, "SOCK_INPUT_OK",  ok_event,            0);
    method declare (agent, "SOCK_OUTPUT_OK", ok_event,            0);
    method declare (agent, "SOCK_READ_OK",   ok_event,            0);
    method declare (agent, "SOCK_WRITE_OK",  ok_event,            0);
    method declare (agent, "SOCK_CLOSED",    sock_closed_event,   0);
    method declare (agent, "SOCK_ERROR",     sock_error_event,    0);
    method declare (agent, "SOCK_TIMEOUT",   sock_timeout_event,  0);

    /*  Reply events from transfer agent                                     */
    method declare (agent, "TRAN_PUTF_OK",   finished_event,      0);
    method declare (agent, "TRAN_CLOSED",    sock_closed_event,   0);
    method declare (agent, "TRAN_ERROR",     sock_error_event,    0);

    /*  Registration events from WSX agents                                  */
    method declare (agent, "WSX_INSTALL",    wsx_install_event,   0);
    method declare (agent, "WSX_CANCEL",     wsx_cancel_event,    0);

    /*  Reply events from WSX agents                                         */
    method declare (agent, "WSX_OK",         wsx_ok_event,        0);
    method declare (agent, "WSX_MULTIPART",  wsx_multi_event,     0);
    method declare (agent, "WSX_BIN",        wsx_binary_event,    0);
    method declare (agent, "WSX_MBIN",       wsx_multibin_event,  0);
    method declare (agent, "WSX_ERROR",      wsx_error_event,     0);
    method declare (agent, "WSX_REDIRECT",   wsx_redirect_event,  0);
    method declare (agent, "WSX_RESTART",    wsx_restart_event,   0);
    method declare (agent, "WSX_KILL",       wsx_kill_event,      0);

    /*  Reply events from timer agent                                        */
    method declare (agent, "TIME_ALARM",     timer_event, SMT_PRIORITY_LOW);

    /*  Private methods used to pass initial thread events                   */
    method declare (agent, "_MASTER",        master_event,        0);
    method declare (agent, "_CLIENT",        client_event,        0);

    /*  Private methods used between threads                                 */
    method declare (agent, "_CANCEL",        cancel_event,        0);
    method declare (agent, "_RESTART",       restart_event,       0);

    /*  Reply events from SSL agents                                         */
    declare_ssl_accepted     (new_ssl_client_event, 0);
    declare_ssl_read_ok      (ok_event,             0);
    declare_ssl_open_ok      (ssl_open_event,       0);
    declare_ssl_error        (ssl_error_event,      0);
    declare_ssl_write_ok     (ok_event,             0);
    declare_ssl_put_slice_ok (finished_event,       0);

    /*  Ensure that operator console is running, else start it up            */
    smtoper init ();
    if ((thread = thread lookup (SMT_OPERATOR, "")) != NULL)
        operq = thread-> queue-> qid;
    else
        return (-1);

    /*  Ensure that socket i/o agent is running, else start it up            */
    smtsock init ();
    if ((thread = thread lookup (SMT_SOCKET, "")) != NULL)
        sockq = thread-> queue-> qid;
    else
        return (-1);

    /*  Check whether SSL agent is running                                   */
    if ((thread = thread lookup ("SMTSSL", "main")) != NULL)
      {
        sslq = thread-> queue-> qid;
        server_secure = TRUE;
      }
    else
        server_secure = FALSE;

    /*  Ensure that timer agent is running, else start it up                 */
    smttime init ();
    if ((thread = thread lookup (SMT_TIMER, "")) != NULL)
        timeq = thread-> queue-> qid;
    else
        return (-1);

    /*  Ensure that transfer agent is running, else start it up              */
    smttran init ();
    if ((thread = thread lookup (SMT_TRANSFER, "")) != NULL)
        tranq = thread-> queue-> qid;
    else
        return (-1);

    /*  Create initial thread to manage master port                          */
    if ((thread = thread create (AGENT_NAME, "main")) != NULL)
      {
        SEND (&thread-> queue-> qid, "_MASTER", "");
        ((TCB *) thread-> tcb)-> thread_type = master_event;
        ((TCB *) thread-> tcb)-> handle      = 0;
      }
    else
        return (-1);

    this_agent = agent;                 /*  Handle to ourselves              */

    /*  Use standard port number.  Caller can set ip_portbase if wanted      */
    /*  to place the port into a specific area.                              */
    master_port = SMT_HTTP_PORT;

    http_init ();                       /*  Initialise HTTP library          */

    /*  Get root and cgi directories passed to smthttp.c                     */
    rootdir = p_rootdir;
    cgidir  = p_cgidir;

    /*  Get local host addresses table, which may be NULL                    */
    hostaddrs = get_hostaddrs ();

    /*  These strings are allocated if not null - initialise now             */
    request_log = NULL;
    header_log  = NULL;

    /*  Signal okay to caller that we initialised okay                       */
    return (0);
}

| << | < | > | >> iMatix Copyright © 1996-99 iMatix Corporation