Пример #1
0
struct flowinfo *
new_flowinfo_ipv4_dst(void) {
  struct flowinfo *self;

  self = calloc(1, sizeof(struct flowinfo));
  if (self != NULL) {
    self->ptree = ptree_init(IPV4_DST_BITLEN);
    /* misc is not used */
    self->add_func = add_flow_ipv4_dst;
    self->del_func = del_flow_ipv4_dst;
    self->match_func = match_flow_ipv4_dst;
    self->find_func = find_flow_ipv4_dst;
    self->destroy_func = destroy_flowinfo_ipv4_dst;
  }
  return self;
}
Пример #2
0
struct flowinfo *
new_flowinfo_in_port(void) {
  struct flowinfo *self;

  self = calloc(1, sizeof(struct flowinfo));
  if (self != NULL) {
    self->ptree = ptree_init(32); /* use vector? */
    self->misc = new_flowinfo_vlan_vid();
    self->add_func = add_flow_in_port;
    self->del_func = del_flow_in_port;
    self->match_func = match_flow_in_port;
    self->find_func = find_flow_in_port;
    self->destroy_func = destroy_flowinfo_in_port;
  }
  return self;
}
Пример #3
0
/* Check */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <parse_tree.h>
#include <aurochs.h>

static unsigned char *load_file(char *name, size_t *size)/*{{{*/
{
  size_t m;
  struct stat st;
  unsigned char *data;
  FILE *f;
  unsigned char *retval;

  retval = 0;
  
  if(!stat(name, &st)) {
    m = st.st_size;
    *size = m;
    data = malloc(m);
    if(data) {
      f = fopen(name, "rb");
      if(f) {
        if(1 == fread(data, m, 1, f)) {
          retval = data;
          data = 0;
        }
        fclose(f);
      }
      if(data) free(data);
    }
  }

  return retval;
}/*}}}*/
int main(int argc, char **argv)
{
  unsigned char *peg_data;
  char *peg_fn;
  size_t peg_data_size;
  nog_program_t *pg;
  packer_t pk;
  staloc_t *st;
  int rc;

  rc = 0;

  argv ++; argc --;

  if(!argc) {
    printf("No PEG data\n");
    exit(EXIT_FAILURE);
  }

  peg_fn = *(argv ++); argc --;
  printf("Loading peg_data from file %s\n", peg_fn);

  peg_data = load_file(peg_fn, &peg_data_size);
  if(!peg_data) {
    printf("Can't load peg data.\n");
    exit(EXIT_FAILURE);
  }

  /* Create a stack allocator */

  st = staloc_create(&alloc_stdlib);
  if(!st) {
    printf("Can't create stack allocator.\n");
    exit(EXIT_FAILURE);
  }

  if(pack_init_from_string(&pk, peg_data, peg_data_size)) {
    printf("peg_data[0] = %d\n", peg_data[0]);
    pg = nog_unpack_program(&st->s_alloc, &pk);
    printf("Unpacked to %p\n", pg);
    if(pg) {
      peg_context_t *cx;
      size_t m;
      int i;
      int error_pos;
      char *fn;
      unsigned char *buf;
      int rc;

      rc = 0;

      for(i = 0; i < argc; i ++) {
        fn = argv[i];
        peg_builder_t pb;
        staloc_t *s2;

        s2 = staloc_create(&alloc_stdlib);

        buf = load_file(fn, &m);
        printf("Loaded file %s to %p\n", fn, buf);
        if(buf) {
          ptree_init(&pb, &s2->s_alloc);
          cx = peg_create_context(&alloc_stdlib, pg, &pb, &s2->s_alloc, buf, m);
          printf("Created context %p\n", cx);
          if(cx) {
            tree tr;

            if(nog_execute(cx, pg, &tr)) {
              printf("Parsed as %p.\n", tr);
              ptree_dump_tree(cx->cx_builder_info, stdout, buf, tr, 0);
            } else {
              printf("Doesn't parse.\n");
              error_pos = nog_error_position(cx, pg);
              printf("Error at %d\n", error_pos);
            }

            peg_delete_context(cx);
          }
        }
        staloc_dispose(s2);
        free(buf);
      }
#if 0
        i = foobar_parse_start(cx, - m);
        if(getenv("DUMP_CONTEXT")) dump_context(stdout, cx);

        if(!i) {
          printf("%05d RESULT OK\n", count);
          tree *tr0;

          if(getenv("DUMP_TREE"))
          {
            tr0 = create_node("Root");
            (void) foobar_build_start(cx, &tr0->t_element.t_node, -m);
            reverse_tree(tr0);
            dump_tree(stdout, cx->cx_input, tr0, 0);
          }
        } else {
          error_pos = error_position(cx);
          if(i > 0) {
            printf("%05d RESULT NOPREFIX; ERROR AT %d\n", count, error_pos);
            rc = 1;
          } else {
            printf("%05d RESULT PREFIX %d; ERROR AT %d\n", count, m + i, error_pos);
          }
        }
        fflush(stdout);
        delete_context(cx);
        fclose(f);
      }
#endif

      /* nog_free_program(&st->s_alloc, pg); */
      staloc_dispose(st);
    }
  }