示例#1
0
static void _parse_stream(config_t *config, xmlDocPtr doc, xmlNodePtr node)
{
    do 
    {
        if (node == NULL) break;
        if (xmlIsBlankNode(node)) continue;

        if (strcmp(node->name, "metadata") == 0)
            _parse_metadata(NULL, config, doc, node->xmlChildrenNode);
        else if (strcmp(node->name, "input") == 0)
            _parse_input(config, doc, node->xmlChildrenNode);
        else if (strcmp(node->name, "instance") == 0)
            _parse_instance(config, doc, node->xmlChildrenNode);
    } while ((node = node->next));
}
示例#2
0
int main(int ac, char *av[])
{
  /* create .preloader directory */
  char path[500];
  sprintf( path, "%s/.preloader", getenv("HOME") );
  if( mkdir( path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) < 0 )  /* mkdir failed */
    if( errno !=  EEXIST ) {
      fprintf( stderr, "error: failed to create %s!\n", path );
      exit( 0 );
    }


  CTX ctx;
  memset( &ctx, 0, sizeof( ctx ) );

  snprintf( ctx.filename,
            sizeof( ctx.filename ),
            "%s%s", *av[1] == '/' || *av[1] == '.' ? "" : "./",
            av[1] );

  _init_display();
  ctx.state = STATE_PROCESSING_SYMS;

  ctx.db = database_init();
  ctx.hash = database_add_target( ctx.db, ctx.filename ); /* add target to db */

  /* get symbols from target target */
  int fd = open( av[1], O_RDONLY );
  DYNSYM *ds = get_dynsyms( fd, DYNSYM_UNDEFINED_ONLY );
  close( fd );

  /* add symbols to db */
  DYNSYM *p_ds = ds;
  while( p_ds ) {
    ctx.extra = p_ds->name;
    _draw_display( &ctx );
    database_add_symbol( ctx.db, p_ds->name );
    p_ds = p_ds->nxt;
  }

  ctx.state = STATE_PROCESSING_LIBS;

  /* add libs to db */
  LL *lib_sym_info = ll_calloc();

  LIBS *libs = get_libs(ctx.filename);
  LIBS *p_libs = libs;
  while( p_libs ) {
    ctx.extra = p_libs->path;
    _draw_display( &ctx );
    database_add_lib( ctx.db, p_libs->name, p_libs->path );

    p_libs = p_libs->nxt;
  }

  ctx.state = STATE_RESOLVING_SYMBOLS;
  /* match symbols to libs */
  /* immensely inefficient, should call get_dynsyms() ONCE for each lib!! (TODO) */
  p_ds = ds;
  while( p_ds ) {   /* for each symbol in target */
    int found = 0;

    ctx.extra = p_ds->name;
    _draw_display( &ctx );

    LIBS *p_lib = libs;
    while( p_lib && !found ) {  /* search each lib for match */

      int fd_lib = open( p_lib->path, O_RDONLY );
      DYNSYM *ds_lib = get_dynsyms( fd_lib, DYNSYM_DEFINED_ONLY );    /* get symbols from lib */

      DYNSYM *p_ds_lib = ds_lib;
      while( p_ds_lib ) { /* for each symbol in library */
        if( strcmp( p_ds_lib->name, p_ds->name ) == 0 ) {
          database_link_sym_lib( ctx.db, p_ds->name, p_lib->path );
          found = 1;
          break;
        }
        p_ds_lib = p_ds_lib->nxt;   /* move to next symbol in library */
      }
      free_dynsyms( ds_lib );

      close( fd_lib );

      p_lib = p_lib->nxt;   /* move to next library */
    }

    p_ds = p_ds->nxt; /* move to next symbol */
  }

  ll_free( lib_sym_info );

  free_libs( libs );

  free_dynsyms( ds );

  // TODO iter through and free free_dynsyms( ds_lib );

  _populate_symbol_list( ctx.db, &ctx.symbols );

  ctx.state = STATE_NORMAL;
  ctx.running = 1;

  while( ctx.running ) {
    usleep(1000);

    _draw_display( &ctx );
    _parse_input( &ctx );
  }

  _disable_display();

  database_kill( ctx.db );

  /* free symbol list */
  ll_free( ctx.symbols.func );
  ll_free( ctx.symbols.sig );

  return 0;
}