Ejemplo n.º 1
0
int main(int argc, char **argv) {

	char *config_xml;

	if (argc != 2) {
		printf("Usage: %s config.xml \n", argv[0]);
		return (EXIT_SUCCESS);
	}


	// GET Ctrl+C signal;
	signal(SIGINT, exit_proc);

	/** Read configure file */

	config_xml = argv[1];
	parse_doc(config_xml);


	/** Initialize NFQUEUE forwarding process, logging files e.t.c */

	if(!nfqp_init() || !glb_init() || !stats_init() /* MYSQL , */){
		exit_proc();
	}




	nfqp_analyzer_function();



	return(EXIT_SUCCESS);

}
Ejemplo n.º 2
0
elemstyle_t *josm_elemstyles_load(const char *name) {
  elemstyle_t *elemstyles = NULL;

  printf("Loading JOSM elemstyles ...\n");

  gchar *filename = find_file(name, NULL, NULL);
  if(!filename) {
    printf("elemstyle file not found\n");
    return NULL;
  }

  /* parse the file and get the DOM */
  xmlDoc *doc = NULL;
  if((doc = xmlReadFile(filename, NULL, 0)) == NULL) {
    xmlErrorPtr errP = xmlGetLastError();
    printf("elemstyles download failed: "
	   "XML error while parsing:\n"
	   "%s\n", errP->message);
  } else {
    printf("ok, parse doc tree\n");
    elemstyles = parse_doc(doc);
  }

  g_free(filename);
  return elemstyles;
}
Ejemplo n.º 3
0
/* read an xml file into our memory structures and update our view,
   dump any old data we have in memory if we can load a new set */
static gboolean
read_xml_file(char *fname)
{
  /* pointer to the new doc */
  xmlDocPtr doc;

  g_return_val_if_fail(fname!=NULL, FALSE);

  /* parse the new file and put the result into newdoc */
  doc = xmlParseFile(fname);

  /* in case something went wrong */
  if(!doc)
    return FALSE;

  if(/* if there is no root element */
     !doc->children ||
     /* if it doesn't have a name */
     !doc->children->name ||
     /* if it isn't a ImageId node */
     g_ascii_strcasecmp((char *)doc->children->name,"ImageId")!=0) {
    xmlFreeDoc(doc);
    return FALSE;
  }

  parse_doc(doc);
  xmlFreeDoc(doc);
  return TRUE;
}
Ejemplo n.º 4
0
/* read an xml file into our memory structures and update our view,
 * dump any old data we have in memory if we can load a new set
 *
 * \param fname is an absolute file name
 *
 */
