예제 #1
0
char * check_streams(ezxml_t registry, char * streams)
{
	ezxml_t streams_xml, stream_xml;

	const char *streamname;

	char *string, *tofree, *token;
	char *failed;
	int missing_stream;

	string = strdup(streams);
	tofree = string;
	failed = NULL;

	while( (token = strsep(&string, ";")) != NULL) {
		missing_stream = 1;
		for (streams_xml = ezxml_child(registry, "streams"); streams_xml; streams_xml = streams_xml->next) {
			for (stream_xml = ezxml_child(streams_xml, "stream"); stream_xml; stream_xml = stream_xml->next) {
				streamname = ezxml_attr(stream_xml, "name");

				if(strcasecmp(streamname, token) == 0) {    /* TODO: Not portable? */
					missing_stream = 0;
				}
			}
		}

		if (missing_stream) {
			failed = strdup(token);
			free(tofree);
			return failed;
		}
	}
	free(tofree);
	return failed;
}
예제 #2
0
const char *FindVersion(int file_id, BYTE *pbVersionBytes, int cpbVersionBytes, const Category cat) {

	if(!doc[cat]) return 0;

	char version_string[128];
	strncpy(version_string, (char *)pbVersionBytes, cpbVersionBytes);
	version_string[sizeof(version_string)-1] = 0;

	ezxml_t root = ezxml_get(doc[cat], "channel", 0, "item", -1);
    while (root) {
        int id = atoi(ezxml_txt(ezxml_child(root, "id")));
        const char* version = ezxml_txt(ezxml_child(root, "version"));
        
		if (id == file_id && version[0]) {
			if (strncmp(version, (char*)pbVersionBytes, cpbVersionBytes) && VersionLess(version_string, version)) {
				return version;
			} else {
				return "same";
            }
		} 

        root = ezxml_next(root);
    }

	return 0;
}
예제 #3
0
externC void
cyg_start( void )
{
  ezxml_t f1, team, driver;
  const char * teamname;
  int i;
  
  CYG_TEST_INIT();
  
  f1 = ezxml_parse_str(document, sizeof(document));

  for (team = ezxml_child(f1, "team"); team; team = team->next) {
    teamname = ezxml_attr(team, "name");
    for (i=0,driver = ezxml_child(team, "driver"); 
         driver; 
         driver = driver->next,i++) {
      if (strcmp(results[i].driver, ezxml_child(driver, "name")->txt) ||
          strcmp(results[i].team, teamname) ||
          strcmp(results[i].points, ezxml_child(driver, "points")->txt))
        CYG_TEST_FAIL("Parser failed first test");
    }
  }
  
  if (strcmp(ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt,
              "David Coultard")) 
    CYG_TEST_FAIL_FINISH("Parser failed second test");
  else
    CYG_TEST_PASS_FINISH("Parser passed");
  
  ezxml_free(f1);
}
예제 #4
0
char * check_packages(ezxml_t registry, char * packages){/*{{{*/
	ezxml_t packages_xml, package_xml;

	const char *packagename;

	char *string, *tofree, *token;
	char *failed;
	int missing_package;

	string = strdup(packages);
	tofree = string;
	failed = NULL;

	while( (token = strsep(&string, ";")) != NULL) {
		missing_package = 1;
		for (packages_xml = ezxml_child(registry, "packages"); packages_xml; packages_xml = packages_xml->next){
			for (package_xml = ezxml_child(packages_xml, "package"); package_xml; package_xml = package_xml->next){
				packagename = ezxml_attr(package_xml, "name");

				if(strcasecmp(packagename, token) == 0){
					missing_package = 0;
				}
			}
		}

		if (missing_package) {
			failed = strdup(token);
			free(tofree);
			return failed;
		}
	}
	free(tofree);
	return failed;
}/*}}}*/
예제 #5
0
char * check_dimensions(ezxml_t registry, char * dims){/*{{{*/
	ezxml_t dims_xml, dim_xml;

	const char *dimname;

	char *string, *tofree, *token;
	int missing_dim;

	string = strdup(dims);
	tofree = string;

	while( (token = strsep(&string, " ")) != NULL) {
		if (strcasecmp(token, "Time") != 0){
			missing_dim = 1;
			for (dims_xml = ezxml_child(registry, "dims"); dims_xml; dims_xml = dims_xml->next){
				for (dim_xml = ezxml_child(dims_xml, "dim"); dim_xml; dim_xml = dim_xml->next){
					dimname = ezxml_attr(dim_xml, "name");

					if(strcasecmp(dimname, token) == 0){
						missing_dim = 0;
					}
				}
			}

			if (missing_dim) {
				free(tofree);
				return token;
			}
		}
	}
	free(tofree);
	return NULL;
}/*}}}*/
예제 #6
0
int is_unique_field(ezxml_t registry, ezxml_t field, const char *check_name){/*{{{*/
	ezxml_t struct_xml, var_arr_xml, var_xml;

	const char *name;

	for(struct_xml = ezxml_child(registry, "var_struct"); struct_xml; struct_xml = struct_xml->next){
		for(var_arr_xml = ezxml_child(struct_xml, "var_array"); var_arr_xml; var_arr_xml = var_arr_xml->next){
			for(var_xml = ezxml_child(var_arr_xml, "var"); var_xml; var_xml = var_xml->next){
				name = ezxml_attr(var_xml, "name");

				if(strcmp(name, check_name) == 0 && var_xml != field){
					return 0;
				}
			}
		}
		for(var_xml = ezxml_child(struct_xml, "var"); var_xml; var_xml = var_xml->next){
			name = ezxml_attr(var_xml, "name");

			if(strcmp(name, check_name) == 0 && var_xml != field){
				return 0;
			}
		}
	}

	return 1;
}/*}}}*/
예제 #7
0
파일: dimension.c 프로젝트: EOX-A/mapcache
static void _mapcache_dimension_sqlite_parse_xml(mapcache_context *ctx, mapcache_dimension *dim,
    ezxml_t node)
{
  mapcache_dimension_sqlite *dimension;
  ezxml_t child;

  dimension = (mapcache_dimension_sqlite*)dim;

  child = ezxml_child(node,"dbfile");
  if(child) {
    dimension->dbfile = apr_pstrdup(ctx->pool, child->txt);
  } else {
    ctx->set_error(ctx,400,"sqlite dimension \"%s\" has no <dbfile> node", dim->name);
    return;
  }
  child = ezxml_child(node,"validate_query");
  if(child) {
    dimension->get_values_for_entry_query = apr_pstrdup(ctx->pool, child->txt);
  } else {
    ctx->set_error(ctx,400,"sqlite dimension \"%s\" has no <validate_query> node", dim->name);
    return;
  }
  child = ezxml_child(node,"list_query");
  if(child) {
    dimension->get_all_values_query = apr_pstrdup(ctx->pool, child->txt);
  } else {
    ctx->set_error(ctx,400,"sqlite dimension \"%s\" has no <list_query> node", dim->name);
    return;
  }

}
예제 #8
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;
}
예제 #9
0
파일: dimension.c 프로젝트: EOX-A/mapcache
static void _mapcache_dimension_values_parse_xml(mapcache_context *ctx, mapcache_dimension *dim,
    ezxml_t node)
{
  mapcache_dimension_values *dimension;
  ezxml_t child_node = ezxml_child(node,"value");
  dimension = (mapcache_dimension_values*)dim;
  
  if(!child_node) {
    ctx->set_error(ctx,400,"failed to parse dimension values: no <value> children supplied");
    return;
  }
  for(; child_node; child_node = child_node->next) {
    const char* entry = child_node->txt;
    if(!entry || !*entry) {
      ctx->set_error(ctx,400,"failed to parse dimension values: empty <value>");
      return;
    }
    APR_ARRAY_PUSH(dimension->values,char*) = apr_pstrdup(ctx->pool,entry);
  }

  child_node = ezxml_child(node,"case_sensitive");
  if(child_node && child_node->txt) {
    if(!strcasecmp(child_node->txt,"true")) {
      dimension->case_sensitive = 1;
    }
  }

  if(!dimension->values->nelts) {
    ctx->set_error(ctx, 400, "<dimension> \"%s\" has no values",dim->name);
    return;
  }
}
예제 #10
0
/**
 * \private \memberof mapcache_source_wms
 * \sa mapcache_source::configuration_parse()
 */
