Beispiel #1
0
int	main(int argc, char* argv[])
{
	int i;

	if((EzxmlBase = OpenLibrary("ezxml.library", 8)))
	{
		ezxml_t xml;
		char *s;

		if (argc != 2) return Printf("usage: %s xmlfile\n", argv[0]);

		xml = ezxml_parse_file(argv[1]);
		Printf("%s\n", (s = ezxml_toxml(xml)));
		FreeVec(s);
		i = Printf("%s", ezxml_error(xml));

		ezxml_free(xml);

		CloseLibrary(EzxmlBase);
	}
	else
		PutStr("Error: Could not open ezxml.library\n");

	return (i) ? 1 : 0;
}
Beispiel #2
0
int main()
{
	int kanji[200][2];
	int i = 0;

	int8_t test = 8;
	ezxml_t f1 = ezxml_parse_file("4e86.xml"), stroke, point;
	const char *teamname;
 
	for (stroke = ezxml_child(f1, "stroke"); stroke; stroke = stroke->next) {
    	printf("new stroke\n");
    	for (point = ezxml_child(stroke, "point"); point; point = point->next) {
        	kanji[i][0] = atoi(ezxml_attr(point,"x"));
		kanji[i][1] = atoi(ezxml_attr(point,"y"));
		i++; 
                // printf("%i",i);
		// printf("%s \n", ezxml_attr(point,"x"));
    	}
	}
	ezxml_free(f1);
	for(int j = 0;j<50;j++) {
	 	printf("j: %i, x: %i, y: %i\n", j, kanji[j][0], kanji[j][1]);
	} 


	return 0;
}
Beispiel #3
0
Book *book_load_file(const char *path)
{
	Book *book;
	ezxml_t beyonwiz_xml, timerlist_xml, timer_xml;
	Timer *timer;
	int i;
	const char *fname;

	book = (Book *)malloc(sizeof(Book));
 
	book->n_timers = 0;
	book->timers = NULL;

	beyonwiz_xml = ezxml_parse_file(path);
	timerlist_xml = ezxml_child(beyonwiz_xml, "TimerList");
	
	//FIXME check to make sure we are reading a version 5 timerlist.
	
	if(timerlist_xml)
	{
		for(timer_xml = ezxml_child(timerlist_xml, "Timer"); timer_xml; timer_xml = timer_xml->next)
		{
			book->n_timers++;
		}

		printf("number of timers = %d\n", book->n_timers);

		timer = (Timer *)malloc(sizeof(Timer) * book->n_timers);
		book->timers = timer;

		for(i=0,timer_xml = ezxml_child(timerlist_xml, "Timer"); timer_xml; timer_xml = timer_xml->next,i++)
		{
			fname = ezxml_attr(timer_xml, "fname");
			timer->filename = (char *)malloc(strlen(fname) + 1);
			strcpy(timer->filename, fname);
			
			timer->startmjd = atoi(ezxml_attr(timer_xml, "startMjd"));
			timer->nextmjd = atoi(ezxml_attr(timer_xml, "nextMjd"));
			timer->start = atoi(ezxml_attr(timer_xml, "start"));
			timer->duration = atoi(ezxml_attr(timer_xml, "duration"));
			timer->repeat = atoi(ezxml_attr(timer_xml, "repeat"));
			timer->play = atoi(ezxml_attr(timer_xml, "play"));
			timer->lock = atoi(ezxml_attr(timer_xml, "lock"));
			timer->onid = atoi(ezxml_attr(timer_xml, "onId"));
			timer->tsid = atoi(ezxml_attr(timer_xml, "tsId"));
			timer->svcid = atoi(ezxml_attr(timer_xml, "svcId"));

			printf("timer fname = %s, startMjd = %d, start = %d\n", timer->filename, timer->startmjd, timer->start);
			timer++;
		}

	}
	ezxml_free(beyonwiz_xml);
	return book;
}
Beispiel #4
0
/* ------------------------------------------------------------------------- */
Reg_TRegistry* Reg_CreateFromFile(const char* file_name)
{
    Reg_TRegistry *const reg = Mem_Alloc(sizeof(Reg_TRegistry));
    if (!reg)
        return NULL;
    memset(reg, 0, sizeof(*reg));

    reg->m_file_name = strdup(file_name);
    if ((reg->m_root = ezxml_parse_file(file_name)))
        return reg;

    if (!(reg->m_root = ezxml_new("registry")))
    {
        Mem_Free(reg);
        return NULL;
    }

    return reg;
}
/**
 * parse_menu_XML(char *file, app_info_s * app_info)
 * @brief parse the XML menu and confirm tags are present
 * @param file
 * @param app_info
 * @return < 0 for error, 0 for success
 */
