Exemplo n.º 1
0
static void msg_rm( const char* p, int len )
{
  const char* path      = p;
  int         path_len =  param_len( p, len );

  if ( path_len == -1 )
  {
    perror("path_len == -1");
    return;
  }
  if ( path_len >= kPathLengthMax )
  {
    perror("path_len too big");
    return;
  }

  p   += path_len+1;
  len -= path_len+1;

  char path_str[kPathLengthMax];

  strncpy( path_str, path, path_len );
  path_str[path_len] = 0;

  int path_ndx = find_path_ndx( path_str, path_len );
  if (path_ndx == -1)
  {
    printf("FILE DOES NOT EXIST \"%s\"\n", path_str );
    return;
  }

  s_source->paths[path_ndx][0] = 0;
}
Exemplo n.º 2
0
static void msg_command( struct mg_connection* nc, const char* p, int len )
{
  const char* cmd      = p;
  int         cmd_len =  param_len( p, len );

  if ( cmd_len == -1 )
  {
    perror("cmd_len == -1");
    return;
  }

  p   += (cmd_len+1);
  len -= (cmd_len+1);

  if ( strncmp( cmd, "SAVE", cmd_len ) == 0 )
  {
    msg_save( p, len );
    return;
  }

  if ( strncmp( cmd, "RM", cmd_len ) == 0 )
  {
    msg_rm( p, len );
    return;
  }

  if ( strncmp( cmd, "JOIN", cmd_len )  == 0)
  {
    send_sources(nc);
    return;
  }

  if ( strncmp( cmd, "ARCHIVE", cmd_len )  == 0)
  {
    save_archive();
    return;
  }

  if ( strncmp( cmd, "SAVE-ALL", cmd_len ) == 0 )
  {
    save_all(nc);
    return;
  }

  printf("UNKNOWN %s\n",cmd);
}
Exemplo n.º 3
0
static void msg_save( const char* p, int len )
{
  const char* path      = p;
  int         path_len =  param_len( p, len );

  if ( path_len == -1 )
  {
    perror("path_len == -1");
    return;
  }
  if ( path_len >= kPathLengthMax )
  {
    perror("path_len too big");
    return;
  }

  p   += path_len+1;
  len -= path_len+1;

  char path_str[kPathLengthMax];

  strncpy( path_str, path, path_len );
  path_str[path_len] = 0;

  int path_ndx = find_path_ndx( path_str, path_len );
  if (path_ndx == -1)
  {
    path_ndx = s_source->pathCount;
    s_source->pathCount++;
    printf("NEW FILE \"%s\" at %d\n", path_str, path_ndx);
    strncpy( s_source->paths[path_ndx], path_str, path_len );
    s_source->paths[path_ndx][path_len] = 0;
  }

  if (len >= kSourceFileLengthMax)
  {
    perror("source file too big");
    return;
  }

  printf("SAVED %d bytes to \"%s\" (%d)\n", len, path_str, path_ndx);
  memcpy( s_source->text[path_ndx], p, len );
  s_source->text[path_ndx][len] = 0;
}
Exemplo n.º 4
0
/* 
 * Function: pg_exec
 *
 * Wrapper for PQexecParams. Only supports text parameters as binary parameters
 * are not possible in Zabbix item keys.
 *
 * Returns: PGresult
 */
PGresult    *pg_exec(PGconn *conn, const char *command, PGparams params) {
    PGresult *res = NULL;
    int      i = 0, nparams = 0;

    // count parameters
    nparams = param_len(params);

    // log the query
    zabbix_log(LOG_LEVEL_DEBUG, "Executing query with %i parameters: %s", nparams, command);
    for (i = 0; i < nparams; i++)
        zabbix_log(LOG_LEVEL_DEBUG, "  $%i: %s", i, params[i]);

    // execute query with escaped parameters
    res = PQexecParams(conn, command, nparams, NULL, params, NULL, NULL, 0);

    //free up the params array which would have been alloc'ed for this request
    param_free(params);

    return res;
}