void _mapcache_source_wms_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_source *source)
{
  ezxml_t cur_node;
  mapcache_source_wms *src = (mapcache_source_wms*)source;


  if ((cur_node = ezxml_child(node,"getmap")) != NULL) {
    ezxml_t gm_node;
    if ((gm_node = ezxml_child(cur_node,"params")) != NULL) {
      for(gm_node = gm_node->child; gm_node; gm_node = gm_node->sibling) {
        apr_table_set(src->getmap_params, gm_node->name, gm_node->txt);
      }
    } else {
      ctx->set_error(ctx,400,"wms source %s <getmap> has no <params> block (should contain at least <LAYERS> child)",source->name);
      return;
    }
  } else {
    ctx->set_error(ctx,400,"wms source %s has no <getmap> block",source->name);
    return;
  }
  if ((cur_node = ezxml_child(node,"getfeatureinfo")) != NULL) {
    ezxml_t fi_node;
    if ((fi_node = ezxml_child(cur_node,"info_formats")) != NULL) {
      char *key,*last;
      char *iformats;
      source->info_formats = apr_array_make(ctx->pool,3,sizeof(char*));
      iformats = apr_pstrdup(ctx->pool,fi_node->txt);

      for (key = apr_strtok(iformats, "," , &last); key != NULL;
           key = apr_strtok(NULL, ",", &last)) {
        APR_ARRAY_PUSH(source->info_formats,char*) = key;
      }
    } else {
예제 #11
0
파일: xml.c 프로젝트: arichnad/pianobar
/*	parse stations returned by pandora
 *	@param piano handle
 *	@param xml returned by pandora
 *	@return _RET_OK or error
 */
PianoReturn_t PianoXmlParseStations (PianoHandle_t *ph, char *xml) {
	ezxml_t xmlDoc, dataNode;
	PianoReturn_t ret;
	char **quickMixIds = NULL, **curQuickMixId = NULL;

	if ((ret = PianoXmlInitDoc (xml, &xmlDoc)) != PIANO_RET_OK) {
		return ret;
	}

	dataNode = ezxml_get (xmlDoc, "params", 0, "param", 0, "value", 0, "array",
			0, "data", -1);

	for (dataNode = ezxml_child (dataNode, "value"); dataNode;
			dataNode = dataNode->next) {
		PianoStation_t *tmpStation;

		if ((tmpStation = calloc (1, sizeof (*tmpStation))) == NULL) {
			ezxml_free (xmlDoc);
			return PIANO_RET_OUT_OF_MEMORY;
		}

		PianoXmlStructParser (ezxml_child (dataNode, "struct"),
				PianoXmlParseStationsCb, tmpStation);

		/* get stations selected for quickmix */
		if (tmpStation->isQuickMix) {
			PianoXmlStructParser (ezxml_child (dataNode, "struct"),
					PianoXmlParseQuickMixStationsCb, &quickMixIds);
		}
		/* start new linked list or append */
		if (ph->stations == NULL) {
			ph->stations = tmpStation;
		} else {
			PianoStation_t *curStation = ph->stations;
			while (curStation->next != NULL) {
				curStation = curStation->next;
			}
			curStation->next = tmpStation;
		}
	}
	/* set quickmix flags after all stations are read */
	if (quickMixIds != NULL) {
		curQuickMixId = quickMixIds;
		while (*curQuickMixId != NULL) {
			PianoStation_t *curStation = PianoFindStationById (ph->stations,
					*curQuickMixId);
			if (curStation != NULL) {
				curStation->useQuickMix = 1;
			}
			free (*curQuickMixId);
			curQuickMixId++;
		}
		free (quickMixIds);
	}

	ezxml_free (xmlDoc);

	return PIANO_RET_OK;
}
예제 #12
0
파일: xml.c 프로젝트: arichnad/pianobar
/*	callback for xml struct parser used in PianoXmlParseSearch, "switch" for
 *	PianoXmlParseSearchArtistCb and PianoXmlParsePlaylistCb
 */
static void PianoXmlParseSearchCb (const char *key, const ezxml_t value,
		void *data) {
	PianoSearchResult_t *searchResult = data;
	ezxml_t curNode;

	if (strcmp ("artists", key) == 0) {
		/* skip <value><array><data> */
		for (curNode = ezxml_child (ezxml_get (value, "array", 0, "data", -1), "value");
				curNode; curNode = curNode->next) {
			PianoArtist_t *artist;
			
			if ((artist = calloc (1, sizeof (*artist))) == NULL) {
				/* fail silently */
				break;
			}

			memset (artist, 0, sizeof (*artist));

			PianoXmlStructParser (ezxml_child (curNode, "struct"),
					PianoXmlParseSearchArtistCb, artist);

			/* add result to linked list */
			if (searchResult->artists == NULL) {
				searchResult->artists = artist;
			} else {
				PianoArtist_t *curArtist = searchResult->artists;
				while (curArtist->next != NULL) {
					curArtist = curArtist->next;
				}
				curArtist->next = artist;
			}
		}
	} else if (strcmp ("songs", key) == 0) {
		for (curNode = ezxml_child (ezxml_get (value, "array", 0, "data", -1), "value");
				curNode; curNode = curNode->next) {
			/* FIXME: copy & waste */
			PianoSong_t *tmpSong;
			
			if ((tmpSong = calloc (1, sizeof (*tmpSong))) == NULL) {
				/* fail silently */
				break;
			}

			PianoXmlStructParser (ezxml_child (curNode, "struct"),
					PianoXmlParsePlaylistCb, tmpSong);
			/* begin linked list or append */
			if (searchResult->songs == NULL) {
				searchResult->songs = tmpSong;
			} else {
				PianoSong_t *curSong = searchResult->songs;
				while (curSong->next != NULL) {
					curSong = curSong->next;
				}
				curSong->next = tmpSong;
			}
		}
	}
}
예제 #13
0
파일: xml.c 프로젝트: MikeBrWade/pianobar
/*	parse getStation xml struct
 */
static void PianoXmlParseGetStationInfoCb (const char *key, const ezxml_t value,
		void *data) {
	PianoStationInfo_t *info = data;

	if (strcmp ("seeds", key) == 0) {
		const ezxml_t dataNode = ezxml_get (value, "array", 0, "data", -1);
		for (ezxml_t seedNode = ezxml_child (dataNode, "value"); seedNode;
					seedNode = seedNode->next) {
			struct PianoXmlParseSeedBag bag;
			memset (&bag, 0, sizeof (bag));

			PianoXmlStructParser (ezxml_child (seedNode, "struct"),
					PianoXmlParseSeedCb, &bag);

			/* FIXME: use if-clause */
			assert (bag.seedId != NULL);
			assert (bag.song != NULL || bag.artist != NULL);

			if (bag.song != NULL) {
				bag.song->seedId = bag.seedId;

				if (info->songSeeds == NULL) {
					info->songSeeds = bag.song;
				} else {
					PianoSong_t *curSong = info->songSeeds;
					while (curSong->next != NULL) {
						curSong = curSong->next;
					}
					curSong->next = bag.song;
				}
			} else if (bag.artist != NULL) {
				bag.artist->seedId = bag.seedId;

				if (info->artistSeeds == NULL) {
					info->artistSeeds = bag.artist;
				} else {
					PianoArtist_t *curSong = info->artistSeeds;
					while (curSong->next != NULL) {
						curSong = curSong->next;
					}
					curSong->next = bag.artist;
				}
			} else {
				free (bag.seedId);
			}
		}
	} else if (strcmp ("feedback", key) == 0) {
		const ezxml_t dataNode = ezxml_get (value, "array", 0, "data", -1);
		for (ezxml_t feedbackNode = ezxml_child (dataNode, "value"); feedbackNode;
					feedbackNode = feedbackNode->next) {
			if (PianoXmlParsePlaylistStruct (feedbackNode, &info->feedback) !=
					PIANO_RET_OK) {
				break;
			}
		}
	}
}
예제 #14
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;
}
예제 #15
0
int generate_namelist(ezxml_t registry, FILE* fd, int pairs, char **keys, char **values){/*{{{*/
	ezxml_t nmlrecs_xml, nmlopt_xml;

	const char *recname;
	const char *optname, *opttype;
	char *optval;

	int write_opt, write_record, record_written;
	int i;

	for (nmlrecs_xml = ezxml_child(registry, "nml_record"); nmlrecs_xml; nmlrecs_xml = nmlrecs_xml->next){
		recname = ezxml_attr(nmlrecs_xml, "name");

		record_written = 0;
		write_record = is_structure_writable(nmlrecs_xml, pairs, keys, values);

		/* If record doesn't have a key, record is writeable */
		if ( write_record == -1 ) write_record = 1;

		if ( write_record == 1 ) {
			fprintf(fd, "&%s\n", recname);
			record_written = 1;
		}

		for (nmlopt_xml = ezxml_child(nmlrecs_xml, "nml_option"); nmlopt_xml; nmlopt_xml = nmlopt_xml->next){
			optname = ezxml_attr(nmlopt_xml, "name");
			opttype = ezxml_attr(nmlopt_xml, "type");

			write_opt = is_structure_writable(nmlopt_xml, pairs, keys, values);

			if ( write_opt == 1 || ( write_opt == -1 && write_record == 1) ){
				if ( !record_written ) {
					fprintf(fd, "&%s\n", recname);
					record_written = 1;
				}

				optval = get_option_value(nmlopt_xml, pairs, values);

				if ( strcmp(opttype, "character") == 0){
					fprintf(fd, "    %s = '%s'\n", optname, optval);
				} else {
					fprintf(fd, "    %s = %s\n", optname, optval);
				}

				free(optval);
			}
		}

		if ( record_written ) {
			fprintf(fd, "/\n");
		}
	}

	return 0;
}/*}}}*/
예제 #16
0
/**
 * \private \memberof mapcache_cache_memcache
 */
static void _mapcache_cache_memcache_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config) {
   ezxml_t cur_node;
   mapcache_cache_memcache *dcache = (mapcache_cache_memcache*)cache;
   int servercount = 0;
   for(cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) {
      servercount++;
   }
   if(!servercount) {
      ctx->set_error(ctx,400,"memcache cache %s has no <server>s configured",cache->name);
      return;
   }
   if(APR_SUCCESS != apr_memcache_create(ctx->pool, servercount, 0, &dcache->memcache)) {
      ctx->set_error(ctx,400,"cache %s: failed to create memcache backend", cache->name);
      return;
   }
   for(cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) {
      ezxml_t xhost = ezxml_child(cur_node,"host");
      ezxml_t xport = ezxml_child(cur_node,"port");
      const char *host;
      apr_memcache_server_t *server;
      apr_port_t port;
      if(!xhost || !xhost->txt || ! *xhost->txt) {
         ctx->set_error(ctx,400,"cache %s: <server> with no <host>",cache->name);
         return;
      } else {
         host = apr_pstrdup(ctx->pool,xhost->txt);
      }

      if(!xport || !xport->txt || ! *xport->txt) {
         ctx->set_error(ctx,400,"cache %s: <server> with no <port>", cache->name);
         return;
      } else {
         char *endptr;
         int iport = (int)strtol(xport->txt,&endptr,10);
         if(*endptr != 0) {
            ctx->set_error(ctx,400,"failed to parse value %s for memcache cache %s", xport->txt,cache->name);
            return;
         }
         port = iport;
      }
      if(APR_SUCCESS != apr_memcache_server_create(ctx->pool,host,port,4,5,50,10000,&server)) {
         ctx->set_error(ctx,400,"cache %s: failed to create server %s:%d",cache->name,host,port);
         return;
      }
      if(APR_SUCCESS != apr_memcache_add_server(dcache->memcache,server)) {
         ctx->set_error(ctx,400,"cache %s: failed to add server %s:%d",cache->name,host,port);
         return;
      }
      if(APR_SUCCESS != apr_memcache_set(dcache->memcache,"mapcache_test_key","mapcache",8,0,0)) {
         ctx->set_error(ctx,400,"cache %s: failed to add test key to server %s:%d",cache->name,host,port);
         return;
      }
   }
}
예제 #17
0
/**
 * \private \memberof mapcache_cache_riak
 */
static void _mapcache_cache_riak_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config) {
    ezxml_t cur_node,xhost,xport,xbucket;
    mapcache_cache_riak *dcache = (mapcache_cache_riak*)cache;
    int servercount = 0;

    for (cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) {
        servercount++;
    }

    if (!servercount) {
        ctx->set_error(ctx, 400, "riak cache %s has no <server>s configured", cache->name);
        return;
    }

    if (servercount > 1) {
        ctx->set_error(ctx, 400, "riak cache %s has more than 1 server configured", cache->name);
        return;
    }

    cur_node = ezxml_child(node, "server");
    xhost = ezxml_child(cur_node, "host");   /* Host should contain just server */
    xport = ezxml_child(cur_node, "port");
    xbucket = ezxml_child(cur_node, "bucket");

    if (!xhost || !xhost->txt || ! *xhost->txt) {
        ctx->set_error(ctx, 400, "cache %s: <server> with no <host>", cache->name);
        return;
    } else {
        dcache->host = apr_pstrdup(ctx->pool, xhost->txt);
        if (dcache->host == NULL) {
            ctx->set_error(ctx, 400, "cache %s: failed to allocate host string!", cache->name);
            return;
        }
    }

    if (!xport || !xport->txt || ! *xport->txt) {
        ctx->set_error(ctx, 400, "cache %s: <server> with no <port>", cache->name);
        return;
    } else {
        dcache->port = atoi(xport->txt);
    }

    if (!xbucket || !xbucket->txt || ! *xbucket->txt) {
        ctx->set_error(ctx, 400, "cache %s: <server> with no <bucket>", cache->name);
        return;
    } else {
        dcache->bucket.value = apr_pstrdup(ctx->pool, xbucket->txt);
        if (dcache->bucket.value == NULL) {
            ctx->set_error(ctx, 400, "cache %s: failed to allocate bucket string!", cache->name);
            return;
        }
        dcache->bucket.len = strlen(dcache->bucket.value);
    }
}
예제 #18
0
파일: http.c 프로젝트: umeier/mapcache
mapcache_http* mapcache_http_configuration_parse_xml(mapcache_context *ctx, ezxml_t node)
{
  ezxml_t http_node;
  mapcache_http *req;
  curl_global_init(CURL_GLOBAL_ALL);
#ifdef DEBUG
  /* make valgrind happy */
  apr_pool_cleanup_register(ctx->pool, NULL,(void*)http_cleanup, apr_pool_cleanup_null);
#endif
  req = (mapcache_http*)apr_pcalloc(ctx->pool,
                                    sizeof(mapcache_http));
  if ((http_node = ezxml_child(node,"url")) != NULL) {
    req->url = apr_pstrdup(ctx->pool,http_node->txt);
  }
  if(!req->url) {
    ctx->set_error(ctx,400,"got an <http> object with no <url>");
    return NULL;
  }

  if ((http_node = ezxml_child(node,"connection_timeout")) != NULL) {
    char *endptr;
    req->connection_timeout = (int)strtol(http_node->txt,&endptr,10);
    if(*endptr != 0 || req->connection_timeout<1) {
      ctx->set_error(ctx,400,"invalid <http> <connection_timeout> \"%s\" (positive integer expected)",
                     http_node->txt);
      return NULL;
    }
  } else {
    req->connection_timeout = 30;
  }
  
  if ((http_node = ezxml_child(node,"timeout")) != NULL) {
    char *endptr;
    req->timeout = (int)strtol(http_node->txt,&endptr,10);
    if(*endptr != 0 || req->timeout<1) {
      ctx->set_error(ctx,400,"invalid <http> <timeout> \"%s\" (positive integer expected)",
                     http_node->txt);
      return NULL;
    }
  } else {
    req->timeout = 600;
  }

  req->headers = apr_table_make(ctx->pool,1);
  if((http_node = ezxml_child(node,"headers")) != NULL) {
    ezxml_t header_node;
    for(header_node = http_node->child; header_node; header_node = header_node->sibling) {
      apr_table_set(req->headers, header_node->name, header_node->txt);
    }
  }
  return req;
  /* TODO: parse <proxy> and <auth> elements */
}
예제 #19
0
/**
 * \private \memberof mapcache_cache_disk
 */
