Beispiel #1
0
MODULE get_user_command_input (THREAD *thread)
{
    static struct {
        char   *name;
        event_t event;
    } keywords [] = {
        { "LIST",    list_event     },
        { "STATUS",  status_event   },
        { "START",   start_event    },
        { "PAUSE",   pause_event    },
        { "STOP",    stop_event     },
        { "HALT",    halt_event     },
        { "EXIT",    exit_event     },
        { "QUIT",    exit_event     },
        { "HELP",    help_event     },
        { "VERSION", version_event  },
        { "REFRESH", refresh_event  },
        {  NULL,     0              }
    };
    int
        keyword_nbr;

    /*  If we got a command from the user, use it, else prompt               */
    if (command && strused (command))
      {
        strncpy (input_line, command, LINE_MAX);
        input_line [LINE_MAX] = '\0';   /*  Ensure delimited, if looong      */
        command = "exit";               /*  Next time treat as Exit          */
      }
    else
      {
        /*  Show syscli prompt and wait for user command                     */
        printf ("syscli> ");
        fflush (stdout);
        if (fgets (input_line, LINE_MAX, stdin) == NULL)
            strclr (input_line);        /*  Treat EOF as empty               */
      }
    if (token_list)
        tok_free (token_list);
    token_list = tok_split (input_line);

    /*  Get event corresponding to user command                              */
    if (token_list [0] && *token_list [0])
      {
        the_next_event = error_event;
        strupc (token_list [0]);
        for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++)
            if (streq (token_list [0], keywords [keyword_nbr].name))
              {
                the_next_event = keywords [keyword_nbr].event;
                break;
              }
        /*  Specific handling for stop command without arguments             */
        if (the_next_event == stop_event && token_list [1] == NULL)
            the_next_event = stop_all_event;
      }
    else
        the_next_event = empty_event;
}
Beispiel #2
0
MODULE get_user_command_input (THREAD *thread)
{
    static char
        input_line [LINE_MAX + 1];
    static struct {
        char   *name;
        event_t event;
    } keywords [] = {
        { "LIST",    list_event     },
        { "START",   start_event    },
        { "STOP",    stop_event     },
        { "STATUS",  status_event   },
        { "HALT",    halt_event     },
        { "EXIT",    exit_event     },
        { "QUIT",    exit_event     },
        { "HELP",    help_event     },
        { "VERSION", version_event  },
        {  NULL,     0              }
    };
    int
        keyword_nbr;

    /*  If we got function arguments, use those, else prompt the user        */
    if (args && strused (args))
      {
        strncpy (input_line, args, LINE_MAX);
        input_line [LINE_MAX] = '\0';   /*  Ensure delimited, if looong      */
        args = "exit";                  /*  Next time treat as Exit          */
      }
    else
      {
        /*  Show upmc prompt and wait for user command                       */
        printf ("upmc> ");
        fflush (stdout);
        if (fgets (input_line, LINE_MAX, stdin) == NULL)
            strclr (input_line);        /*  Treat EOF as empty               */
      }
    if (token_list)
        tok_free (token_list);
    token_list = tok_split (input_line);

    /*  Get event corresponding to user command                              */
    if (token_list [0] && *token_list [0])
      {
        the_next_event = error_event;
        strupc (token_list [0]);
        for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++)
            if (streq (token_list [0], keywords [keyword_nbr].name))
              {
                the_next_event = keywords [keyword_nbr].event;
                break;
              }
      }
    else
        the_next_event = empty_event;
}
Beispiel #3
0
MODULE terminate_the_thread (THREAD *thread)
{
    if (upm_socket)
        close_socket (upm_socket);
    if (token_list)
        tok_free (token_list);          /*  Free-up allocated memory         */

    smt_shutdown ();                    /*  End the entire application       */
    the_next_event = terminate_event;
}
Beispiel #4
0
Cookie* cook_parse(char* s,char isSetCookie) {
   Cookie* c = (Cookie*)ecalloc(1,sizeof(Cookie));
   Tokenizer* ctok = tok_createCTok(s,';'); 
   char* curtok;

   while((curtok = tok_next(ctok)) != NULL){
      char* varn = NULL,*varnTrimmed=NULL;
      char* varv = NULL,*varvTrimmed=NULL; 

      if(mxstr_indexOf(curtok,'=') != -1) {
         varn = mxstr_substring(curtok,0,mxstr_indexOf(curtok,'='));
         varv = mxstr_substr(curtok,mxstr_indexOf(curtok,'=')+1);
      } else {
         varn=curtok;
      }

      varnTrimmed = mxstr_trim(varn);
      varvTrimmed = mxstr_trim(varv);

      /* Pick off open and close quotes */

      if(varvTrimmed[0]=='\"' && varvTrimmed[strlen(varvTrimmed)-1]=='\"'){
         char* tmp = varvTrimmed;
         varvTrimmed = mxstr_substring(varvTrimmed,1,strlen(varvTrimmed)-1);
         free(tmp);
      }

      if(!strcasecmp((!isSetCookie?"$path":"path"),varnTrimmed)){
         c->path = varvTrimmed;
      } else if (!strcasecmp((!isSetCookie?"$domain":"domain"),varnTrimmed)){
         c->domain = varvTrimmed;
      } else if (!strcasecmp((!isSetCookie?"$version":"version"),varnTrimmed)){
         c->version = varvTrimmed;
      } else if (isSetCookie && !strcasecmp("max-age",varnTrimmed)){
         c->maxage = varvTrimmed;
      } else if (isSetCookie && !strcasecmp("comment",varnTrimmed)){
         c->comment = varvTrimmed;
      } else if (isSetCookie && !strcasecmp("secure",varnTrimmed)){
         c->secure = '\1';
      } else {
         c->name = estrdup(varnTrimmed);
         c->value = varvTrimmed;
      }
 
      free(varn);
      free(varv);
      free(varnTrimmed);
      free(curtok);
   }

   tok_free(ctok);

   return c;
}
Beispiel #5
0
void tokz_close(Tokenizer *tokz)
{
    while(tokz->filestack_n>0)
        do_tokz_popf(tokz, FALSE);
          
    if(tokz->file!=NULL)
        fclose(tokz->file);
    if(tokz->name!=NULL)
        free(tokz->name);
    tok_free(&(tokz->ungettok));
    
    free(tokz);
}
Beispiel #6
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);
      }
}
Beispiel #7
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);
}
Beispiel #8
0
static void
parse_slot_specifier (THREAD *thread, SPEC *spec)
{
    int
        day,                            /*  Specifier is weekday             */
        time_nbr,                       /*  Index into spec_list             */
        time_from,                      /*  Start and end of range           */
        time_to;                        /*    of minutes for specifier       */
    long
        date,                           /*  Converted date value             */
        time;                           /*  Converted time value             */
    Bool
        use_spec;                       /*  Do we want this specifier?       */
    char
        **spec_list,                    /*  Broken-up specifier list         */
        *time_ptr;                      /*  Delimiter in specifier           */

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

    spec_list = tok_split (spec-> times);
    day = conv_str_day (spec_list [0]);
    if (day != -1)
        use_spec = (day == day_of_week (tcb-> today));
    else
      {
        /*  Try to parse date as YY/MM/DD                                    */
        date = conv_str_date (spec_list [0], 0, DATE_YMD_DELIM, DATE_ORDER_YMD);
        if (date == 0)
          {
            /*  If that fails, try as MM/DD                                  */
            date = conv_str_date
                             (spec_list [0], 0, DATE_MD_DELIM, DATE_ORDER_YMD);
            if (date > 0)               /*  Add in current century/year      */
                date += (tcb-> today % 10000L) * 10000L;
          }
        use_spec = (date == tcb-> today);
      }
    /*  If specification matches today, parse the specifier                  */
    if (use_spec)
      {
        for (time_nbr = 1; spec_list [time_nbr]; time_nbr++)
          {
            /*  We expect either "off" or a time range specification         */
            if (streq (spec_list [time_nbr], "off"))
              {
                day_range_empty (tcb-> range);
                continue;
              }
            /*  Split string at hyphen; if not found, means single minute    */
            time_ptr = strchr (spec_list [time_nbr], '-');
            if (time_ptr)
                *time_ptr++ = '\0';     /*  Split the string into 2 pieces   */
            else                        /*  Or parse the same string twice   */
                time_ptr = spec_list [time_nbr];

            time = conv_str_time (spec_list [time_nbr]);
            if (time <= 0)
                continue;               /*  Invalid or empty time            */
            time_from = time_to_min (time);

            time = conv_str_time (time_ptr);
            if (time <= 0)
                continue;               /*  Invalid or empty time            */
            time_to = time_to_min (time);

            day_slot_set (tcb-> range, time_from, time_to);
          }
      }
    tok_free (spec_list);
}
Beispiel #9
0
void tokz_unget_token(Tokenizer *tokz, Token *tok)
{
    tok_free(&(tokz->ungettok));    
    tokz->ungettok=*tok;
    tok->type=TOK_INVALID;
}
Beispiel #10
0
bool tokz_get_token(Tokenizer *tokz, Token *tok)
{
    int c, c2, e;
    
    if (!(tokz->flags&TOKZ_READ_FROM_BUFFER))
    assert(tokz->file!=NULL);
    
    tok_free(tok);
    
    if(!TOK_IS_INVALID(&(tokz->ungettok))){
        *tok=tokz->ungettok;
        tokz->ungettok.type=TOK_INVALID;
        return TRUE;
    }

    while(1){
    
        e=0;
        
        do{
            c=GETCH();
        }while(c!='\n' && c!=EOF && isspace(c));
    
        tok->line=tokz->line;
    
        switch(c){
        case EOF:
            TOK_SET_OP(tok, OP_EOF);
            return TRUE;
            
        case '\n':
            INC_LINE();
            
            if(tokz->flags&TOKZ_IGNORE_NEXTLINE)
                continue;
            
            TOK_SET_OP(tok, OP_NEXTLINE);
            
            return TRUE;
            
        case '\\':
            do{
                c=GETCH();
                if(c==EOF){
                    TOK_SET_OP(tok, OP_EOF);
                    return FALSE;
                }
                if(!isspace(c) && e==0){
                    e=E_TOKZ_EOL_EXPECTED;
                    tokz_warn_error(tokz, tokz->line, e);
                    if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
                        return FALSE;
                }
            }while(c!='\n');
            
            INC_LINE();
            continue;

        case '#':
            if(tokz->flags&TOKZ_READ_COMMENTS){
                e=scan_line_comment(tok, tokz);
                break;
            }else if((e=skip_line_comment(tokz))){
                break;
            }
            
            continue;
            
        case '/':
            c2=GETCH();
            
            if(c2=='='){
                TOK_SET_OP(tok, OP_AS_DIV);
                return TRUE;
            }
            
            if(c2!='*'){
                UNGETCH(c2);
                TOK_SET_OP(tok, OP_DIV);
                return TRUE;
            }
            
            if(tokz->flags&TOKZ_READ_COMMENTS){
                e=scan_c_comment(tok, tokz);
                break;
            }else if((e=skip_c_comment(tokz))){
                break;
            }
            
            continue;
            
        case '\"':
            e=scan_string(tok, tokz, TRUE);
            break;

        case '\'':
            e=scan_char(tok, tokz);
            break;

        default: 
            if(('0'<=c && c<='9') || c=='-' || c=='+'){
                e=scan_number(tok, tokz, c);
                break;
            }

             if(START_IDENT(c))
                e=scan_identifier(tok, tokz, c);
            else
                e=scan_op(tok, tokz, c);
        }
        
        if(!e)
            return TRUE;
        
        tokz_warn_error(tokz, tokz->line, e);
        return FALSE;
    }
}
Beispiel #11
0
static void
point_in_map_element (char *line, char *return_url, int point_x, int point_y,
                      char *default_url)
{
    char
    **tokens,                       /*  Line split into tokens           */
    *map_type,                      /*  Element type name                */
    *map_url,                       /*  Element URL value                */
    *comma;                         /*  Split x,y at comma               */
    FPOINT
    click_point,                    /*  Request point                    */
    shape_points [MAP_MAX_POINTS];  /*  Array of element point           */
    int
    token_nbr,                      /*  Index into token array           */
    nbr_points;                     /*  Number of points in element      */

    /*  Store selected point in image                                        */
    click_point.x = (double) point_x;
    click_point.y = (double) point_y;

    /*  Now parse the map file line into space-delimited tokens              */
    tokens = tok_split (line);

    /*  Ignore anything which is unparsable                                  */
    if (tokens [0] == NULL || tokens [1] == NULL)
    {
        tok_free (tokens);              /*  Release memory                   */
        return;
    }

    /*  First token is image element type; second is the URL                 */
    map_type = strlwc (tokens [0]);
    map_url  = tokens [1];

    /*  Third to n tokens are x,y pairs...                                   */
    token_nbr = 2;
    for (nbr_points = 0; nbr_points < MAP_MAX_POINTS; nbr_points++)
    {
        if (!tokens [token_nbr])
            break;                      /*  Null token => finished           */
        comma = strchr (tokens [token_nbr], ',');
        if (!comma)
            break;                      /*  Syntax error in line => quit     */
        *comma = '\0';                  /*  Else break into separate x & y   */
        shape_points [nbr_points].x = atof (tokens [token_nbr]);
        shape_points [nbr_points].y = atof (comma + 1);
        token_nbr++;                    /*  Bump to next token               */
    }

    /*  Check element type and test the request point                      */
    if (streq (map_type, "poly"))
    {
        if (point_in_poly (&click_point, shape_points, nbr_points))
            strcpy (return_url, map_url);
    }
    else if (streq (map_type, "circle"))
    {
        if (point_in_circle (&click_point, shape_points))
            strcpy (return_url, map_url);
    }
    else if (streq (map_type, "rect"))
    {
        if (point_in_rect (&click_point, shape_points))
            strcpy (return_url, map_url);
    }
    else if (streq (map_type, "point"))
    {
        double dist;
        dist = ((click_point.x - shape_points [0].x)
                *  (click_point.x - shape_points [0].x))
               + ((click_point.y - shape_points [0].y)
                  *  (click_point.y - shape_points [0].y));
        if (dist < 10)
            strcpy (return_url, map_url);
    }
    else if (streq (map_type, "default"))
        strcpy (default_url, map_url);

    tok_free (tokens);                  /*  Release memory                   */
}