static int parse_menu_XML(char *file, appconfig_t * app_info)
{

	ezxml_t app_config = ezxml_parse_file(file);
	ezxml_t app_attributes = NULL;
	int err = 0;

	// Are app attributes defined?
	if ((app_attributes = ezxml_child(app_config, "appAttributes")) == NULL) {
		printf("appAttributes is missing\n");
		return (-1);
	}
	// Parse application attributes from XML
	if (get_app_attributes(app_attributes, app_info) < 0) {
		printf("appAttributes error\n");
		return (-1);
	}

	ezxml_free(app_config);
	return err;
}
Beispiel #6
0
int config_load()
{
	ezxml_t config_xml, root;

	// Clear configuration structure
	memset(import_patch_map, 0, sizeof(import_patch_map));
	memset(import_percussion_map, 0, sizeof(import_percussion_map));

	// Attempt to load configuration XML
	if((config_xml = ezxml_parse_file(CONFIG_XML)) == NULL)
	{
		if(errno == ENOENT || errno == EACCES)
			// Handle file errors
			fprintf(stderr, "Unable to open " CONFIG_XML);
		else
			fprintf(stderr, ezxml_error(config_xml));
		return 0;
	}

	if((root = required_child(config_xml, "patches")) == NULL)
		return 0;

	process_import_map(root, import_patch_map, "patch");

	if((root = required_child(config_xml, "noises")) == NULL)
		return 0;

	process_import_map(root, import_noise_map, "noise");

	if((root = required_child(config_xml, "percussions")) == NULL)
		return 0;

	process_import_map(root, import_percussion_map, "percussion");

	ezxml_free(config_xml);
	return 1;
}
Beispiel #7
0
/* Load a BSDF struct from the given file (free first and keep name) */
SDError
SDloadFile(SDData *sd, const char *fname)
{
	SDError		lastErr;
	ezxml_t		fl, wtl;

	if ((sd == NULL) | (fname == NULL || !*fname))
		return SDEargument;
				/* free old data, keeping name */
	SDfreeBSDF(sd);
				/* parse XML file */
	fl = ezxml_parse_file(fname);
	if (fl == NULL) {
		sprintf(SDerrorDetail, "Cannot open BSDF \"%s\"", fname);
		return SDEfile;
	}
	if (ezxml_error(fl)[0]) {
		sprintf(SDerrorDetail, "BSDF \"%s\" %s", fname, ezxml_error(fl));
		ezxml_free(fl);
		return SDEformat;
	}
	if (strcmp(ezxml_name(fl), "WindowElement")) {
		sprintf(SDerrorDetail,
			"BSDF \"%s\": top level node not 'WindowElement'",
				sd->name);
		ezxml_free(fl);
		return SDEformat;
	}
	wtl = ezxml_child(fl, "FileType");
	if (wtl != NULL && strcmp(ezxml_txt(wtl), "BSDF")) {
		sprintf(SDerrorDetail,
			"XML \"%s\": wrong FileType (must be 'BSDF')",
				sd->name);
		ezxml_free(fl);
		return SDEformat;
	}
	wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
	if (wtl == NULL) {
		sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'",
				sd->name);
		ezxml_free(fl);
		return SDEformat;
	}
				/* load geometry if present */
	lastErr = SDloadGeometry(sd, wtl);
	if (lastErr) {
		ezxml_free(fl);
		return lastErr;
	}
				/* try loading variable resolution data */
	lastErr = SDloadTre(sd, wtl);
				/* check our result */
	if (lastErr == SDEsupport)	/* try matrix BSDF if not tree data */
		lastErr = SDloadMtx(sd, wtl);
		
				/* done with XML file */
	ezxml_free(fl);
	
	if (lastErr) {		/* was there a load error? */
		SDfreeBSDF(sd);
		return lastErr;
	}
				/* remove any insignificant components */
	if (sd->rf != NULL && sd->rf->maxHemi <= .001) {
		SDfreeSpectralDF(sd->rf); sd->rf = NULL;
	}
	if (sd->rb != NULL && sd->rb->maxHemi <= .001) {
		SDfreeSpectralDF(sd->rb); sd->rb = NULL;
	}
	if (sd->tf != NULL && sd->tf->maxHemi <= .001) {
		SDfreeSpectralDF(sd->tf); sd->tf = NULL;
	}
	if (sd->tb != NULL && sd->tb->maxHemi <= .001) {
		SDfreeSpectralDF(sd->tb); sd->tb = NULL;
	}
				/* return success */
	return SDEnone;
}
int main() {

	printf("Reading XML.. .. ..\n");
	ezxml_t f1 = ezxml_parse_file("test.xml"), classification, temp, algo, temp2;
	 
	classification = ezxml_child(f1, "classification");
	temp = ezxml_child(classification, "algorithm");
	algo = ezxml_child(temp, "MultiLayerPerceptron");

	const unsigned int num_input = atoi(ezxml_child(classification, "input")->txt);
	const unsigned int num_output = atoi(ezxml_child(classification, "output")->txt);
	const unsigned int num_layers = atoi(ezxml_child(classification, "numberOfLayers")->txt);
	const unsigned int num_neurons_hidden = atoi(ezxml_child(algo, "hiddenNeurons")->txt);
	const float desired_error = (const float) (atof(ezxml_child(algo, "desiredError")->txt));
	const unsigned int max_epochs = atoi(ezxml_child(algo, "maxEpochs")->txt);
	const unsigned int epochs_between_reports = atoi(ezxml_child(algo, "epochsBetweenReports")->txt);

	fann_type *calc_out;
	
	struct fann *ann;
	struct fann_train_data *data;

	unsigned int i = 0;
	unsigned int decimal_point;

	printf("Creating network.\n");
	ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output);

	data = fann_read_train_from_file(ezxml_child(classification, "datafile")->txt);

	fann_set_activation_steepness_hidden(ann, atoi(ezxml_child(algo, "hiddenActivationSteepness")->txt));
	fann_set_activation_steepness_output(ann, atoi(ezxml_child(algo, "outputActivationSteepness")->txt));

	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
	fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
	
	temp2 = ezxml_child(algo, "trainStopFuction");
	const char *stopFunc = temp2->txt;
	if(stopFunc == "FANN_STOPFUNC_BIT"){
		fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
	} else {
		fann_set_train_stop_function(ann, FANN_STOPFUNC_MSE);
	}
	fann_set_bit_fail_limit(ann, 0.01f);

	fann_set_training_algorithm(ann, FANN_TRAIN_RPROP);

	fann_init_weights(ann, data);
	
	printf("Training network.\n");
	fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error);

	printf("Testing network. %f\n", fann_test_data(ann, data));

	for(i = 0; i < fann_length_train_data(data); i++)
	{
		calc_out = fann_run(ann, data->input[i]);
		printf("Test Results (%f,%f,%f) -> %f, should be %f, difference=%f\n",
			   data->input[i][0], data->input[i][1], data->input[i][2], calc_out[0], data->output[i][0],
			   fann_abs(calc_out[0] - data->output[i][0]));
	}

	printf("Saving network.\n");

	fann_save(ann, "xor_float.net");

	decimal_point = fann_save_to_fixed(ann, "xor_fixed.net");
	fann_save_train_to_fixed(data, "xor_fixed.data", decimal_point);

	printf("Cleaning up.\n");
	fann_destroy_train(data);
	fann_destroy(ann);

	ezxml_free(f1);

	return 0;
}
struct governor_config *
config_init (const char *path)
{
  ezxml_t xml = ezxml_parse_file (path);
  ezxml_t tmp_xml, inner_xml, tmp_xml_limit;
  const char *error_str;
  const char *ptr;

  if (xml == NULL)
    {
      fprintf (stderr, "Error reading config file %s\n", path);
      exit (-1);
    }

  if (strlen (error_str = ezxml_error (xml)))
    {
      fprintf (stderr, "Error in config file (%s): %s\n", path, error_str);
      ezxml_free (xml);
      exit (-1);
    }

  cfg = calloc (1, sizeof (struct governor_config));
  memset (cfg, 0, sizeof (struct governor_config));

  cfg->is_gpl = check_liblve();
  cfg->account_limits = g_hash_table_new_full (g_str_hash, g_str_equal,
					       (GDestroyNotify) free,
					       (GDestroyNotify) free);

  tmp_xml = ezxml_child (xml, "log");
  if (tmp_xml == NULL)
    {
      fprintf (stderr, "No log path\n");
      exit (-1);
    }
  cfg->log = strdup (ezxml_attr (tmp_xml, "file"));
  cfg->log_mode =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "mode")) ==
     NULL) ? ERROR_MODE : mode_type_str_to_enum (ptr);

  tmp_xml = ezxml_child (xml, "intervals");
  if (tmp_xml == NULL)
    {
      fprintf (stderr, "No 'intervals' parameter\n");
      exit (-1);
    }
  cfg->interval_short =
    ((ptr = ezxml_attr (tmp_xml, "short")) == NULL) ? 5 : atoi (ptr);
  cfg->interval_mid =
    ((ptr = ezxml_attr (tmp_xml, "mid")) == NULL) ? 15 : atoi (ptr);
  cfg->interval_long =
    ((ptr = ezxml_attr (tmp_xml, "long")) == NULL) ? 30 : atoi (ptr);

  tmp_xml = ezxml_child (xml, "lve");
  cfg->use_lve = 0;
  cfg->all_lve = 0;
  cfg->separate_lve = 0;
  if(tmp_xml != NULL){
	  if (ezxml_attr (tmp_xml, "use")){
		  if(!strcasecmp(ezxml_attr (tmp_xml, "use"),"On") || 
             !strcasecmp(ezxml_attr (tmp_xml, "use"),"Single")){
			  cfg->use_lve = 1;
		  }
		  if(!strcasecmp(ezxml_attr (tmp_xml, "use"),"AbUsers")){
			  cfg->use_lve = 1;
              cfg->separate_lve = 1;
		  }
		  if(!strcasecmp(ezxml_attr (tmp_xml, "use"),"All")){
			  cfg->use_lve = 1;
			  cfg->all_lve = 1;
			  cfg->separate_lve = 1;
		  }
	  }
  }

  tmp_xml = ezxml_child (xml, "statistic");
  cfg->statistic_mode = 1;
  if( tmp_xml != NULL )
  {
    if( ezxml_attr( tmp_xml, "mode" ) )
    {
      if( !strcasecmp( ezxml_attr( tmp_xml, "mode" ), "Off" ) )
      {
        cfg->statistic_mode = 0;
      }
	}
  }

  tmp_xml = ezxml_child (xml, "debug_user");
  cfg->debug_user = NULL;
    if( tmp_xml != NULL )
    {
      if( ezxml_attr( tmp_xml, "name" ) )
      {
    	  cfg->debug_user = strdup (ezxml_attr (tmp_xml, "name"));
  	}
  }

  tmp_xml = ezxml_child( xml, "logqueries" );
  cfg->logqueries_use = 0;
  if( tmp_xml != NULL )
  {
    if( ezxml_attr( tmp_xml, "use" ) )
    {
      if( !strcasecmp( ezxml_attr( tmp_xml, "use" ), "On" ) )
      {
        cfg->logqueries_use = 1;
      }
      if( !strcasecmp( ezxml_attr( tmp_xml, "use" ), "Before" ) )
      {
        cfg->logqueries_use = 2;
      }
    }
  }

  tmp_xml = ezxml_child (xml, "daemon");
  cfg->daemon_monitor = 1;
  if( tmp_xml != NULL )
  {
    if( ezxml_attr( tmp_xml, "monitor" ) )
    {
      if( !strcasecmp( ezxml_attr( tmp_xml, "monitor" ), "Off" ) )
      {
        cfg->daemon_monitor = 0;
      }
	}
  }

  tmp_xml = ezxml_child (xml, "slow_queries");
  cfg->slow_queries = 0;
  if( tmp_xml != NULL )
  {
    if( ezxml_attr( tmp_xml, "run" ) )
    {
      if( !strcasecmp( ezxml_attr( tmp_xml, "run" ), "On" ) )
      {
        cfg->slow_queries = 1;
      }
    }
    if( ezxml_attr( tmp_xml, "log" ) )
    {
      cfg->slow_queries_log = strdup( ezxml_attr( tmp_xml, "log" ) );
    }
    else
    {
      cfg->slow_queries_log = NULL;
    }
  }

  tmp_xml = ezxml_child( xml, "restrict_mode" );
  cfg->restrict_mode = 1;
  cfg->l_unlimit = parse_period( "60s" );
  if( tmp_xml != NULL )
  {
    if( ezxml_attr( tmp_xml, "use" ) )
    {
      if( !strcasecmp( ezxml_attr( tmp_xml, "use" ), "period" ) )
      {
        cfg->restrict_mode = 0;
      }
    }
    if( ( ptr = ezxml_attr( tmp_xml, "unlimit" ) ) != NULL )
    {
      cfg->l_unlimit = parse_period( ptr );
    }
  }

  cfg->killuser = 0;
  cfg->max_user_connections = 30;

  tmp_xml = ezxml_child (xml, "restrict");
  if (tmp_xml == NULL)
    {
      fprintf (stderr, "No 'restrict' parameter\n");
      exit (-1);
    }
  if (ezxml_attr (tmp_xml, "log"))
    {
      cfg->restrict_log = strdup (ezxml_attr (tmp_xml, "log"));
    }
  else
    {
      cfg->restrict_log = NULL;
    }

  if(ezxml_attr (tmp_xml, "killuser")){
         if(!strcasecmp(ezxml_attr (tmp_xml, "killuser"), "on")){
               cfg->killuser = 1;
         }
    }

  if(ezxml_attr (tmp_xml, "user_max_connections")){
	  cfg->max_user_connections = atoi(ezxml_attr (tmp_xml, "user_max_connections"));
	  if(cfg->max_user_connections<0) cfg->max_user_connections = 30;
  }

  cfg->restrict_format = getRestrictFormat (ezxml_attr (tmp_xml, "format"));

  cfg->level1 =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "level1")) ==
     NULL) ? parse_period ("60s") : parse_period (ptr);
  cfg->level2 =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "level2")) ==
     NULL) ? parse_period ("15m") : parse_period (ptr);
  cfg->level3 =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "level3")) ==
     NULL) ? parse_period ("1h") : parse_period (ptr);
  cfg->level4 =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "level4")) ==
     NULL) ? parse_period ("1d") : parse_period (ptr);
  cfg->timeout =
    ((ptr =
      ezxml_attr (tmp_xml,
		  "timeout")) ==
     NULL) ? parse_period ("1h") : parse_period (ptr);

  if (ezxml_attr (tmp_xml, "script"))
    {
      cfg->exec_script = strdup (ezxml_attr (tmp_xml, "script"));
      if (cfg->exec_script)
	{
	  int status_script;
	  struct stat buffer_script;
	  status_script = stat (cfg->exec_script, &buffer_script);
	  if (status_script)
	    {
	      fprintf (stderr, "Wrong script name - %s\n", cfg->exec_script);
	      exit (-1);
	    }
	  else
	    {
	      if (S_ISDIR (buffer_script.st_mode))
		{
		  fprintf (stderr, "Script is directory - %s\n",
			   cfg->exec_script);
		  exit (-1);
		}
	    }
	}
    }
  else
    {
      cfg->exec_script = NULL;
    }

  tmp_xml = ezxml_child (xml, "connector");
  if (tmp_xml == NULL)
    {
      fprintf (stderr, "No connector parameter");
      exit (-1);
    }
  cfg->db_login =
    strdup (!ezxml_attr (tmp_xml, "login") ? "" :
	    ezxml_attr (tmp_xml, "login"));
  cfg->db_password =
    strdup (!ezxml_attr (tmp_xml, "password") ? "" :
	    ezxml_attr (tmp_xml, "password"));
  cfg->host =
    strdup (!ezxml_attr (tmp_xml, "host") ? "" :
	    ezxml_attr (tmp_xml, "host"));
  cfg->separator =
    !ezxml_attr (tmp_xml,
		 "prefix_separator") ? '_' : *(ezxml_attr (tmp_xml,
							   "prefix_separator"));

  tmp_xml = ezxml_child (xml, "default");
  if (tmp_xml == NULL)
    {
      fprintf (stderr, "No default limits");
      exit (-1);
    }

  cfg->default_limit.mode = RESTRICT_MODE;

  for (tmp_xml_limit = ezxml_child (tmp_xml, "limit"); tmp_xml_limit;
       tmp_xml_limit = tmp_xml_limit->next)
    {
      set_stats_limit (tmp_xml_limit, &cfg->default_limit);
    }
  cfg->default_limit.mode = RESTRICT_MODE;
  cfg->default_limit.account_flag = true;

  for (tmp_xml = ezxml_child (xml, "user"); tmp_xml; tmp_xml = tmp_xml->next)
    {
      const char *account = ezxml_attr (tmp_xml, "name");
      const char *mysql_name = ezxml_attr (tmp_xml, "mysql_name");
      if ((account == NULL) && (mysql_name == NULL))
	{
	  fprintf (stderr,
		   "Error: both 'name' and 'mysql_name' attributes are absent\n");
	  exit (-1);
	}
      if ((account != NULL) && (mysql_name != NULL))
	{
	  fprintf (stderr,
		   "Error: both 'name' and 'mysql_name' attributes are present\n");
	  exit (-1);
	}
      stats_limit_cfg *l = calloc (1, sizeof (stats_limit_cfg));

      // inheritance of limits from default
      memcpy (l, &cfg->default_limit, sizeof (stats_limit_cfg));

      l->account_flag = account != NULL;
      l->mode =
	((ptr =
	  ezxml_attr (tmp_xml,
		      "mode")) ==
	 NULL) ? RESTRICT_MODE : mode_type_str_to_enum (ptr);
      for (tmp_xml_limit = ezxml_child (tmp_xml, "limit"); tmp_xml_limit;
	   tmp_xml_limit = tmp_xml_limit->next)
	{
	  set_stats_limit (tmp_xml_limit, l);
	}
      g_hash_table_replace (cfg->account_limits,
			    (gpointer) strdup ((account == NULL) ? mysql_name
					       : account), l);
    }

  ezxml_free (xml);
  return cfg;
}
Beispiel #10
0
/* ------------------------------------------------------------------------- */
int main(int argc, char* argv[])
{
    int ret;
    ezxml_t xml;
    bool retrieve;
    TMessage message;
    int connection;

    if (argc < 2)
    {
        printf("usage: %s <xml file>\n", argv[0]);
        return -EXIT_FAILURE;
    }

    xml = ezxml_parse_file(argv[1]);
    if (!xml)
    {
        printf("Failed to parse the file '%s'.\n", argv[1]);
        return -EXIT_FAILURE;
    }
    message.m_body = ezxml_toxml(xml, false);
    message.m_len = strlen(message.m_body);
    {
        const char *const name = ezxml_name(xml);
        retrieve = (0 == strcmp("retrieve", name));
    }
    ezxml_free(xml);


    ret = -EXIT_FAILURE;
    do
    {
        if (-1 == (connection = Connect(SERVER_IP, SERVER_PORT)))
            break;

        if (SendMessage(connection, &message))
        {
            printf("Failed to send the message.\n");
            break;
        }

        if (!retrieve)
        {
            ret = -EXIT_SUCCESS;
            break;
        }

        if (ReceiveMessage(connection, &message))
        {
            printf("Failed to receive the reply message.\n");
            break;
        }

        xml = ezxml_parse_str(message.m_body, message.m_len);
        if (xml)
        {
            const char *const str = ezxml_toxml(xml, true);
            if (str)
            {
                puts(str);
                free((char*)str);
            }
            ezxml_free(xml);
        }
        else
        {
            printf("Failed to parse the reply message.\n");
            break;
        }

        ret = -EXIT_SUCCESS;
    } while(0);

    free(message.m_body);
    close(connection);
    return ret;
}
ClParserPtrT clParserParseFile(const char *file)
{
    return ezxml_parse_file(file);
}
/*
 * parse_automaton_set_xml_file
 *
 * Parse the entire of an automaton set xml file.
 *
 * This is called once per xml file. It creates the automaton structure and 
 * fills it in joining up the links. Any error is considered fatal and will
 * cause a return code along with debug remarks.
 *
 * Parameters: filename - If this cannot be read then the function will fail.
 *             automaton_set - The set to fill in a structure for.
 *             state_callback - Callback to generate the states.
 *             event_callback - Callback to generate the events.
 *             match_state - Used to set up lua globals.
 */