static void _mapcache_cache_disk_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config)
{
  ezxml_t cur_node;
  mapcache_cache_disk *dcache = (mapcache_cache_disk*)cache;
  char *layout = NULL;
  int template_layout = MAPCACHE_FALSE;

  layout = (char*)ezxml_attr(node,"layout");
  if (!layout || !strlen(layout) || !strcmp(layout,"tilecache")) {
    dcache->tile_key = _mapcache_cache_disk_tilecache_tile_key;
  } else if(!strcmp(layout,"arcgis")) {
    dcache->tile_key = _mapcache_cache_disk_arcgis_tile_key;
  } else if (!strcmp(layout,"template")) {
    dcache->tile_key = _mapcache_cache_disk_template_tile_key;
    template_layout = MAPCACHE_TRUE;
    if ((cur_node = ezxml_child(node,"template")) != NULL) {
      dcache->filename_template = apr_pstrdup(ctx->pool,cur_node->txt);
    } else {
      ctx->set_error(ctx, 400, "no template specified for cache \"%s\"", cache->name);
      return;
    }
  } else {
    ctx->set_error(ctx, 400, "unknown layout type %s for cache \"%s\"", layout, cache->name);
    return;
  }

  if (!template_layout && (cur_node = ezxml_child(node,"base")) != NULL) {
    dcache->base_directory = apr_pstrdup(ctx->pool,cur_node->txt);
  }

  if (!template_layout && (cur_node = ezxml_child(node,"symlink_blank")) != NULL) {
    if(strcasecmp(cur_node->txt,"false")) {
#ifdef HAVE_SYMLINK
      dcache->symlink_blank=1;
#else
      ctx->set_error(ctx,400,"cache %s: host system does not support file symbolic linking",cache->name);
      return;
#endif
    }
  }

  if ((cur_node = ezxml_child(node,"creation_retry")) != NULL) {
    dcache->creation_retry = atoi(cur_node->txt);
  }
  
  if ((cur_node = ezxml_child(node,"maxzoom")) != NULL) 
  {
    dcache->maxzoom = atoi(cur_node->txt);
  }
  
}
예제 #20
0
/**
 * \private \memberof mapcache_source_gdal
 * \sa mapcache_source::configuration_parse()
 */
