Esempio n. 1
0
MODULE add_to_cache (THREAD *thread)
{
    SYMBOL
        *symbol;
    time_t
        current_time;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    if (cache_table
    &&  tcb-> host_name
    &&  tcb-> ip_address)
      {
        symbol = sym_assume_symbol (cache_table, tcb-> host_name,
                                    tcb-> ip_value);
        if (symbol-> data)
            mem_free (symbol-> data);
        symbol-> data = mem_alloc (sizeof (long));
        if (symbol-> data)
          {
            current_time = time (NULL);
            *(long *)symbol-> data =   (long)current_time
                                     + tcb-> cur_request-> ttl;
          }
      }
}
Esempio n. 2
0
static void
context_load (int scope, qbyte bufsize, byte *buffer)
{
    size_t
        block_size;
    qbyte
        portable_size;                  /*  Block size in network order      */
    SYMTAB
        *table;
    SYMBOL
        *symbol;                        /*  Symbol we create in table        */

    table = context_init (scope);       /*  Initialise new symbol table      */
    while (bufsize)                     /*    and fill-up from buffer        */
      {
        symbol = sym_assume_symbol (table, (char *) buffer, NULL);
        bufsize -= (strlen ((char *) buffer) + 1);
        buffer  += (strlen ((char *) buffer) + 1);

        ((byte *) &portable_size) [0] = *buffer++;
        ((byte *) &portable_size) [1] = *buffer++;
        ((byte *) &portable_size) [2] = *buffer++;
        ((byte *) &portable_size) [3] = *buffer++;
        block_size = ntohl (portable_size);

        symbol-> data = mem_descr (buffer, block_size);
        bufsize -= 4;
        bufsize -= block_size;
        buffer  += block_size;
      }
}
Esempio n. 3
0
SYMTAB *
env2symb (void)
{
    SYMTAB
        *symtab;                        /*  Allocated symbol table           */
    char
        *next_entry,                    /*  Environment variable + value     */
        *equals;                        /*  Position of '=' in string        */
    int
        string_nbr;                     /*  Index into string table          */

    /*  We create the table here, instead of passing through strt2symb(),
        since we have to ensure that environment variable names are stored
        in uppercase.  Some systems (NT) return mixed-case names.            */

    symtab = sym_create_table ();
    if (symtab)
      {
        for (string_nbr = 0; environ [string_nbr]; string_nbr++)
          {
            next_entry = mem_strdup (environ [string_nbr]);
            equals = strchr (next_entry, '=');
            if (equals)
              {
                *equals = '\0';         /*  Cut into two strings             */
                strupc (next_entry);
                sym_assume_symbol (symtab, next_entry, equals + 1);
              }
            mem_free (next_entry);
          }
      }
    return (symtab);
}
Esempio n. 4
0
MODULE add_bad_result_to_cache (THREAD *thread)
{
    SYMBOL
        *symbol;
    time_t
        current_time;
    char
        *ip_value;

    tcb = thread-> tcb;                 /*  Point to thread's context        */
    if (cache_table
    &&  (   tcb-> host_name
         || tcb-> ip_value
         || tcb-> ip_address))
      {
        if (tcb-> host_name)
            symbol = sym_assume_symbol (cache_table, tcb-> host_name, NULL);
        else
        if (tcb-> ip_value)
            symbol = sym_assume_symbol (cache_table, tcb-> ip_value,
                                                     tcb-> ip_value);
        else
          {
            inaddr.s_addr = tcb-> ip_address;
            ip_value = inet_ntoa (inaddr);
            symbol = sym_assume_symbol (cache_table, ip_value, ip_value);
          }

        if (symbol-> data)
            mem_free (symbol-> data);
        symbol-> data = mem_alloc (sizeof (long));
        if (symbol-> data)
          {
            current_time = time (NULL);
            *(long *) symbol-> data = (long) current_time + BAD_RESULT_TTL;
          }
      }
}
Esempio n. 5
0
MODULE open_listen_socket (THREAD *thread)
{
    static char
        port [10];
    Bool
        next_port = FALSE;
    int
        index = 0;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    tcb-> transfer_type = 0;
    if (tcb-> data_port > ip_portbase)
        tcb-> data_port -= ip_portbase;

    sprintf (port, "%d", tcb-> data_port);
    if (sym_lookup_symbol (pasv_port, port) == NULL)
      {
        next_port = FALSE;
        tcb-> handle = passive_TCP (port, 5);
        index++;
      }
    else
        next_port = TRUE;

    while (index < 200
    &&    (next_port == TRUE || connect_error () == IP_BINDERROR))
      {
        tcb-> data_port++;              /*  Port in use - try next one       */
        sprintf (port, "%d", tcb-> data_port);
        if (sym_lookup_symbol (pasv_port, port) == NULL)
          {
            next_port = FALSE;
            tcb-> handle = passive_TCP (port, 5);
            index++;
          }
        else
            next_port = TRUE;
      }

    if (tcb-> handle == INVALID_SOCKET || index >= 200)
        tcb-> handle = 0;               /*  0 means 'not open'               */
    else
      {
        tcb-> data_port += ip_portbase;
        sym_assume_symbol (pasv_port, port, port);
      }
    the_next_event  = tcb-> handle? ok_event: error_event;
}
Esempio n. 6
0
char *
ini_dyn_default (
    SYMTAB *symtab,
    const char *section,
    const char *keyword,
    const char *default_value)
{
    ASSERT (section);
    if (keyword && *keyword)
        snprintf (ini_keyword, sizeof (ini_keyword), "%s:%s", section, keyword);
    else
        strncpy  (ini_keyword, section, sizeof (ini_keyword));

    strlwc (ini_keyword);
    if (!sym_lookup_symbol (symtab, ini_keyword))
        sym_assume_symbol (symtab, ini_keyword, default_value);
    
    return (sym_get_value (symtab, ini_keyword, default_value));
}
Esempio n. 7
0
void
add_host_line_in_cache (char *line)
{
    char
        **host_list,
        *ip_value;
    SYMBOL
        *symbol;
    int
        index,
        list_size;

    host_list = tok_split (line);
    if (host_list)
      {
        list_size = tok_size (host_list);
        if (list_size >= 2)
          {
            ip_value = host_list [0];
            for (index = 1;
                 index < list_size
                 && *host_list [index] != '#';
                 index++)
              {
                symbol = sym_lookup_symbol (cache_table, host_list [index]);
                if (symbol == NULL)
                  {
                    symbol = sym_assume_symbol (cache_table, host_list [index],
                                                ip_value);
                    if (symbol)
                      {
                        symbol-> data = mem_alloc (sizeof (long));
                        if (symbol-> data)
                            *(long *)symbol-> data = -1;
                      }
                  }
              }
          }
        tok_free (host_list);
      }
}
Esempio n. 8
0
MODULE load_session_context (void)
{
    DESCR
        symbols;                        /*  Symbol descriptor                */

    context_load (SCOPE_GLOBAL, msg_do-> global_size, msg_do-> global_data);
    context_load (SCOPE_LOCAL,  msg_do-> local_size,  msg_do-> local_data);

    /*  Normally if either of these two blocks are not found, we're
     *  starting a new session.  The form symbol table is populated
     *  with all the HTTP environment symbols passed from WTPMAN at
     *  the start of the session.
     */
    if (!context_get (SCOPE_GLOBAL, "_sess", &session, sizeof (session)))
      {
        memset (&session, 0, sizeof (session));
        session.disable_actions = DISABLE_HIDDEN;
      }
    if (!context_getsym (SCOPE_GLOBAL, "_sym", &session.symbols))
      {
        symbols.size = msg_do-> env_size;
        symbols.data = msg_do-> env_data;
        session.symbols = descr2symb (&symbols);
      }
    session.buffer_ = &buffer;
    session.program_callcode = msg_do-> call_result;
    session.back_used = FALSE;
    if (strlen (msg_do-> http_data) == 7
    &&   streq (msg_do-> http_data, "refresh"))
      {
        session.back_used = TRUE;
        msg_do-> http_data [0] = '\0';
      }
    strcpy  (session.program_name, msg_do-> program);
    strncpy ((char *) buffer.data, msg_do-> http_data, BUFFER_MAX);
    buffer.data [BUFFER_MAX] = 0;

    sym_assume_symbol (session.symbols, "uri", msg_do-> http_uri);
}
Esempio n. 9
0
MODULE get_next_request (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */

    if (tcb-> cur_request-> host_name
    && !(   tcb-> main_req_type == REQ_TYPE_IP
         && streq (tcb-> host_name, tcb-> cur_request-> host_name))
       )
        sym_assume_symbol (tcb-> invalid_ns_tab,
                           tcb-> cur_request-> host_name, " ");

    rdns_request_free (tcb-> cur_request);
    tcb-> cur_request = tcb-> stack.next;
    current_id++;
    if (tcb-> cur_request != NULL
    &&  (void *)tcb-> cur_request != (void *)&tcb-> stack)
        the_next_event = ok_event;
    else
    if ((void *)tcb-> cur_request == (void *)&tcb-> stack)
        the_next_event = end_event;
    else
        the_next_event = error_event;
}
Esempio n. 10
0
MODULE load_host_file_in_cache (THREAD *thread)
{
    /*  Load content of host file into cache table.  Skip comment line
     *  beginning with '#' character.  The search key in the cache is the
     *  host name, which is a unique value.
     */

    FILE
        *f_host;
    Bool
        read_line = TRUE;
    char
        **host_list,
        *p_char,
        *ip_value;
    SYMBOL
        *symbol;
    int
        index,
        list_size;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    f_host = file_open (get_host_file (), 'r');
    if (f_host == NULL)
        return;
    read_line = file_read (f_host, buffer);
    while (read_line)
      {
        p_char = strskp (buffer);
        if (*p_char != '#')
          {
            host_list = tok_split (p_char);
            if (host_list)
              {
                list_size = tok_size (host_list);
                if (list_size >= 2)
                  {
                    ip_value = host_list [0];
                    for (index = 1;
                         index < list_size
                      && *host_list [index] != '#';
                         index++)
                      {
                        symbol = sym_assume_symbol (
                                   cache_table, host_list [index], ip_value);
                        if (symbol)
                          {
                            symbol-> data = mem_alloc (sizeof (long));
                            if (symbol-> data)
                            *(long *)symbol-> data = -1;
                          }
                      }
                  }
                tok_free (host_list);
              }
          }
        read_line = file_read (f_host, buffer);
      }
    file_close (f_host);
}
Esempio n. 11
0
SYMTAB *
ini_dyn_load (
    SYMTAB *load_symtab,
    const char *filename)
{
    FILE
        *inifile;
    SYMTAB
        *symtab,                        /*  Symbol table to populate         */
        *envtab;                        /*  Environment, as symbol table     */
    char
        *section = NULL,                /*  Filled as we scan through        */
        *keyword = NULL,                /*    the ini file                   */
        *value   = NULL,
        *fromptr,
        *toptr,
        *section_end;                   /*  Null byte at end of section      */

    ASSERT (filename);
    inifile = file_locate ("PATH", filename, NULL);

    if (load_symtab)                    /*  Use specified symbol table       */
        symtab = load_symtab;           /*    or create a new one            */
    else {
        symtab = sym_create_table ();
        if (symtab == NULL)
            return (NULL);              /*  Quit if insufficient memory      */
    }
    /*  Store control variables in symbol table                              */
    if (inifile || load_symtab == NULL) {
        sym_assume_symbol (symtab, "filename", filename);
        snprintf (iniline, sizeof (iniline), "%ld",
            timer_to_date (get_file_time (filename)));
        sym_assume_symbol (symtab, "filedate", iniline);
        snprintf (iniline, sizeof (iniline), "%ld",
            timer_to_time (get_file_time (filename)));
        sym_assume_symbol (symtab, "filetime", iniline);
    }
    if (!inifile)
        return (symtab);                /*  File not found; empty table      */

    /*  Now load the ini file, starting from the beginning                   */
    envtab = env2symb ();
    fseek (inifile, 0, SEEK_SET);
    FOREVER
      {
        if (ini_scan_section (inifile, &keyword, &value))
          {
            if (section)
              {
                section_end = strchr (section, '\0');
                ASSERT (section_end);
                xstrcat (section, ":", keyword, NULL);
                value = tok_subst (value, envtab);

                /*  Handle value in quotes                                   */
                if (*value == '"')
                  {
                    /*  Unescape value if necessary                          */
                    if (strchr (value, '\\'))
                      {
                        toptr = value;
                        for (fromptr = value; *fromptr; fromptr++)
                          {
                            if (*fromptr == '\\')
                              {
                                fromptr++;
                                if (*fromptr == 'n')
                                    *toptr++ = '\n';
                                else
                                    *toptr++ = *fromptr;
                              }
                            else
                                *toptr++ = *fromptr;
                          }
                        *toptr = '\0';
                      }
                    strlast (value) = '\0'; 
                    sym_assume_symbol (symtab, section, value + 1);
                  }
                else
                    sym_assume_symbol (symtab, section, value);

                mem_strfree (&value);
                *section_end = '\0';
              }
          }
        else
        if (keyword)                    /*  Found new section                */
          {
            section = keyword;
            sym_assume_symbol (symtab, section, "");
          }
        else
            break;
      }
    file_close (inifile);
    sym_delete_table (envtab);
    sym_sort_table (symtab, NULL);      /*  Sort table by symbol name        */
    return (symtab);
}