int parse_automaton_set_xml_file(char *filename,
                                 AUTOMATON_SET *automaton_set,
                                 int (*state_callback)(AUTOMATON_STATE ***,int),
                                 int (*event_callback)(AUTOMATON_EVENT ***),
                                 MATCH_STATE *match_state)
{
  /*
   * Local Variables.
   */
  int ret_code = AUTOMATON_XML_FILE_OK;
  ezxml_t xml_file;
  ezxml_t xml_automaton;
  ezxml_t xml_start_automaton;
  int ii;
  int rc;

  /*
   * The transition file is strictly an xml file so we use an external xml
   * library to load it and look for values.
   *
   * If the file comes back null then it failed to load for some reason.
   */
  xml_file = ezxml_parse_file(filename);
  if (NULL == xml_file)
  {
    DT_DEBUG_LOG("Failed to load xml_automaton file %s: error %s\n", 
                 filename,
                 ezxml_error(xml_file));
    ret_code = AUTOMATON_XML_FILE_LOAD_FAIL;
    goto EXIT_LABEL;
  }

  /*
   * This allocates the memory required for the automaton array and creates 
   * the automaton structures. It does not fill in any information.
   */
  create_automatons_from_xml(&xml_file, 
                             automaton_set, 
                             state_callback, 
                             event_callback);

  /*
   * Fill in the names of the automatons and transitions from the file. This
   * is required so that we can refer to them from each other when building
   * up the links later.
   */
  ret_code = parse_automaton_names(&xml_file, automaton_set);
  if (AUTOMATON_XML_FILE_OK != ret_code)
  {
    DT_DEBUG_LOG("Failed to parse automaton names\n");
    goto EXIT_LABEL;
  }

  /*
   * Finally now that the automatons are created and have their names filled in
   * we can set up all the links between transitions, states, events and other
   * automatons.
   */
  ii = 0;
  for (xml_automaton = ezxml_child(xml_file, "automaton");
       xml_automaton;
       xml_automaton = xml_automaton->next)
  {
    /*
     * Attempt to set up the automaton links.
     */
    rc = init_automaton_links(automaton_set->automaton_array[ii],
                              xml_automaton,
                              automaton_set,
                              match_state);
    if (INIT_AUTOMATON_LINKS_OK != rc)
    {
      DT_DEBUG_LOG("Failed setting up automaton links for automaton %s\n",
                   automaton_set->automaton_array[ii]->name);
      ret_code = AUTOMATON_XML_FILE_LINKS_FAIL;
      goto EXIT_LABEL;
    }

    ii++;
  }

  /*
   * The automaton that this set starts in is hardcoded into the xml file so
   * retrieve it now and verify that it exists.
   */
  xml_start_automaton = ezxml_child(xml_file, "start_automaton");
  if (NULL == xml_start_automaton)
  {
    DT_DEBUG_LOG("There is no starting automaton in the set.\n");
    ret_code = AUTOMATON_XML_FILE_START_AUTOMATON_BAD;
    goto EXIT_LABEL;
  }

  /*
   * There was a starting automaton so retrieve it by name.
   */
  automaton_set->start_automaton = get_automaton_by_name(
                                                      automaton_set,
                                                      xml_start_automaton->txt);
  if (NULL == automaton_set->start_automaton)
  {
    DT_DEBUG_LOG("The starting automaton listed (%s) does not exist in the " \
                 "set.\n",
                 xml_start_automaton->txt);
    ret_code = AUTOMATON_XML_FILE_START_AUTOMATON_BAD;
    goto EXIT_LABEL;
  }

EXIT_LABEL:

  return(ret_code);
}
void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filename, mapcache_cfg *config) {
   ezxml_t doc, node;
   const char *mode;
   doc = ezxml_parse_file(filename);
   if (doc == NULL) {
      ctx->set_error(ctx,400, "failed to parse file %s. Is it valid XML?", filename);
      goto cleanup;
   } else {
      const char *err = ezxml_error(doc);
      if(err && *err) {
         ctx->set_error(ctx,400, "failed to parse file %s: %s", filename, err);
         goto cleanup;
      }
   }

   if(strcmp(doc->name,"mapcache")) {
      ctx->set_error(ctx,400, "failed to parse file %s. first node is not <mapcache>", filename);
      goto cleanup;
   }
   mode = ezxml_attr(doc,"mode");
   if(mode) {
      if(!strcmp(mode,"combined_mirror")) {
         config->mode = MAPCACHE_MODE_MIRROR_COMBINED;
      } else if(!strcmp(mode,"split_mirror")) {
         config->mode = MAPCACHE_MODE_MIRROR_SPLIT;
      } else if(!strcmp(mode,"normal")) {
         config->mode = MAPCACHE_MODE_NORMAL;
      } else {
         ctx->set_error(ctx,400,"unknown mode \"%s\" for <mapcache>",mode);
         goto cleanup;
      }
   } else {
         config->mode = MAPCACHE_MODE_NORMAL;
   }

   for(node = ezxml_child(doc,"metadata"); node; node = node->next) {
      parseMetadata(ctx, node, config->metadata);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   for(node = ezxml_child(doc,"source"); node; node = node->next) {
      parseSource(ctx, node, config);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   for(node = ezxml_child(doc,"grid"); node; node = node->next) {
      parseGrid(ctx, node, config);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   for(node = ezxml_child(doc,"format"); node; node = node->next) {
      parseFormat(ctx, node, config);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   for(node = ezxml_child(doc,"cache"); node; node = node->next) {
      parseCache(ctx, node, config);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   for(node = ezxml_child(doc,"tileset"); node; node = node->next) {
      parseTileset(ctx, node, config);
      if(GC_HAS_ERROR(ctx)) goto cleanup;
   }

   if ((node = ezxml_child(doc,"service")) != NULL) {
      ezxml_t service_node;
      for(service_node = node; service_node; service_node = service_node->next) {
         char *enabled = (char*)ezxml_attr(service_node,"enabled");
         char *type = (char*)ezxml_attr(service_node,"type");
         if(!strcasecmp(enabled,"true")) {
            if (!strcasecmp(type,"wms")) {
               mapcache_service *new_service = mapcache_service_wms_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_WMS] = new_service;
            }
            else if (!strcasecmp(type,"tms")) {
               mapcache_service *new_service = mapcache_service_tms_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_TMS] = new_service;
            }
            else if (!strcasecmp(type,"wmts")) {
               mapcache_service *new_service = mapcache_service_wmts_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_WMTS] = new_service;
            }
            else if (!strcasecmp(type,"kml")) {
               mapcache_service *new_service = mapcache_service_kml_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_KML] = new_service;
            }
            else if (!strcasecmp(type,"gmaps")) {
               mapcache_service *new_service = mapcache_service_gmaps_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_GMAPS] = new_service;
            }
            else if (!strcasecmp(type,"ve")) {
               mapcache_service *new_service = mapcache_service_ve_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_VE] = new_service;
            }
            else if (!strcasecmp(type,"demo")) {
               mapcache_service *new_service = mapcache_service_demo_create(ctx);
               if(new_service->configuration_parse_xml) {
                  new_service->configuration_parse_xml(ctx,service_node,new_service,config);
               }
               config->services[MAPCACHE_SERVICE_DEMO] = new_service;
            } else {
               ctx->set_error(ctx,400,"unknown <service> type %s",type);
            }
            if(GC_HAS_ERROR(ctx)) goto cleanup;
         }
      }
   }
   else if ((node = ezxml_child(doc,"services")) != NULL) {
      ctx->log(ctx,MAPCACHE_WARN,"<services> tag is deprecated, use <service type=\"wms\" enabled=\"true|false\">");
      parseServices(ctx, node, config);
   } else {
      ctx->set_error(ctx, 400, "no <services> configured");
   }
   if(GC_HAS_ERROR(ctx)) goto cleanup;


   node = ezxml_child(doc,"default_format");
   if(!node)
      node = ezxml_child(doc,"merge_format");
   if (node) {
      mapcache_image_format *format = mapcache_configuration_get_image_format(config,node->txt);
      if(!format) {
         ctx->set_error(ctx, 400, "default_format tag references format %s but it is not configured",
               node->txt);
         goto cleanup;
      }
      config->default_image_format = format;
   }

   if ((node = ezxml_child(doc,"errors")) != NULL) {
      if(!strcmp(node->txt,"log")) {
         config->reporting = MAPCACHE_REPORT_LOG;
      } else if(!strcmp(node->txt,"report")) {
         config->reporting = MAPCACHE_REPORT_MSG;
      } else if(!strcmp(node->txt,"empty_img")) {
         config->reporting = MAPCACHE_REPORT_EMPTY_IMG;
         mapcache_image_create_empty(ctx, config);
         if(GC_HAS_ERROR(ctx)) goto cleanup;
      } else if(!strcmp(node->txt, "report_img")) {
         config->reporting = MAPCACHE_REPORT_ERROR_IMG;
         ctx->set_error(ctx,501,"<errors>: report_img not implemented");
         goto cleanup;
      } else {
         ctx->set_error(ctx,400,"<errors>: unknown value %s (allowed are log, report, empty_img, report_img)",
               node->txt);
         goto cleanup;
      }
   }

   if((node = ezxml_child(doc,"lock_dir")) != NULL) {
      config->lockdir = apr_pstrdup(ctx->pool, node->txt);
   } else {
      config->lockdir = apr_pstrdup(ctx->pool,"/tmp");
   }

   if((node = ezxml_child(doc,"lock_retry")) != NULL) {
      char *endptr;
      config->lock_retry_interval = (unsigned int)strtol(node->txt,&endptr,10);
      if(*endptr != 0 || config->lock_retry_interval < 0) {
         ctx->set_error(ctx, 400, "failed to parse lock_retry microseconds \"%s\". Expecting a positive integer",
               node->txt);
         return;
      }
   }
   
   if((node = ezxml_child(doc,"threaded_fetching")) != NULL) {
      if(!strcasecmp(node->txt,"true")) {
         config->threaded_fetching = 1;
      } else if(strcasecmp(node->txt,"false")) {
         ctx->set_error(ctx, 400, "failed to parse threaded_fetching \"%s\". Expecting true or false",node->txt);
         return;
      }
   }

   if((node = ezxml_child(doc,"log_level")) != NULL) {
      if(!strcasecmp(node->txt,"debug")) {
         config->loglevel = MAPCACHE_DEBUG;
      } else if(!strcasecmp(node->txt,"info")) {
         config->loglevel = MAPCACHE_INFO;
      } else if(!strcasecmp(node->txt,"notice")) {
         config->loglevel = MAPCACHE_NOTICE;
      } else if(!strcasecmp(node->txt,"warn")) {
         config->loglevel = MAPCACHE_WARN;
      } else if(!strcasecmp(node->txt,"error")) {
         config->loglevel = MAPCACHE_ERROR;
      } else if(!strcasecmp(node->txt,"crit")) {
         config->loglevel = MAPCACHE_CRIT;
      } else if(!strcasecmp(node->txt,"alert")) {
         config->loglevel = MAPCACHE_ALERT;
      } else if(!strcasecmp(node->txt,"emerg")) {
         config->loglevel = MAPCACHE_EMERG;
      } else {
         ctx->set_error(ctx,500,"failed to parse <log_level> \"%s\". Expecting debug, info, notice, warn, error, crit, alert or emerg",node->txt);
         return;
      }
   }
   if((node = ezxml_child(doc,"auto_reload")) != NULL) {
      if(!strcasecmp(node->txt,"true")) {
         config->autoreload = 1;
      } else if(!strcasecmp(node->txt,"false")) {
         config->autoreload = 0;
      } else {
         ctx->set_error(ctx,500,"failed to parse <auto_reload> \"%s\". Expecting true or false",node->txt);
         return;
      }
   }