void _mapcache_source_gdal_configuration_parse(mapcache_context *ctx, ezxml_t node, mapcache_source *source)
{
  ezxml_t cur_node;
  mapcache_source_gdal *src = (mapcache_source_gdal*)source;

  if ((cur_node = ezxml_child(node,"data")) != NULL) {
    src->datastr = apr_pstrdup(ctx->pool,cur_node->txt);
  }

  if ((cur_node = ezxml_child(node,"gdalparams")) != NULL) {
    for(cur_node = cur_node->child; cur_node; cur_node = cur_node->sibling) {
      apr_table_set(src->gdal_params, cur_node->name, cur_node->txt);
    }
  }
}
예제 #21
0
void parseDimensions(mapcache_context *ctx, ezxml_t node, mapcache_tileset *tileset) {
   ezxml_t dimension_node;
   apr_array_header_t *dimensions = apr_array_make(ctx->pool,1,sizeof(mapcache_dimension*));
   for(dimension_node = ezxml_child(node,"dimension"); dimension_node; dimension_node = dimension_node->next) {
      char *name = (char*)ezxml_attr(dimension_node,"name");
      char *type = (char*)ezxml_attr(dimension_node,"type");
      char *unit = (char*)ezxml_attr(dimension_node,"unit");
      char *default_value = (char*)ezxml_attr(dimension_node,"default");
      
      mapcache_dimension *dimension = NULL;
      
      if(!name || !strlen(name)) {
         ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <dimension>");
         return;
      }

      if(type && *type) {
         if(!strcmp(type,"values")) {
            dimension = mapcache_dimension_values_create(ctx->pool);
         } else if(!strcmp(type,"regex")) {
            dimension = mapcache_dimension_regex_create(ctx->pool);
         } else if(!strcmp(type,"intervals")) {
            dimension = mapcache_dimension_intervals_create(ctx->pool);
         } else if(!strcmp(type,"time")) {
            ctx->set_error(ctx,501,"time dimension type not implemented yet");
            return;
            dimension = mapcache_dimension_time_create(ctx->pool);
         } else {
            ctx->set_error(ctx,400,"unknown dimension type \"%s\"",type);
            return;
         }
      } else {
         ctx->set_error(ctx,400, "mandatory attribute \"type\" not found in <dimensions>");
         return;
      }

      dimension->name = apr_pstrdup(ctx->pool,name);

      if(unit && *unit) {
         dimension->unit = apr_pstrdup(ctx->pool,unit);
      }

      if(default_value && *default_value) {
         dimension->default_value = apr_pstrdup(ctx->pool,default_value);
      } else {
         ctx->set_error(ctx,400,"dimension \"%s\" has no \"default\" attribute",dimension->name);
         return;
      }

      dimension->configuration_parse_xml(ctx,dimension,dimension_node);
      GC_CHECK_ERROR(ctx);

      APR_ARRAY_PUSH(dimensions,mapcache_dimension*) = dimension;
   }
   if(apr_is_empty_array(dimensions)) {
      ctx->set_error(ctx, 400, "<dimensions> for tileset \"%s\" has no dimensions defined (expecting <dimension> children)",tileset->name);
      return;
   }
   tileset->dimensions = dimensions;
}
예제 #22
0
파일: xml2dom.c 프로젝트: Joouis/EVGUI
dom_exception dom_element_get_elements_by_tag_name(dom_element *element, dom_string *string, dom_nodelist **outNodeList) {
  dom_nodelist *result = NULL;
  dom_element **nodeList = NULL;
  int nodeCount = 0;
  for (ezxml_t candidate = ezxml_child(element->node, string->s); candidate; candidate = candidate->next) {
      if (NULL == nodeList) {
        nodeList = (dom_element **)malloc(nodeCount * sizeof(dom_element *));
      } else {
        dom_element **t = realloc(nodeList, (1+nodeCount) * sizeof(dom_element *));
        if (t) {
          nodeList = t;
        } else {
          for (int i = 0; i < nodeCount; ++i) {
            dom_node_unref(nodeList[i]);
          }
          free(nodeList);
          *outNodeList = result;
          return DOM_MEM_ERR;
        }
      }
      dom_element *elem = (dom_element *)calloc(sizeof(dom_element), 1);
      elem->node = candidate;
      elem->ref = 1;
      nodeList[nodeCount++] = elem;
  }
  if (nodeCount) {
    result = calloc(sizeof(dom_nodelist), 1);
    result->nodes = nodeList;
    result->count = nodeCount;
    result->ref = 1;
  }
  *outNodeList = result;
  return DOM_NO_ERR;
}
예제 #23
0
/* ------------------------------------------------------------------------- */
int Reg_Get(Reg_TRegistry* reg, const ezxml_t keys, ezxml_t items)
{
    ezxml_t key;

    assert(reg);

    key = keys->child;
    if (key)
    {
        do
        {
            ezxml_t item;
            if ((item = ezxml_child(reg->m_root, ezxml_txt(key))) &&
                            ezxml_name(item))
            {
                ezxml_t child = ezxml_add_child_d(items, ezxml_name(item), 0);
                ezxml_set_txt_d(child, ezxml_txt(item));
            }
        } while((key = key->ordered));
    }
    else
    {
        ezxml_t item = reg->m_root->child;
        while(item)
        {
            ezxml_t child = ezxml_add_child_d(items, ezxml_name(item), 0);
            ezxml_set_txt_d(child, ezxml_txt(item));

            item = item->ordered;
        }
    }

    return -EXIT_SUCCESS;
}
예제 #24
0
int is_unique_struct(ezxml_t current_position, ezxml_t check_struct, const char *check_name){/*{{{*/
	ezxml_t struct_xml;

	const char *name;

	int test;


	test = 1;

	for(struct_xml = ezxml_child(current_position, "var_struct"); struct_xml; struct_xml = struct_xml->next){
		name = ezxml_attr(struct_xml, "name");

		if(strcmp(name, check_name) == 0 && struct_xml != check_struct){
			return 0;
		} else {
			test = is_unique_struct(struct_xml, check_struct, check_name);
			if ( !test ) {
				return 0;
			}
		}
	}

	return 1;
}/*}}}*/
예제 #25
0
/* Finds child element with given name and returns it. Errors out if
 * more than one instance exists. */