static gboolean
read_xml_file(gchar *fname)
{
  /* pointer to the new doc */
  xmlDocPtr doc;

  g_return_val_if_fail(fname!=NULL, FALSE);

  doc = xmlParseFile(fname);

  /* in case something went wrong */
  if(!doc)
    return FALSE;

  if(/* if there is no root element */
     !doc->children ||
     /* if it doesn't have a name */
     !doc->children->name ||
     /* if it isn't the good node */
     g_ascii_strcasecmp((gchar *)doc->children->name, "ImageSetRoot")!=0) {
    xmlFreeDoc(doc);
    return FALSE;
  }

  /* parse our document and replace old data */
  parse_doc(doc);

  xmlFreeDoc(doc);

  return TRUE;
}
Ejemplo n.º 5
0
void
RL::Heap::on_document_received (bool error,
				std::string value)
{
  if (error) {

    // FIXME: do something
    std::cout << "XCAP error: " << value << std::endl;
  } else {

    parse_doc (value);
  }
}
Ejemplo n.º 6
0
int read_config(char* path_conf_file, struct option* options)
{
#ifdef HAVE_LIBXML2
  char* path = NULL;
  char* file = NULL;
  int   res;

  /* Check path with '-W' in tiptop options */
  if (path_conf_file != NULL) {
    path = path_conf_file;
  }

  if (!path) {
      /* Check Env. Var.  $TIPTOP */
      path = getenv("TIPTOP");
    }

  if (!path) {
      /* Check Current Folder */
      if (access(config_file, R_OK) == 0) {
        path = ".";
      }
    }

  if (!path) {
    /* Check $HOME */
    path = getenv("HOME");
  }

  if (!path)
    return -1;

  file = malloc(strlen(path) + strlen(config_file) + 2);
  sprintf(file, "%s/%s", path, config_file);

  if (access(file, R_OK) == -1) {
    free(file);
    return -1;
  }

  res = parse_doc(file, options);
  free(file);
  return res;

#else  /* HAVE_LIBXML2 */

  fprintf(stderr, "No xml support, cannot read config file.\n");
  return -1;

#endif  /* !HAVE_LIBXML2 */
}
long time_parser(void (*parse_doc)(char*,int, bool,char*), char* buf, int len, bool doHash, char *charset, int test_count)
{
	struct timeval tv1, tv2;
	struct timezone tz1, tz2;

	long times[test_count];
	long long total=0;
	long max_time=-1;
	long min_time=999999999;
	for (int i=0;i<test_count;i++ ){
		gettimeofday(&tv1, &tz1);
		parse_doc(buf,len, doHash,charset);
		gettimeofday(&tv2, &tz2);
		times[i] = elapsed_usec(&tv1, &tv2);
		total += times[i];
		if (times[i] < min_time) min_time = times[i];
		if (times[i] > max_time) max_time = times[i];
	}
	long avg_time = total/test_count;
	printf("Hash %s, count: %d, avg: %ld, min: %ld, max: %ld\n",
	       (doHash?"true":"false"),
	       test_count, avg_time, min_time, max_time);
	return avg_time;	
}
Ejemplo n.º 8
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    int fd;
    int fsize;
    int index=0;
    int dirsector;
    char utf16[64];
    char orig[64];
    int datasector,datasize;
    int ministreamcutoff;
    int a;
    char *stream=NULL;
    char *token,*token1;

    fd=open(filename,O_RDONLY);
    if (!fd)
    {
	return hash_err;
    }
    fsize=lseek(fd,0,SEEK_END);
    lseek(fd,0,SEEK_SET);
    buf=malloc(fsize+1);
    read(fd,buf,fsize);
    if (memcmp(buf,"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1",8)!=0) 
    {
        //printf("No header signature found!\n");
        free(buf);
        return hash_err;
    }
    index+=24;
    if (memcmp(buf+index,"\x3e\x00",2)!=0)
    {
        //printf("Minor version wrong!\n");
        free(buf);
        return hash_err;
    }
    index+=2;
    if ((memcmp(buf+index,"\x03\x00",2)!=0)&&(memcmp(buf+index,"\x04\x00",2)!=0))
    {
        //printf("Major version wrong!\n");
        free(buf);
        return hash_err;
    }
    else
    {
        if ((short)*(buf+index)==3) sectorsize=512;
        else if ((short)*(buf+index)==4) sectorsize=4096;
        else 
        {
            //printf("Bad sector size!\n");
            free(buf);
            return hash_err;
        }
    }

    index+=22;
    memcpy(&dirsector,(int*)(buf+index),4);
    dirsector+=1;
    dirsector*=sectorsize;
    index+=8;
    memcpy(&ministreamcutoff,(int*)(buf+index),4);
    memcpy(&minifatsector,(int*)(buf+index+4),4);
    difat=(int *)(buf+index+20);


    index=dirsector;
    orig[0]='M';
    while ((orig[0]!=0)&&((strcmp(orig,"Workbook")!=0)||(strcmp(orig,"1Table")!=0)))
    {
        memcpy(utf16,buf+index,64);
        for (a=0;a<64;a+=2) orig[a/2]=utf16[a];
        memcpy(&datasector,buf+index+116,4);
        //printf("%s \n",orig);
        if (strcmp(orig,"Root Entry")==0)
        {
            minisectionstart=datasector;
            memcpy(&minisectionsize,buf+index+120,4);
        }
        if (strcmp(orig,"Workbook")==0)
        {
            memcpy(&datasize,buf+index+120,4);
            stream = read_stream(datasector,datasize);
            if (hash_err == parse_xls(stream,datasize))
            {
        	free(stream);
        	return hash_err;
    	    }
            break;
        }
        if (strcmp(orig,"1Table")==0)
        {
            memcpy(&datasize,buf+index+120,4);
            stream = read_stream(datasector,datasize);
            if (hash_err == parse_doc(stream,datasize))
            {
        	free(stream);
        	return hash_err;
    	    }
            break;
        }
        index+=128;
    }

    if (!stream)
    {
	//printf("No stream found!\n");
	return hash_err;
    }


    close(fd);
    free(stream);
    free(buf);

    (void)hash_add_username(filename);
    (void)hash_add_hash("MS Office document  \0",0);
    (void)hash_add_salt("123");
    (void)hash_add_salt2(" ");

    return hash_ok;
}
Ejemplo n.º 9
0
/** read an xml file into our memory structures and update our view,
 *   dump any old data we have in memory if we can load a new set
 *
 * \return TRUE is the parsing occurs, FALSE instead
 *
 */
static gboolean
read_dataset_directory(gchar *dataset_dir)
{
  GDir *dataset_directory = g_dir_open (dataset_dir, 0, NULL);
  const gchar *fname;
  gchar *absolute_fname;

  if(!dataset_directory)
    return FALSE;

  while ((fname = g_dir_read_name(dataset_directory))) {
    /* skip files without ".xml" */
    if (!g_str_has_suffix (fname,".xml")){
      g_warning("skipping file not in .xml : %s", fname);
      continue;
    }

    absolute_fname = g_strdup_printf("%s/%s", dataset_dir, fname);
    g_warning("Reading dataset file %s", absolute_fname);

    if (!g_file_test ((absolute_fname), G_FILE_TEST_EXISTS))
    {
      g_free(absolute_fname);
      continue;
    }

    /* parse the new file and put the result into newdoc */

    /* pointer to the new doc */
    xmlDocPtr doc;

    doc = xmlParseFile(absolute_fname);

    /* in case something went wrong */
    if(!doc)
    {
      g_free(absolute_fname);
      continue;
    }

    if(/* if there is no root element */
       !doc->children ||
       /* if it doesn't have a name */
       !doc->children->name ||
       /* if it isn't the good node */
       g_ascii_strcasecmp((gchar *)doc->children->name, "ImageSetRoot")!=0) {
      xmlFreeDoc(doc);
      g_free(absolute_fname);
      continue;
    }

    /* parse our document and replace old data */
    g_warning("Parsing dataset : %s \n", absolute_fname);
    g_free(absolute_fname);
    parse_doc(doc);

    xmlFreeDoc(doc);
  }

  g_dir_close(dataset_directory);

  return TRUE;
}