cleanup:
   ezxml_free(doc);
   return;
}
static int parseConfigFile(const char *pConfigFile,
                           const char *pNodeName,
                           const char *pNodeType,
                           char ***comps,
                           int *numComps)
{
    int err = -1;
    ezxml_t top, xml, xmlver;
    char **pComps = NULL;
    int c = 0;
    if(!pConfigFile || !pNodeName || !pNodeType || !comps || !numComps)
        return -1;
    top = xml = ezxml_parse_file(pConfigFile);
    if(!xml)
    {
        fprintf(stderr, "Error parsing xml file\n");
        return -1;
    }
    /*
     * Parse the cpmconfigs for the nodename first. to get asp component list.
     */
    xml = ezxml_child(xml, "version");
    if(!xml)
    {
        fprintf(stderr, "Unable to find version tag. Assuming old config file format\n");
        xmlver = top;
    }
    else
    {
        xmlver = xml->child;
    }
    xml = ezxml_child(xmlver, "cpmConfigs");
    if(!xml)
    {
        fprintf(stderr, "Unable to find cpmConfigs tag\n");
        goto out_free;
    }
    xml = ezxml_child(xml, "cpmConfig");
    if(!xml)
    {
        fprintf(stderr, "Unable to find cpmConfig tag\n");
        goto out_free;
    }

    while(xml)
    {
        char *nodetype = (char*)ezxml_attr(xml, "nodeType");
        if(!nodetype)
        {
            fprintf(stderr, "Unable to find nodeType attribute for cpmConfig tag\n");
            goto out_free;
        }
        if(!strncmp(nodetype, pNodeType, strlen(pNodeType)))
        {
            /*
             * found the hit for the node type. Copy the asp component list now
             */
            xml = ezxml_child(xml, "aspServiceUnits");
            if(!xml)
            {
                fprintf(stderr, "Unable to find asp service units\n");
                goto out_free;
            }
            xml = ezxml_child(xml, "aspServiceUnit");
            while(xml)
            {
                char *aspUnit = (char*)ezxml_attr(xml, "name");
                const char **compMap = NULL;
                if(!aspUnit)
                {
                    fprintf(stderr, "Unable to find asp service unit\n");
                    goto out_free;
                }
                compMap = aspMapSU(aspUnit);
                assert(compMap != NULL);
                while(*compMap)
                {
                    pComps = realloc(pComps, (c+1)*sizeof(*pComps));
                    assert(pComps);
                    pComps[c] = strdup(*compMap);
                    assert(pComps[c]);
                    ++c;
                    ++compMap;
                }
                xml = xml->next;
            }
            goto out_find;
        }
        xml = xml->next;
    }
    
    goto out_free;

    out_find:
    xml = ezxml_child(xmlver, "nodeInstances");
    if(!xml)
    {
        fprintf(stderr, "Unable to find nodeInstances tag\n");
        goto out_free;
    }
    xml = ezxml_child(xml, "nodeInstance");
    while(xml)
    {
        char *nodename = (char*)ezxml_attr(xml, "name");
        if(!nodename)
        {
            fprintf(stderr, "Unable to find nodename tag\n");
            goto out_free;
        }
        if(!strncmp(nodename, pNodeName, strlen(pNodeName)))
        {
            /*
             * node matched. Gather components in this node.
             */
            xml = ezxml_child(xml, "serviceUnitInstances");
            if(!xml)
            {
                fprintf(stderr, "Unable to parse service unit instances\n");
                goto out_free;
            }
            xml = ezxml_child(xml, "serviceUnitInstance");
            if(!xml)
            {
                fprintf(stderr, "Unable to parse service unit tag\n");
                goto out_free;
            }
            while(xml)
            {
                ezxml_t xmlComp;
                ezxml_t xmlComps = ezxml_child(xml, "componentInstances");
                if(!xmlComps)
                {
                    goto next;
                }
                xmlComp = ezxml_child(xmlComps, "componentInstance");
                while(xmlComp)
                {
                    char *compName = (char*)ezxml_attr(xmlComp, "type");
                    if(!compName)
                    {
                        fprintf(stderr, "Unable to find comp name type\n");
                        goto out_free;
                    }
                    pComps = realloc(pComps, (c+1)*sizeof(*pComps));
                    assert(pComps);
                    pComps[c] = strdup(compName);
                    assert(pComps[c]);
                    ++c;
                    xmlComp = xmlComp->next;
                }
                next:
                xml = xml->next;
            }
            goto out_free;
        }
        xml = xml->next;
    }

    out_free:
    ezxml_free(top);
    if(!c)
    {
        if(pComps)
            free(pComps);
    }
    else
    {
        *comps = pComps;
        *numComps = c;
        err = 0;
    }
    return err;
}
int main() {

	printf("Reading XML.. .. ..\n");
	ezxml_t f1 = ezxml_parse_file("test.xml"), classification, temp, algo, temp2;
	 
	classification = ezxml_child(f1, "classification");
	
	temp = ezxml_child(classification, "datafile");
	printf("Datafile is ");	
	printf("%s", temp->txt);
	printf("\n");

	temp = ezxml_child(classification, "input");
	printf("I/P is ");	
	printf("%s", temp->txt);
	printf("\n");

	temp = ezxml_child(classification, "output");
	printf("O/P is ");	
	printf("%s", temp->txt);
	printf("\n");

	temp = ezxml_child(classification, "numberOfLayers");
	printf("# of Neurons is ");	
	printf("%s", temp->txt);
	printf("\n");

	temp = ezxml_child(classification, "algorithm");
	algo = ezxml_child(temp, "MultiLayerPerceptron");
	temp2 = ezxml_child(algo, "hiddenLayerActivation");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "hiddenActivationSteepness");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "outputLayerActivation");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "outputActivationSteepness");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "trainStopFuction");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "hiddenNeurons");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "desiredError");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "maxEpochs");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	temp2 = ezxml_child(algo, "epochsBetweenReports");
	printf("Activation Func. is ");	
	printf("%s", temp2->txt);
	printf("\n");

	ezxml_free(f1); 

	return 0;
}
Beispiel #16
0
void LISACode::config(char * fNInXML)
{
	
	if(LISA == NULL)
		LISA = new LCDetector(MT);
	
	//! ****** Check that the file exist
	Cout << ">>>>> Read configuration " << fNInXML << " ..." << Endl;
	std::ifstream fIn;
	fIn.open(fNInXML);
	if(fIn == NULL){
		Cout << "ERROR: LISACode::config : Can not open the file " << fNInXML << " !" << Endl;
		throw std::invalid_argument("ERROR: LISACode::config : Can not open the file.");
	}
	fIn.close();
	fIn.clear();
	
	
	//! ****** Read XML
	ezxml_t tree, section, param, subsection, orbitdata;
	tree = ezxml_parse_file(fNInXML);
	for (section = ezxml_child(tree, "XSIL"); section; section = section->next) {
		
		if(MT->wcmp(ezxml_attr(section, "Type"),"Simulate")){
			
			//! **** Configuration of simulation parameters
			for(param = ezxml_child(section,"Param"); param; param = param->next){
				
				if(MT->wcmp(ezxml_attr(param,"Name"),"TimeOffset"))
					t0 = MT->gXMLTime(param);
				
				if(MT->wcmp(ezxml_attr(param,"Name"),"Cadence"))
					dtMes = MT->gXMLTime(param);
				
				if(MT->wcmp(ezxml_attr(param,"Name"),"Duration"))
					tDur = MT->gXMLTime(param);
				
			}
			
			for (subsection = ezxml_child(section, "XSIL"); subsection; subsection = subsection->next) {
				if(MT->wcmp(ezxml_attr(subsection, "Type"),"Output")){
					configOuput(subsection);
				}
			}
		}
		
		//! **** Configuration of gravitational waves
		if(MT->wcmp(ezxml_attr(section, "Type"),"SourceData")){
			ezxml_t gwdata; 
			for (gwdata = ezxml_child(section, "XSIL"); gwdata; gwdata = gwdata->next) {
				ezxml_t param;
				
				//! * Configure GW read in file
				if(MT->wcmp(ezxml_attr(gwdata,"Type"),"SampledPlaneWave")){
					AddGW("SampledPlaneWave");
					GWs[NGWs-1]->config(gwdata);
				}else{
					if(MT->wcmp(ezxml_attr(gwdata,"Type"),"PlaneWave")){
						
						for(param = ezxml_child(gwdata,"Param"); param; param = param->next){
							//! * Configure GW modeled in the code
							
							char * SourceType(NULL);
							if(MT->wcmp(ezxml_attr(param,"Name"),"SourceType")){
								MT->stripcopy((*param).txt, SourceType);
								if(MT->wcmp(SourceType, "Stochastic")){
									AddGW("Stochastic");
									GWs[NGWs-1]->config(gwdata);
									GWOptimizeTime = true;
								}
								if((MT->wcmp(SourceType, "GalacticBinaryV"))||(MT->wcmp(SourceType, "GalacticBinary"))){
									AddGW("GalacticBinary");
									GWs[NGWs-1]->config(gwdata);
								}
								if((MT->wcmp(SourceType, "SpinBBHHighHarm"))||(MT->wcmp(SourceType, "SpinBBHHH"))){
									AddGW("SpinBBHHighHarm");
									GWs[NGWs-1]->config(gwdata);
								}
								if((MT->wcmp(SourceType, "NRwave"))){
									AddGW("NRwave");
									GWs[NGWs-1]->config(gwdata);
								}
							       


								if((MT->wcmp(SourceType, "CosmicString"))||(MT->wcmp(SourceType, "CosmicString"))){
									AddGW("CosmicString");
									GWs[NGWs-1]->config(gwdata);
								}

							}
							if(SourceType != NULL)
								MT->Free(SourceType, (strlen(SourceType)+1) * sizeof(char));
						}
					}
				}
			}
		}
									
		
		
		//! **** Configuration of orbits
		if(MT->wcmp(ezxml_attr(section, "Type"),"LISAData")){
			for(orbitdata = ezxml_child(section, "XSIL"); orbitdata; orbitdata = orbitdata->next) {
				if(MT->wcmp(ezxml_attr(orbitdata,"Type"),"LISACode_Orbits")){
					if (Orb != NULL)
						throw std::invalid_argument("ERROR in LISACode::config : The orbit have already been created !  If you want to had complement informations to the orbits use an xml bloc with Type='OrbitsInfo' . ");
					Orb = new LCOrbitsAnaLISA(MT);
					Orb->config(orbitdata);
				}
                if(MT->wcmp(ezxml_attr(orbitdata,"Type"),"MLDC_Orbits")){
					if (Orb != NULL)
						throw std::invalid_argument("ERROR in LISACode::config : The orbit have already been created !  If you want to had complement informations to the orbits use an xml bloc with Type='OrbitsInfo' . ");
					Orb = new LCOrbitsAnaMLDC(MT);
					Orb->config(orbitdata);
				}
				if(MT->wcmp(ezxml_attr(orbitdata,"Type"),"OrbitsFile")){
					if (Orb != NULL)
						throw std::invalid_argument("ERROR in LISACode::config : The orbit have already been created ! If you want to had complement informations to the orbits use an xml bloc with Type='OrbitsInfo' . ");
					Orb = new LCOrbitsData(MT);
					Orb->config(orbitdata);
				}
				if(MT->wcmp(ezxml_attr(orbitdata,"Type"),"Octahedron_FirstOrbits")){
					if (Orb != NULL)
						throw std::invalid_argument("ERROR in LISACode::config : The orbit have already been created ! If you want to had complement informations to the orbits use an xml bloc with Type='OrbitsInfo' . ");
					Orb = new LCOrbitsAnaOctahedron(MT);
					Orb->config(orbitdata);
				}
				if(MT->wcmp(ezxml_attr(orbitdata,"Type"),"OrbitsInfo")){
					if (Orb == NULL)
						throw std::invalid_argument("ERROR in LISACode::config : You have to define orbits before reading an 'OrbitsInfo' bloc !");
					Orb->config(orbitdata);
				}
			}
		}
									
		
		//! **** Configuration of noises 
		if(MT->wcmp(ezxml_attr(section, "Type"),"NoiseData"))
			LISA->configNoise(section);
		
		
		
		if(MT->wcmp(ezxml_attr(section, "Type"),"LISACode")){
			
			for (subsection = ezxml_child(section, "XSIL"); subsection; subsection = subsection->next) {
				
				//Cout << ezxml_attr(subsection,"Type") << Endl;
				
				//! *** Configuration of the detector
				if(MT->wcmp(ezxml_attr(subsection,"Type"),"Detector"))
					LISA->configDetector(subsection);
				
				//! *** Configuration of intermediate TDI
				if(MT->wcmp(ezxml_attr(subsection,"Type"),"TDIIntermediate"))
					configTDIIntermediate(subsection);
				
				//! *** Configuration of TDI generator
				if(MT->wcmp(ezxml_attr(subsection,"Type"),"TDIGenerator")){
					NTDIG++;
					TDIG = (LCTDIGen**) MT->ReAllocMemory(TDIG, (NTDIG-1)*sizeof(LCTDIGen*), NTDIG*sizeof(LCTDIGen*));
					TDIG[NTDIG-1] = new LCTDIGen(MT);
					TDIG[NTDIG-1]->config(subsection);
				}
			}
			
		}
		
	}
	ezxml_free(tree);
}
Beispiel #17
0
int main(int argc, char *argv[])
{
    pid_t pid = getpid();
    int str_end,hash_beg,i = 0, sm, lo, rs, dr, hash_len;
    char dir[200],report[1000],mdString[40]= {0}, *parcel, tmp[100], *from_str, *from_str_tmp, *hash_et, *help_ptr, *arglist_sm[100], *arglist_lo[100], *arglist_rs[100], *arglist_dr[100];
    unsigned char *hash_cand = malloc(50*sizeof(char));
    t_elements parsed_elements;
    sprintf(dir,"%s%d_log.log",LOG_DIR,pid);
    FILE *log = fopen(dir,"w");
    if(log == NULL) exit(-4);
    from_str_tmp = malloc(sizeof(char)*100000);
    sprintf(tmp, "/tmp/%d/", pid);
    mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    chdir(tmp);
    fprintf(log, "PID: %d, dir changed\nthats what we got:\n", pid);
    do
    {
        from_str_tmp[i] = getc(stdin);
        fputc(from_str_tmp[i],log);
        if(from_str_tmp[i] == '-' && from_str_tmp[i-1] == '-')
        {
            str_end=i-1;
            hash_beg=i+1;
            from_str_tmp[str_end]=0;
        }
    }
    while(from_str_tmp[i++] != EOF);
    hash_et = from_str_tmp + sizeof(char)*hash_beg;
    hash_et[40]=0;
    from_str_tmp += 8*sizeof(char);
    from_str = curl_decode(from_str_tmp);
    help_ptr = from_str;
    from_str_tmp = decode(from_str); /*base64 conversion*/
    fprintf(log,"\nAfter url_decode:%s",from_str);
    //\r\n
    from_str=from_str_tmp;
    fprintf(log,"\nhashed string:%s\n",help_ptr);
    HMAC(EVP_sha1(),SALT, strlen(SALT), (unsigned char*)help_ptr, strlen(help_ptr),hash_cand,(unsigned int*)&hash_len);
    for(i = 0; i < 20; i++)
        sprintf(&mdString[i*2], "%02x",hash_cand[i]);
    //FIXME leaks everywhere
    if(strcmp(mdString,hash_et)==0)
    {
        fprintf(log,"\nhash correct\n");
        fprintf(log,"decoded string: %s\n", from_str);
        printf("Content-Type: text/plain;charset=us-ascii\n\n");
    }
    else
    {
        fprintf(log, "%s\n%s\n hash incorrect\n",mdString,hash_et);
        printf("Content-Type: text/html\nStatus: 422 Bad Request\n\n");
        free(hash_cand);
        free(from_str);
        fclose(log);
        exit(-1);
    }
    /*we have now string to parse*/
    cJSON *root = cJSON_Parse(from_str);
    if (!root)
    {
        fprintf(log,"Error before: [%s]\n", cJSON_GetErrorPtr());
    }
    fprintf(log,"exec part\n");
    parse_into_elements(&parsed_elements, root, log);
    fflush(NULL);
    lo = make_arglist_for_login(arglist_lo, parsed_elements);
    fork_exec_with_inp_redir(arglist_lo, 1, "whatever");
    sm = make_arglist_for_submit_and_run(arglist_sm, parsed_elements, arglist_lo[4]);
    fork_exec_with_inp_redir(arglist_sm, 1, "num.txt");
    rs = make_arglist_for_run_status(arglist_rs, parsed_elements, arglist_lo[4]);
    int rep_num;
    if((rep_num=wait_for_report(5, arglist_rs, parsed_elements.status))==-1)
    {
        strcpy(parsed_elements.status,"error");
        strcpy(report,"ejudge marking error");
    }
    else
    {
        int flag=0,some;
        some = submit_checked(parsed_elements.status, ejudge_common);
        if(strcmp(parsed_elements.status,"OK")==0)
        {
            strcpy(parsed_elements.status,"ok");
            flag=1;
        }
        else if(submit_checked(parsed_elements.status, ejudge_error)!=-1)
        {
            strcpy(parsed_elements.status,"error");
            strcpy(report,ejudge_detailed[some]);
            if(some == 1) flag = 2; /*let report be when compilation error*/
        }
        else
        {
            strcpy(parsed_elements.status, "fail");
            flag=1;
        }
        if(flag)
        {
            dr = make_arglist_for_dump_report(arglist_dr, parsed_elements, arglist_lo[4]); //BACKTRACE part
            fork_exec_with_inp_redir(arglist_dr, 1, "return_report.xml");
            /*xml parse part*/
            if(flag==1){
                ezxml_t trace = ezxml_parse_file("return_report.xml");
                const char * points = ezxml_attr(trace, "score");
                const char * tp = ezxml_attr(trace, "tests-passed");
                const char * to = ezxml_attr(trace, "run-tests");
                sprintf(report, "%s. Your score is = %s, %s/%s tests passed",ejudge_detailed[some], points , tp, to);
                ezxml_free(trace);
                /* parse part end */
                /* BTW ezxml lib used so you have possibility to add smth to report */
            }
            else if(flag==2)
            {
                char *iftmp;
                iftmp = read_string("return_report.xml");
                strcat(report, iftmp);
                free(iftmp);
            }

        }
    }
    fprintf(log, "exec part end\n");
    cJSON_AddStringToObject(root, "trace", report);
    cJSON_AddStringToObject(root, "status", parsed_elements.status);
    cJSON_DeleteItemFromObject(root,"programming_language");
    cJSON_DeleteItemFromObject(root,"file_name");
    cJSON_DeleteItemFromObject(root,"file_content");
    parcel = cJSON_Print(root);
    fprintf(log,"output:%s\n",parcel);
    free(from_str);
    from_str=encode(parcel);
    fprintf(log,"encoded output:%s\n", from_str);
    parcel=curl_encode(from_str);
    fprintf(log,"curl_encoded output:%s\n", parcel);
    HMAC(EVP_sha1(),SALT, strlen(SALT), (unsigned char*)from_str, strlen(from_str),hash_cand,(unsigned int*)&hash_len);
    for(i = 0; i < 20; i++)
        sprintf(&mdString[i*2], "%02x", (unsigned int)hash_cand[i]);
    fprintf(log,"hash HMAC:%s\n", mdString);
    sprintf(from_str,"session=%s--%s",parcel,mdString);
    fprintf(log,"final output:%s\n", from_str);
    /*ready to send backparcel*/
    sendJSON(parsed_elements.url, from_str);
    sendJSON("http://ejudge.100ege.ru/cgi-bin/a.out", from_str); //FIXME: for logging purposes
    //printf("%s",from_str);
    /*now clean part*/
    fprintf(log,"\n%s\n",from_str);
    str_vector_free(arglist_lo, lo);
    str_vector_free(arglist_rs, rs);
    str_vector_free(arglist_sm, sm);
    free(root);
    free(from_str);
    free(parcel);
    fclose(log);
    chdir("/tmp/");
    execl("/bin/rm", "/bin/rm", "-rf", tmp, NULL);
    return 0;
}
Beispiel #18
0
/**
 * Reads the transistor properties from the .xml file
 */