ezxml_t
FindElement(INP ezxml_t Parent, INP const char *Name, INP boolean Required)
{
    ezxml_t Cur;

        /* Find the first node of correct name */
        Cur = ezxml_child(Parent, Name);

        /* Error out if node isn't found but they required it */
        if(Required)
        {
            if(NULL == Cur)
                {
                    printf(ERRTAG
                            "[LINE %d] Element '%s' not found within element '%s'.\n", Parent->line,
							Name, Parent->name);
                    exit(1);
                }
        }

        /* Look at next tag with same name and error out if exists */
        if(Cur != NULL && Cur->next)
        {
            printf(ERRTAG "[LINE %d] Element '%s' found twice within element '%s'.\n", Parent->line,
                    Name, Parent->name);
            exit(1);
        }
    return Cur;
}
예제 #26
0
/**
 * \private \memberof mapcache_source_mapserver
 * \sa mapcache_source::configuration_parse()
 */
void _mapcache_source_mapserver_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_source *source) {
   ezxml_t cur_node;
   mapcache_source_mapserver *src = (mapcache_source_mapserver*)source;
   if ((cur_node = ezxml_child(node,"mapfile")) != NULL) {
      src->mapfile = apr_pstrdup(ctx->pool,cur_node->txt);
   }
}
예제 #27
0
파일: xml.c 프로젝트: hunner/pianobarfly
static PianoReturn_t PianoXmlParsePlaylistStruct (ezxml_t xml,
		PianoSong_t **retSong) {
	PianoSong_t *playlist = *retSong, *tmpSong;
	
	if ((tmpSong = calloc (1, sizeof (*tmpSong))) == NULL) {
		return PIANO_RET_OUT_OF_MEMORY;
	}

	PianoXmlStructParser (ezxml_child (xml, "struct"), PianoXmlParsePlaylistCb,
			tmpSong);
	/* begin linked list or append */
	if (playlist == NULL) {
		playlist = tmpSong;
	} else {
		PianoSong_t *curSong = playlist;
		while (curSong->next != NULL) {
			curSong = curSong->next;
		}
		curSong->next = tmpSong;
	}

	*retSong = playlist;

	return PIANO_RET_OK;
}
/*
 * create_automatons_from_xml
 *
 * Once this functions is complete all the structure will be in place in the 
 * automaton_set to fill in the names of the automatons and transitions.

 * It goes through the file twice. The first time counting the number of 
 * automatons and then allocating the memory required for that number.
 * The second time it creates each of the automatons and puts them into the
 * automaton set.
 *
 * They get entered into the array in the order that they appear in the file.
 *
 * Parameters: xml_file - A reference to the structure that contains the entire
 *                        xml.
 *             automaton_set - The collection of automatons to be filled in.
 *             state_callback - Callback function to generate the states for
 *                              each of the automatons.
 *             event_callback - Callback function to generate the events for
 *                              each of the automatons.
 */
