Beispiel #1
0
static char *
get_map_value (
    char *map_file,                     /*  Name of map file                 */
    char *request_point                 /*  Point coordinates                */
)
{
    static char
    buffer      [LINE_MAX],         /*  Buffer for map file line         */
                url         [LINE_MAX],         /*  Buffer to store URL              */
                default_url [LINE_MAX];         /*  Default URL value for the map    */
    char
    *full_uri;                      /*  Full URI                         */
    FILE
    *file;
    int
    point_x = 0,                    /*  Used only for sscanf             */
    point_y = 0;

    ASSERT (map_file);

    strclr (url);
    strclr (default_url);
    file = file_open (map_file, 'r');
    if (file)
    {
        /*  Get the coodinates of point                                      */
        if (request_point)
            sscanf (request_point, "%d,%d", &point_x, &point_y);

        /*  Note: The first line of map sets the value url_def               */
        while (file_readn (file, buffer, LINE_MAX))
        {
            /*  Ignore comments and blank lines                              */
            if ((buffer [0] == '#') || strnull (buffer))
                continue;
            point_in_map_element (buffer, url, point_x, point_y, default_url);
            if (strused (url))
                break;
        }
        /*  If not found a URL, set the return with the default value        */
        if (strnull (url))
            strcpy (url, default_url);

        file_close (file);
    }

    /*  Return final URL string, or NULL if we did not find anything         */
    if (strused (url))
    {
        full_uri = build_full_url (url, map_file);
        strcpy (url, full_uri);
        mem_free (full_uri);
        return (url);
    }
    else
        return (NULL);
}
Beispiel #2
0
MYSQLHANDLE *
alloc_mysql_handle    (char *table_name, void *context)
{
    MYSQLHANDLE
        *handle = NULL;                 /* mysql Context handle                */
    MYSQL_CONNECT_CTX
        *temp_ctx,
        *ctx;
    if (context)
      {
        ctx = (MYSQL_CONNECT_CTX *)context;
        temp_ctx = dbio_mysql_connect (ctx-> dbname, ctx-> user, ctx->password,
                                       ctx->host);
        if (temp_ctx)
          {
            handle = mem_alloc (sizeof (MYSQLHANDLE));
            if (handle)
              {
                memset (handle, 0, sizeof (MYSQLHANDLE));
                handle-> db_handle = temp_ctx-> db_handle;
                if (table_name && strused (table_name))
                    handle-> table_name = mem_strdup (table_name);
                mem_free (temp_ctx);
              }
            else
              {
                coprintf ("DBIO MYSQL: Error in alloc_mysql_handle (Memory Allocation)");
                dbio_mysql_disconnect (temp_ctx);
              }
          }
      }
    return (handle);
}
Beispiel #3
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 #4
0
void
send_body (sock_t socket_handle, char *body)
{
    char
        buffer [BUFFER_SIZE + 1],
        *p_buffer,
        *end_line;

    p_buffer = body;
    do {
        end_line = strstr (p_buffer, "\r\n");
        if (end_line)
          {
            if ((end_line - p_buffer) > 512)
              {
                strncpy (buffer, p_buffer, 510);
                strcpy (&buffer [510], "\r\n");
                send_body_data (socket_handle, buffer);
                p_buffer += 510;
              }
            else
              {
                 *end_line = '\0';
                 send_body_data (socket_handle, p_buffer);
                 send_body_data (socket_handle, "\r\n");
                 p_buffer = end_line + 2;
              }
          }
        else
        if (         p_buffer
        &&  strused (p_buffer))
          {
            while (strlen (p_buffer) > 510)
              {
                strncpy (buffer, p_buffer, 510);
                strcpy (&buffer [510], "\r\n");
                send_body_data (socket_handle, buffer);
                p_buffer += 510;
              }
            if (         p_buffer
            &&  strused (p_buffer))
                send_body_data (socket_handle, p_buffer);
          }
      } while (end_line);
}
Beispiel #5
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 #6
0
void *
dbio_mysql_connect (char *name, char *user, char *pwd, char *host)
{
    MYSQL_CONNECT_CTX
        *handle = NULL;
    MYSQL
        *mysql;


    mysql = mysql_connect (NULL, host, user, pwd);
    if (mysql)
      {
        if (mysql_select_db (mysql, name) != 0)
          {
            mysql_close (mysql);
            mysql = NULL;
          }
      }
    if (mysql)
      {
        handle = mem_alloc (sizeof (MYSQL_CONNECT_CTX));
        memset (handle, 0,  sizeof (MYSQL_CONNECT_CTX));
        handle-> db_handle = mysql;
        handle-> port      = MYSQL_PORT;
        strcpy (handle-> dbname, name);
        if (user && strused (user))
            strcpy (handle-> user,     user);
        if (pwd  && strused (pwd))
            strcpy (handle-> password, pwd);
        if (host && strused (host))
            strcpy (handle-> host,     host);
      }
    else
        coprintf ("Error on Connect to %s in MySql", name);
    
    return ((void *)handle);
}
Beispiel #7
0
/* concatenates msg_body to buffer, single dot characters (.) at beginning of
   a line are duplicated and line terminators are all set to "\r\n".         */
static
void append_msg_body (char *buffer, char *body)
{
    char
        *p_end_line;

    ASSERT (buffer);
    ASSERT (body);

    buffer += strlen (buffer);          /*  Point to end of string.  */
    if (*body == '\n')
      {
        *buffer++ = '\r';
        *buffer++ = '\n';
        body++;
      }
    while (strused (body))
      {
        /* is line starting with a single DOT character ? */
        if (*body == '.')
            /* --> an extra dot is appended to buffer */
            *buffer++ = '.';

        /* line can now be appended to buffer */
        p_end_line = strchr (body, '\n');
        if (p_end_line)                 /* Was line terminator found?        */
          {
            memcpy (buffer, body, p_end_line - body);
            buffer += p_end_line - body;
            if (* (p_end_line - 1) != '\r')
                *buffer++ = '\r';
            *buffer++ = '\n';
            body = p_end_line + 1;      /* sets body to next line          */
          }
        else
          {
            strcpy (buffer, body);
            buffer += strlen (body);
            body   += strlen (body);
          }
      }
    *buffer = '\0';      /*  Add final string terminator  */
}