void power_tech_load_xml_file(char * cmos_tech_behavior_filepath) {
	ezxml_t cur, child, prev;
	const char * prop;
	char msg[BUFSIZE];

	if (!file_exists(cmos_tech_behavior_filepath)) {
		/* .xml transistor characteristics is missing */
		sprintf(msg,
				"The CMOS technology behavior file ('%s') does not exist.  No power information will be calculated.",
				cmos_tech_behavior_filepath);
		power_log_msg(POWER_LOG_ERROR, msg);

		g_power_tech->NMOS_inf.num_size_entries = 0;
		g_power_tech->NMOS_inf.long_trans_inf = NULL;
		g_power_tech->NMOS_inf.size_inf = NULL;

		g_power_tech->PMOS_inf.num_size_entries = 0;
		g_power_tech->PMOS_inf.long_trans_inf = NULL;
		g_power_tech->PMOS_inf.size_inf = NULL;

		g_power_tech->Vdd = 0.;
		g_power_tech->temperature = 85;
		g_power_tech->PN_ratio = 1.;
		return;
	}
	cur = ezxml_parse_file(cmos_tech_behavior_filepath);

	prop = FindProperty(cur, "file", TRUE);
	ezxml_set_attr(cur, "file", NULL);

	prop = FindProperty(cur, "size", TRUE);
	g_power_tech->tech_size = atof(prop);
	ezxml_set_attr(cur, "size", NULL);

	child = FindElement(cur, "operating_point", TRUE);
	g_power_tech->temperature = GetFloatProperty(child, "temperature", TRUE, 0);
	g_power_tech->Vdd = GetFloatProperty(child, "Vdd", TRUE, 0);
	FreeNode(child);

	child = FindElement(cur, "p_to_n", TRUE);
	g_power_tech->PN_ratio = GetFloatProperty(child, "ratio", TRUE, 0);
	FreeNode(child);

	/* Transistor Information */
	child = FindFirstElement(cur, "transistor", TRUE);
	process_tech_xml_load_transistor_info(child);

	prev = child;
	child = child->next;
	FreeNode(prev);

	process_tech_xml_load_transistor_info(child);
	FreeNode(child);

	/* Multiplexer Voltage Information */
	child = FindElement(cur, "multiplexers", TRUE);
	power_tech_xml_load_multiplexer_info(child);
	FreeNode(child);

	/* Vds Leakage Information */
	child = FindElement(cur, "nmos_leakages", TRUE);
	power_tech_xml_load_nmos_st_leakages(child);
	FreeNode(child);

	/* Buffer SC Info */
	child = FindElement(cur, "buffer_sc", TRUE);
	power_tech_xml_load_sc(child);
	FreeNode(child);

	/* Components */
	child = FindElement(cur, "components", TRUE);
	power_tech_xml_load_components(child);
	FreeNode(child);

	FreeNode(cur);
}