void create_automatons_from_xml(ezxml_t *xml_file, 
                                AUTOMATON_SET *automaton_set,
                                int (*state_callback)(AUTOMATON_STATE ***,int),
                                int (*event_callback)(AUTOMATON_EVENT ***))
{
  /*
   * Local Variables.
   */
  int ii;
  int num_automatons;
  ezxml_t xml_automaton;

  /*
   * Count the number of automaton objects in this file. We need to know this
   * so that we allocate the memory for the automaton array.
   */
  num_automatons = 0;
  for (xml_automaton = ezxml_child(*xml_file, "automaton");
       xml_automaton;
       xml_automaton = xml_automaton->next)
  {
    num_automatons++;
  }
  automaton_set->num_automatons = num_automatons;

  /*
   * Attempt to allocate the memory for the automaton array.
   */
  automaton_set->automaton_array =
                (AUTOMATON **) DT_MALLOC(sizeof(AUTOMATON *) * num_automatons);

  /*
   * Create each of the automatons individually.
   */
  ii = 0;
  for (xml_automaton = ezxml_child(*xml_file, "automaton");
       xml_automaton;
       xml_automaton = xml_automaton->next)
  {
    /*
     * This allocated the memory and sets up the state, event tables.
     */
    automaton_set->automaton_array[ii] = create_automaton(state_callback,
                                                          event_callback);
    ii++;
  }
}
예제 #29
0
static void _mapcache_cache_tc_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config)
{
  ezxml_t cur_node;
  mapcache_cache_tc *dcache = (mapcache_cache_tc*)cache;
  if ((cur_node = ezxml_child(node,"base")) != NULL) {
    dcache->basedir = apr_pstrdup(ctx->pool,cur_node->txt);
  }
  if ((cur_node = ezxml_child(node,"key_template")) != NULL) {
    dcache->key_template = apr_pstrdup(ctx->pool,cur_node->txt);
  } else {
    dcache->key_template = apr_pstrdup(ctx->pool,"{tileset}-{grid}-{dim}-{z}-{y}-{x}.{ext}");
  }
  if(!dcache->basedir) {
    ctx->set_error(ctx,500,"tokyocabinet cache \"%s\" is missing <base> entry",cache->name);
    return;
  }
}
예제 #30
0
/**
 * \private \memberof mapcache_cache_memcache
 */
static void _mapcache_cache_memcache_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config)
{
  ezxml_t cur_node;
  int i = 0;
  mapcache_cache_memcache *dcache = (mapcache_cache_memcache*)cache;
  for(cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) {
    dcache->nservers++;
  }
  if(!dcache->nservers) {
    ctx->set_error(ctx,400,"memcache cache %s has no <server>s configured",cache->name);
    return;
  }
  dcache->servers = apr_pcalloc(ctx->pool, dcache->nservers * sizeof(struct mapcache_cache_memcache_server));

  for(cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) {
    ezxml_t xhost = ezxml_child(cur_node,"host");
    ezxml_t xport = ezxml_child(cur_node,"port");
    if(!xhost || !xhost->txt || ! *xhost->txt) {
      ctx->set_error(ctx,400,"cache %s: <server> with no <host>",cache->name);
      return;
    } else {
      dcache->servers[i].host = apr_pstrdup(ctx->pool,xhost->txt);
    }

    if(!xport || !xport->txt || ! *xport->txt) {
      ctx->set_error(ctx,400,"cache %s: <server> with no <port>", cache->name);
      return;
    } else {
      char *endptr;
      int iport = (int)strtol(xport->txt,&endptr,10);
      if(*endptr != 0) {
        ctx->set_error(ctx,400,"failed to parse value %s for memcache cache %s", xport->txt,cache->name);
        return;
      }
      dcache->servers[i].port = iport;
    }
    i++;
  }
  
  dcache->detect_blank = 0;
  if ((cur_node = ezxml_child(node, "detect_blank")) != NULL) {
    if(!strcasecmp(cur_node->txt,"true")) {
      dcache->detect_blank = 1;
    }
  }
}