Ejemplo n.º 1
0
bool JSONReader::parseAll(const std::string& text, IdType& nextId, std::string& filepath, std::string& checksum,
    std::vector<std::shared_ptr<MetadataStream::VideoSegment>>& segments,
    std::vector<std::shared_ptr<MetadataSchema>>& schemas,
    std::vector<std::shared_ptr<MetadataInternal>>& metadata)
{
    if(text.empty())
    {
        VMF_LOG_ERROR("Empty input JSON string");
        return false;
    }

    schemas.clear();
    metadata.clear();

    JSONNode root;
    try
    {
        root = libjson::parse(text);
    }
    catch(...)
    {
        VMF_LOG_ERROR("Can't get JSON root");
        return false;
    }

    if(root.size() != 1)
    {
        VMF_LOG_ERROR("More than one JSON root");
        return false;
    }

    JSONNode localRootNode = root[0];

    if( localRootNode.name() == TAG_VMF )
    {
        auto nextIdIter = localRootNode.find(ATTR_VMF_NEXTID);
        if(nextIdIter != localRootNode.end() )
            nextId = nextIdIter->as_int();
        auto filepathIter = localRootNode.find(ATTR_VMF_FILEPATH);
        if(filepathIter != localRootNode.end() )
            filepath = filepathIter->as_string();
        auto checksumIter = localRootNode.find(ATTR_VMF_CHECKSUM);
        if(checksumIter != localRootNode.end() )
            checksum = checksumIter->as_string();

	if(!parseVideoSegments(text, segments))
	    return false;
        if(!parseSchemas(text, schemas))
            return false;
        if(!parseMetadata(text, schemas, metadata))
            return false;
    }
    else
    {
        VMF_LOG_ERROR("Root JSON element isn't 'vmf'");
        return false;
    }

    return true;
}
Ejemplo n.º 2
0
std::vector<std::string> MDAL::LoaderGdal::parseDatasetNames( const std::string &fileName )
{
  std::string gdal_name = GDALFileName( fileName );
  std::vector<std::string> ret;

  GDALDatasetH hDataset = GDALOpen( gdal_name.data(), GA_ReadOnly );
  if ( hDataset == nullptr ) throw MDAL_Status::Err_UnknownFormat;

  metadata_hash metadata = parseMetadata( hDataset, "SUBDATASETS" );

  for ( auto iter = metadata.begin(); iter != metadata.end(); ++iter )
  {
    const std::string &key =  iter->first;

    if ( MDAL::endsWith( key, "_name" ) )
    {
      // skip subdataset desc keys, just register names
      ret.push_back( iter->second );
    }
  }

  // there are no GDAL subdatasets
  if ( ret.empty() )
  {
    ret.push_back( gdal_name );
  }

  GDALClose( hDataset );
  return ret;
}
shared_ptr<FDSObjectMetadata> GalaxyFDSClient::getObjectMetadata(const string&
    bucketName, const string& objectName) {
  vector<string> subResources;
  subResources.push_back(SubResource::METADATA);
  string uri = formatUri(_pConfig->getBaseUri(), bucketName + "/" + objectName,
      subResources);
  URI pocoUri(uri);

  shared_ptr<HTTPClientSession> pSession(_pSessionFacotry->createClientSession(
        pocoUri));
  pSession->setHost(pocoUri.getHost());
  pSession->setPort(pocoUri.getPort());
  HTTPRequest request(HTTPRequest::HTTP_GET, uri, HTTPMessage::HTTP_1_1);
  prepareRequestHeaders(uri, HTTPRequest::HTTP_GET, "", _emptyStream,
      *_pEmptyMetadata, request);
  HTTPResponse response;

  pSession->sendRequest(request);
  istream& rs = pSession->receiveResponse(response);

  if (response.getStatus() != HTTPResponse::HTTP_OK) {
    stringstream msg;
    msg << "Get object metadata failed, status=" << response.getStatus()
      << ", reason=";
    StreamCopier::copyStream(rs, msg);
    throw GalaxyFDSClientException(response.getStatus(), msg.str());
  }

  return parseMetadata(response);
}
Ejemplo n.º 4
0
void SM_QDropbox::parseBlockingMetadata(QString response)
{
    clearError();
    parseMetadata(response);
    stopEventLoop();
    return;
}
Ejemplo n.º 5
0
void StatTool::parseGroup(xercesc::DOMElement * parentNode, 
                          crispr::xml::base& xmlParser)
{
    
    StatManager * sm = new StatManager();
    ST_StatsVec.push_back(sm);
    char * c_cons = tc(parentNode->getAttribute(xmlParser.attr_Drseq()));
    std::string concensusRepeat =c_cons;
    sm->setConcensus(concensusRepeat);
    xr(&c_cons);

    char * c_gid = tc(parentNode->getAttribute(xmlParser.attr_Gid()));
    std::string gid = c_gid;
    xr(&c_gid);
    sm->setGid(gid);
    
    
    for (xercesc::DOMElement * currentElement = parentNode->getFirstElementChild(); 
         currentElement != NULL; 
         currentElement = currentElement->getNextElementSibling()) {

        if (xercesc::XMLString::equals(currentElement->getTagName(), xmlParser.tag_Data())) {
            parseData(currentElement, xmlParser, sm);
        } else if (xercesc::XMLString::equals(currentElement->getTagName(), xmlParser.tag_Metadata())) {
            parseMetadata(currentElement, xmlParser, sm);
        }
    }
}
Ejemplo n.º 6
0
Word parseWord(QString word) {
    Word ret;
    if(word.startsWith("<")) { // lines with words start with this.
        QStringList split = word.split("#");
        for(int i = 0; i < split.length(); i++) {
            QString part = split[i];
            switch(i) {
                case 0: // first part, contains some magic and the word
                    parseMetadata(part, &ret); // parses the meta data between <>
                    part = part.remove(0, part.indexOf('>') + 1); // take of the stuff between <>
                                                                  // TODO: find out what it is
                    if(part.contains('.')) {
                        // end of sentence, put the linkedWords right here.
                        
                    }
                    ret.setWord(part.trimmed());
                    break;
                case 1: // second part, contains the meaning
                    ret.setMeaning(part.trimmed());
                    break;
                case 2: // third part, contains the grammar
                    ret.setGrammar(part.trimmed());
                    break;
                case 3: // fourth part, contains the word to look up in the dictionary
                    ret.setDictionary(part.trimmed());
                    break;
            }
        }
    }
    return ret;
}
Ejemplo n.º 7
0
bool OsmAnd::MapStyle_P::parseMetadata()
{
    if(owner->isEmbedded)
    {
        QXmlStreamReader data(EmbeddedResources::decompressResource(owner->resourcePath));
        return parseMetadata(data);
    }
    else
    {
        QFile styleFile(owner->resourcePath);
        if(!styleFile.open(QIODevice::ReadOnly | QIODevice::Text))
            return false;
        QXmlStreamReader data(&styleFile);
        bool ok = parseMetadata(data);
        styleFile.close();
        return ok;
    }

    return false;
}
Ejemplo n.º 8
0
void parseSource(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
{
  ezxml_t cur_node;
  char *name = NULL, *type = NULL;
  mapcache_source *source;

  name = (char*)ezxml_attr(node,"name");
  type = (char*)ezxml_attr(node,"type");
  if(!name || !strlen(name)) {
    ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <source>");
    return;
  } else {
    name = apr_pstrdup(ctx->pool, name);
    /* check we don't already have a source defined with this name */
    if(mapcache_configuration_get_source(config, name)) {
      ctx->set_error(ctx, 400, "duplicate source with name \"%s\"",name);
      return;
    }
  }
  if(!type || !strlen(type)) {
    ctx->set_error(ctx, 400, "mandatory attribute \"type\" not found in <source>");
    return;
  }
  source = NULL;
  if(!strcmp(type,"wms")) {
    source = mapcache_source_wms_create(ctx);
  } else if(!strcmp(type,"mapserver")) {
    source = mapcache_source_mapserver_create(ctx);
  } else if(!strcmp(type,"gdal")) {
    source = mapcache_source_gdal_create(ctx);
  } else if(!strcmp(type,"dummy")) {
    source = mapcache_source_dummy_create(ctx);
  } else {
    ctx->set_error(ctx, 400, "unknown source type %s for source \"%s\"", type, name);
    return;
  }
  if(source == NULL) {
    ctx->set_error(ctx, 400, "failed to parse source \"%s\"", name);
    return;
  }
  source->name = name;

  if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
    parseMetadata(ctx, cur_node, source->metadata);
    GC_CHECK_ERROR(ctx);
  }

  source->configuration_parse_xml(ctx,node,source);
  GC_CHECK_ERROR(ctx);
  source->configuration_check(ctx,config,source);
  GC_CHECK_ERROR(ctx);
  mapcache_configuration_add_source(config,source,name);
}
Ejemplo n.º 9
0
void Regola::insertCompleteMetadata(QTreeWidget *tree)
{
    insertMetadata(tree);
    MetadataInfo info;
    parseMetadata(&info);
    //---
    appendAMetadatum(tree, &info.project, MetadataInfo::ProjectMetaType);
    appendAMetadatum(tree, &info.copyright, MetadataInfo::CopyrightMetaType);
    appendAMetadatum(tree, &info.version, MetadataInfo::VersionMetaType);
    appendAMetadatum(tree, &info.domain, MetadataInfo::DomainMetaType);
    appendAMetadatum(tree, &info.name, MetadataInfo::NameMetaType);
    //---

}
Ejemplo n.º 10
0
void Playlist::onRefreshFinished() {
    auto reply = qobject_cast<QNetworkReply*>(sender());
    reply->deleteLater();

    if (reply->error() != QNetworkReply::NoError) {
        qWarning() << Q_FUNC_INFO << "Failed to refresh metadata";
        return;
    }

    QFile output(_cachePath.filePath("metadata"));
    output.open(QIODevice::WriteOnly);
    output.write(reply->readAll());
    output.close();

    parseMetadata();
}
Ejemplo n.º 11
0
void AvatarAsset::readBlocks()
{
	DWORD prevAddress = header.blockStartAddress, prevDataLen = 0;
	io->setPosition(0, ios_base::end);
	DWORD fileSize = io->getPosition();

	for (;;)
	{
		// seek to the position of the next block
		DWORD curBlockAddress = prevAddress + roundUpToBlockAlignment(prevDataLen);
		io->setPosition(curBlockAddress);

		// if the io is at the end of the file, then break out
		if ((curBlockAddress + header.blockHeaderSize) > fileSize)
			break;

		// create a new block
		STRBBlock block;
		block.data = NULL;

		// read the block header
		block.id = (STRRBBlockId)io->readMultiByte(header.blockIDSize);
		block.dataLength = prevDataLen = (int)io->readMultiByte(header.blockSpanSize);
		block.fieldSize = (int)io->readMultiByte(header.blockSpanSize);

		if (block.id == STRBAssetMetadata)
			parseMetadataLegacyV1(curBlockAddress + header.blockHeaderSize);
		else if (block.id == STRBAssetMetadataVersioned)
			parseMetadata(curBlockAddress + header.blockHeaderSize);
		else if (block.id == STRBCustomColorTable)
			parseColorTable(curBlockAddress + header.blockHeaderSize);
		else if (block.id == STRBAnimation)
			readAnimationInfo(curBlockAddress + header.blockHeaderSize);

		// check the values read in
		if (block.dataLength < 0 || block.fieldSize == 0 || (block.dataLength % block.fieldSize) != 0)
			throw string("STRB: Invalid block header value(s).\n");

		prevAddress = curBlockAddress + header.blockHeaderSize;
		block.dataAddress = prevAddress;

		blocks.push_back(block);
	}
}
Ejemplo n.º 12
0
void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
{
  char *name = NULL;
  mapcache_tileset *tileset = NULL;
  ezxml_t cur_node;
  char* value;
  int havewgs84bbox=0;
  if(config->mode == MAPCACHE_MODE_NORMAL) {
    name = (char*)ezxml_attr(node,"name");
  } else {
    name = "mirror";
  }
  if(!name || !strlen(name)) {
    ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <tileset>");
    return;
  } else {
    name = apr_pstrdup(ctx->pool, name);
    /* check we don't already have a cache defined with this name */
    if(mapcache_configuration_get_tileset(config, name)) {
      ctx->set_error(ctx, 400, "duplicate tileset with name \"%s\"",name);
      return;
    }
  }
  tileset = mapcache_tileset_create(ctx);
  tileset->name = name;

  if ((cur_node = ezxml_child(node,"read-only")) != NULL) {
    if(cur_node->txt && !strcmp(cur_node->txt,"true"))
      tileset->read_only = 1;
  }

  if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
    parseMetadata(ctx, cur_node, tileset->metadata);
    GC_CHECK_ERROR(ctx);
  }


  if ((value = (char*)apr_table_get(tileset->metadata,"wgs84boundingbox")) != NULL) {
    double *values;
    int nvalues;
    value = apr_pstrdup(ctx->pool,value);
    if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
        nvalues != 4) {
      ctx->set_error(ctx, 400, "failed to parse extent array %s."
                     "(expecting 4 space separated numbers, got %d (%f %f %f %f)"
                     "eg <wgs84bbox>-180 -90 180 90</wgs84bbox>",
                     value,nvalues,values[0],values[1],values[2],values[3]);
      return;
    }
    tileset->wgs84bbox.minx = values[0];
    tileset->wgs84bbox.miny = values[1];
    tileset->wgs84bbox.maxx = values[2];
    tileset->wgs84bbox.maxy = values[3];
    havewgs84bbox = 1;
  }

  for(cur_node = ezxml_child(node,"grid"); cur_node; cur_node = cur_node->next) {
    mapcache_grid *grid;
    mapcache_grid_link *gridlink;
    char *restrictedExtent = NULL, *sTolerance = NULL;
    mapcache_extent *extent;
    int tolerance;

    if (tileset->grid_links == NULL) {
      tileset->grid_links = apr_array_make(ctx->pool,1,sizeof(mapcache_grid_link*));
    }
    grid = mapcache_configuration_get_grid(config, cur_node->txt);
    if(!grid) {
      ctx->set_error(ctx, 400, "tileset \"%s\" references grid \"%s\","
                     " but it is not configured", name, cur_node->txt);
      return;
    }
    gridlink = apr_pcalloc(ctx->pool,sizeof(mapcache_grid_link));
    gridlink->grid = grid;
    gridlink->minz = 0;
    gridlink->maxz = grid->nlevels;
    gridlink->grid_limits = (mapcache_extent_i*)apr_pcalloc(ctx->pool,grid->nlevels*sizeof(mapcache_extent_i));
    gridlink->outofzoom_strategy = MAPCACHE_OUTOFZOOM_NOTCONFIGURED;
    gridlink->intermediate_grids = apr_array_make(ctx->pool,1,sizeof(mapcache_grid_link*));

    restrictedExtent = (char*)ezxml_attr(cur_node,"restricted_extent");
    if(restrictedExtent) {
      int nvalues;
      double *values;
      restrictedExtent = apr_pstrdup(ctx->pool,restrictedExtent);
      if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, restrictedExtent, NULL, &values, &nvalues) ||
          nvalues != 4) {
        ctx->set_error(ctx, 400, "failed to parse extent array %s."
                       "(expecting 4 space separated numbers, "
                       "eg <grid restricted_extent=\"-180 -90 180 90\">foo</grid>",
                       restrictedExtent);
        return;
      }
      gridlink->restricted_extent = (mapcache_extent*) apr_pcalloc(ctx->pool, sizeof(mapcache_extent));
      gridlink->restricted_extent->minx = values[0];
      gridlink->restricted_extent->miny = values[1];
      gridlink->restricted_extent->maxx = values[2];
      gridlink->restricted_extent->maxy = values[3];
      extent = gridlink->restricted_extent;
    } else {
      extent = &grid->extent;
    }

    tolerance = 5;
    sTolerance = (char*)ezxml_attr(cur_node,"tolerance");
    if(sTolerance) {
      char *endptr;
      tolerance = (int)strtol(sTolerance,&endptr,10);
      if(*endptr != 0 || tolerance < 0) {
        ctx->set_error(ctx, 400, "failed to parse grid tolerance %s (expecting a positive integer)",
                       sTolerance);
        return;
      }
    }
    sTolerance = (char*)ezxml_attr(cur_node,"use_wms_intermediate_resolutions");
    if(sTolerance && !strcmp(sTolerance,"true")) {
      mapcache_grid_link *intermediate_gridlink = apr_pcalloc(ctx->pool,sizeof(mapcache_grid_link));
      APR_ARRAY_PUSH(gridlink->intermediate_grids,mapcache_grid_link*) = intermediate_gridlink;
    }


    mapcache_grid_compute_limits(grid,extent,gridlink->grid_limits,tolerance);

    sTolerance = (char*)ezxml_attr(cur_node,"minzoom");
    if(sTolerance) {
      char *endptr;
      tolerance = (int)strtol(sTolerance,&endptr,10);
      if(*endptr != 0 || tolerance < 0) {
        ctx->set_error(ctx, 400, "failed to parse grid minzoom %s (expecting a positive integer)",
                       sTolerance);
        return;
      }
      gridlink->minz = tolerance;
    }

    sTolerance = (char*)ezxml_attr(cur_node,"maxzoom");
    if(sTolerance) {
      char *endptr;
      tolerance = (int)strtol(sTolerance,&endptr,10);
      if(*endptr != 0 || tolerance < 0) {
        ctx->set_error(ctx, 400, "failed to parse grid maxzoom %s (expecting a positive integer)",
                       sTolerance);
        return;
      }
      gridlink->maxz = tolerance + 1;
    }

    if(gridlink->minz<0 || gridlink->maxz>grid->nlevels || gridlink->minz>=gridlink->maxz) {
      ctx->set_error(ctx, 400, "invalid grid maxzoom/minzoom %d/%d", gridlink->minz,gridlink->maxz);
      return;
    }
    
    sTolerance = (char*)ezxml_attr(cur_node,"max-cached-zoom");
    /* RFC97 implementation: check for a maximum zoomlevel to cache */
    if(sTolerance) {
      char *endptr;
      tolerance = (int)strtol(sTolerance,&endptr,10);
      if(*endptr != 0 || tolerance < 0) {
        ctx->set_error(ctx, 400, "failed to parse grid max-cached-zoom %s (expecting a positive integer)",
                       sTolerance);
        return;
      }
      
      if(tolerance > gridlink->maxz) {
        ctx->set_error(ctx, 400, "failed to parse grid max-cached-zoom %s (max cached zoom is greater than grid's max zoom)",
                       sTolerance);
        return;
      }
      gridlink->max_cached_zoom = tolerance;
      
      /* default to reassembling */
      gridlink->outofzoom_strategy = MAPCACHE_OUTOFZOOM_REASSEMBLE;
      sTolerance = (char*)ezxml_attr(cur_node,"out-of-zoom-strategy");
      if(sTolerance) {
        if(!strcasecmp(sTolerance,"reassemble")) {
          gridlink->outofzoom_strategy = MAPCACHE_OUTOFZOOM_REASSEMBLE;
        }
        else if(!strcasecmp(sTolerance,"proxy")) {
          gridlink->outofzoom_strategy = MAPCACHE_OUTOFZOOM_PROXY;
        } else {
          ctx->set_error(ctx, 400, "failed to parse grid out-of-zoom-strategy %s (expecting \"reassemble\" or \"proxy\")",
                        sTolerance);
          return;
        }
      }
    }



    /* compute wgs84 bbox if it wasn't supplied already */
    if(!havewgs84bbox && !strcasecmp(grid->srs,"EPSG:4326")) {
      tileset->wgs84bbox = *extent;
    }

    if(gridlink->intermediate_grids->nelts > 0) {
      double factor = 0.5, unitheight,unitwidth;
      int i;
      mapcache_grid_link *igl = APR_ARRAY_IDX(gridlink->intermediate_grids, 0, mapcache_grid_link*);
      igl->restricted_extent = gridlink->restricted_extent;
      igl->minz = gridlink->minz;
      igl->max_cached_zoom = gridlink->max_cached_zoom - 1;
      igl->maxz = gridlink->maxz - 1;
      igl->outofzoom_strategy = gridlink->outofzoom_strategy;
      igl->grid = mapcache_grid_create(ctx->pool);
      igl->grid->extent = gridlink->grid->extent;
      igl->grid->name = apr_psprintf(ctx->pool,"%s_intermediate_%g",gridlink->grid->name,factor);
      igl->grid->nlevels = gridlink->grid->nlevels - 1;
      igl->grid->origin = gridlink->grid->origin;
      igl->grid->srs = gridlink->grid->srs;
      igl->grid->srs_aliases = gridlink->grid->srs_aliases;
      igl->grid->unit = gridlink->grid->unit;
      igl->grid->tile_sx = gridlink->grid->tile_sx + gridlink->grid->tile_sx * factor;
      igl->grid->tile_sy = gridlink->grid->tile_sy + gridlink->grid->tile_sy * factor;
      igl->grid->levels = (mapcache_grid_level**)apr_pcalloc(ctx->pool, igl->grid->nlevels*sizeof(mapcache_grid_level*));
      for(i=0; i<igl->grid->nlevels; i++) {
        mapcache_grid_level *level = (mapcache_grid_level*)apr_pcalloc(ctx->pool,sizeof(mapcache_grid_level));
        level->resolution = gridlink->grid->levels[i]->resolution + (gridlink->grid->levels[i+1]->resolution - gridlink->grid->levels[i]->resolution) * factor;
        unitheight = igl->grid->tile_sy * level->resolution;
        unitwidth = igl->grid->tile_sx * level->resolution;
        
        level->maxy = ceil((igl->grid->extent.maxy-igl->grid->extent.miny - 0.01* unitheight)/unitheight);
        level->maxx = ceil((igl->grid->extent.maxx-igl->grid->extent.minx - 0.01* unitwidth)/unitwidth);
        igl->grid->levels[i] = level;
      }
      igl->grid_limits = (mapcache_extent_i*)apr_pcalloc(ctx->pool,igl->grid->nlevels*sizeof(mapcache_extent_i));
      mapcache_grid_compute_limits(igl->grid,extent,igl->grid_limits,tolerance);
    }
Ejemplo n.º 13
0
void parseGrid(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
{
  char *name;
  mapcache_extent extent = {0,0,0,0};
  mapcache_grid *grid;
  ezxml_t cur_node;
  char *value;

  name = (char*)ezxml_attr(node,"name");
  if(!name || !strlen(name)) {
    ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <grid>");
    return;
  } else {
    name = apr_pstrdup(ctx->pool, name);
    /* check we don't already have a grid defined with this name */
    if(mapcache_configuration_get_grid(config, name)) {
      ctx->set_error(ctx, 400, "duplicate grid with name \"%s\"",name);
      return;
    }
  }
  grid = mapcache_grid_create(ctx->pool);
  grid->name = name;

  if ((cur_node = ezxml_child(node,"extent")) != NULL) {
    double *values;
    int nvalues;
    value = apr_pstrdup(ctx->pool,cur_node->txt);
    if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
        nvalues != 4) {
      ctx->set_error(ctx, 400, "failed to parse extent array %s."
                     "(expecting 4 space separated numbers, got %d (%f %f %f %f)"
                     "eg <extent>-180 -90 180 90</extent>",
                     value,nvalues,values[0],values[1],values[2],values[3]);
      return;
    }
    extent.minx = values[0];
    extent.miny = values[1];
    extent.maxx = values[2];
    extent.maxy = values[3];
  }

  if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
    parseMetadata(ctx, cur_node, grid->metadata);
    GC_CHECK_ERROR(ctx);
  }

  if ((cur_node = ezxml_child(node,"units")) != NULL) {
    if(!strcasecmp(cur_node->txt,"dd")) {
      grid->unit = MAPCACHE_UNIT_DEGREES;
    } else if(!strcasecmp(cur_node->txt,"m")) {
      grid->unit = MAPCACHE_UNIT_METERS;
    } else if(!strcasecmp(cur_node->txt,"ft")) {
      grid->unit = MAPCACHE_UNIT_FEET;
    } else {
      ctx->set_error(ctx, 400, "unknown unit %s for grid %s (valid values are \"dd\", \"m\", and \"ft\"",
                     cur_node->txt, grid->name);
      return;
    }
  }
  if ((cur_node = ezxml_child(node,"srs")) != NULL) {
    grid->srs = apr_pstrdup(ctx->pool,cur_node->txt);
  }

  for(cur_node = ezxml_child(node,"srsalias"); cur_node; cur_node = cur_node->next) {
    value = apr_pstrdup(ctx->pool,cur_node->txt);
    APR_ARRAY_PUSH(grid->srs_aliases,char*) = value;
  }

  if ((cur_node = ezxml_child(node,"origin")) != NULL) {
    if(!strcasecmp(cur_node->txt,"top-left")) {
      grid->origin = MAPCACHE_GRID_ORIGIN_TOP_LEFT;
    } else if(!strcasecmp(cur_node->txt,"bottom-left")) {
      grid->origin = MAPCACHE_GRID_ORIGIN_BOTTOM_LEFT;
    } else if(!strcasecmp(cur_node->txt,"top-right")) {
      grid->origin = MAPCACHE_GRID_ORIGIN_TOP_RIGHT;
    } else if(!strcasecmp(cur_node->txt,"bottom-right")) {
      grid->origin = MAPCACHE_GRID_ORIGIN_BOTTOM_RIGHT;
    } else {
      ctx->set_error(ctx, 400,
          "unknown origin %s for grid %s (valid values are \"top-left\", \"bottom-left\", \"top-right\" and \"bottom-right\"",
          cur_node->txt, grid->name);
      return;
    }
    if(grid->origin == MAPCACHE_GRID_ORIGIN_BOTTOM_RIGHT || grid->origin == MAPCACHE_GRID_ORIGIN_TOP_RIGHT) {
      ctx->set_error(ctx,500,"grid origin %s not implemented",cur_node->txt);
      return;
    }
  }
  if ((cur_node = ezxml_child(node,"size")) != NULL) {
    int *sizes, nsizes;
    value = apr_pstrdup(ctx->pool,cur_node->txt);

    if(MAPCACHE_SUCCESS != mapcache_util_extract_int_list(ctx, value, NULL, &sizes, &nsizes) ||
        nsizes != 2) {
      ctx->set_error(ctx, 400, "failed to parse size array %s in  grid %s"
                     "(expecting two space separated integers, eg <size>256 256</size>",
                     value, grid->name);
      return;
    }
    grid->tile_sx = sizes[0];
    grid->tile_sy = sizes[1];
  }

  if ((cur_node = ezxml_child(node,"resolutions")) != NULL) {
    int nvalues;
    double *values;
    value = apr_pstrdup(ctx->pool,cur_node->txt);

    if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
        !nvalues) {
      ctx->set_error(ctx, 400, "failed to parse resolutions array %s."
                     "(expecting space separated numbers, "
                     "eg <resolutions>1 2 4 8 16 32</resolutions>",
                     value);
      return;
    }
    grid->nlevels = nvalues;
    grid->levels = (mapcache_grid_level**)apr_pcalloc(ctx->pool,
                   grid->nlevels*sizeof(mapcache_grid_level));
    while(nvalues--) {
      double unitheight;
      double unitwidth;
      mapcache_grid_level *level = (mapcache_grid_level*)apr_pcalloc(ctx->pool,sizeof(mapcache_grid_level));
      level->resolution = values[nvalues];
      unitheight = grid->tile_sy * level->resolution;
      unitwidth = grid->tile_sx * level->resolution;
      level->maxy = ceil((extent.maxy-extent.miny - 0.01* unitheight)/unitheight);
      level->maxx = ceil((extent.maxx-extent.minx - 0.01* unitwidth)/unitwidth);
      grid->levels[nvalues] = level;
    }
  }

  if(grid->srs == NULL) {
    ctx->set_error(ctx, 400, "grid \"%s\" has no srs configured."
                   " You must add a <srs> tag.", grid->name);
    return;
  }
  if(extent.minx >= extent.maxx || extent.miny >= extent.maxy) {
    ctx->set_error(ctx, 400, "grid \"%s\" has no (or invalid) extent configured"
                   " You must add/correct a <extent> tag.", grid->name);
    return;
  } else {
    grid->extent = extent;
  }
  if(grid->tile_sx <= 0 || grid->tile_sy <= 0) {
    ctx->set_error(ctx, 400, "grid \"%s\" has no (or invalid) tile size configured"
                   " You must add/correct a <size> tag.", grid->name);
    return;
  }
  if(!grid->nlevels) {
    ctx->set_error(ctx, 400, "grid \"%s\" has no resolutions configured."
                   " You must add a <resolutions> tag.", grid->name);
    return;
  }
  mapcache_configuration_add_grid(config,grid,name);
}
Ejemplo n.º 14
0
void SM_QDropbox::requestFinished(int nr, QNetworkReply *rply)
{
    rply->deleteLater();
#ifdef SM_QTDROPBOX_DEBUG
    int resp_bytes = rply->bytesAvailable();
#endif
    QByteArray buff = rply->readAll();
    QString response = QString(buff);
#ifdef SM_QTDROPBOX_DEBUG
    qDebug() << "request " << nr << "finished." << endl;
    qDebug() << "request was: " << rply->url().toString() << endl;
#endif
#ifdef SM_QTDROPBOX_DEBUG
    qDebug() << "response: " << resp_bytes << "bytes" << endl;
    qDebug() << "status code: " << rply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString() << endl;
    qDebug() << "== begin response ==" << endl << response << endl << "== end response ==" << endl;
    qDebug() << "req#" << nr << " is of type " << requestMap[nr].type << endl;
#endif
    // drop box error handling based on return codes
    switch(rply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
    {
    case SM_DROPBOX_ERROR_BAD_INPUT:
        errorState = SM_QDropbox::BadInput;
        errorText  = "";
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_EXPIRED_TOKEN:
        errorState = SM_QDropbox::TokenExpired;
        errorText  = "";
        emit tokenExpired();
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_BAD_OAUTH_REQUEST:
        errorState = SM_QDropbox::BadOAuthRequest;
        errorText  = "";
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_FILE_NOT_FOUND:
        emit fileNotFound();
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_WRONG_METHOD:
        errorState = SM_QDropbox::WrongHttpMethod;
        errorText  = "";
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_REQUEST_CAP:
        errorState = SM_QDropbox::MaxRequestsExceeded;
        errorText = "";
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
        break;
    case SM_DROPBOX_ERROR_USER_OVER_QUOTA:
        errorState = SM_QDropbox::UserOverQuota;
        errorText = "";
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
        break;
    default:
        break;
    }

    if(rply->error() != QNetworkReply::NoError)
    {

        errorState = SM_QDropbox::CommunicationError;
        errorText  = QString("%1 - %2").arg(rply->error()).arg(rply->errorString());
#ifdef SM_QTDROPBOX_DEBUG
        qDebug() << "error " << errorState << "(" << errorText << ") in request" << endl;
#endif
        emit errorOccured(errorState);
        checkReleaseEventLoop(nr);
        return;
    }

    // ignore connection requests
    if(requestMap[nr].type == SM_DROPBOX_REQ_CONNECT)
    {
#ifdef SM_QTDROPBOX_DEBUG
        qDebug() << "- answer to connection request ignored" << endl;
#endif
        removeRequestFromMap(nr);
        return;
    }

    bool delayed_finish = false;
    int delayed_nr;

    if(rply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 302)
    {
#ifdef SM_QTDROPBOX_DEBUG
        qDebug() << "redirection received" << endl;
#endif
        // redirection handling
        QUrl newlocation(rply->header(QNetworkRequest::LocationHeader).toString(), QUrl::StrictMode);
#ifdef SM_QTDROPBOX_DEBUG
        qDebug() << "new url: " << newlocation.toString() << endl;
#endif
        int oldnr = nr;
        nr = sendRequest(newlocation, requestMap[nr].method, 0, requestMap[nr].host);
        requestMap[nr].type = SM_DROPBOX_REQ_REDIREC;
        requestMap[nr].linked = oldnr;
        return;
    }
    else
    {
        if(requestMap[nr].type == SM_DROPBOX_REQ_REDIREC)
        {
            // change values if this is the answert to a redirect
            SM_DROPBOX_request redir = requestMap[nr];
            SM_DROPBOX_request orig  = requestMap[redir.linked];
            requestMap[nr] = orig;
            removeRequestFromMap(nr);
            nr = redir.linked;
        }

        // standard handling depending on message type
        switch(requestMap[nr].type)
        {
        case SM_DROPBOX_REQ_CONNECT:
            // was only a connect request - so drop it
            break;
        case SM_DROPBOX_REQ_RQTOKEN:
            // requested a tiken
            responseTokenRequest(response);
            break;
        case SM_DROPBOX_REQ_RQBTOKN:
            responseBlockedTokenRequest(response);
            break;
        case SM_DROPBOX_REQ_AULOGIN:
            delayed_nr = responseDropboxLogin(response, nr);
            delayed_finish = true;
            break;
        case SM_DROPBOX_REQ_ACCTOKN:
            responseAccessToken(response);
            break;
        case SM_DROPBOX_REQ_METADAT:
            parseMetadata(response);
            break;
        case SM_DROPBOX_REQ_BMETADA:
            parseBlockingMetadata(response);
            break;
        case SM_DROPBOX_REQ_BACCTOK:
            responseBlockingAccessToken(response);
            break;
        case SM_DROPBOX_REQ_ACCINFO:
            parseAccountInfo(response);
            break;
        case SM_DROPBOX_REQ_BACCINF:
            parseBlockingAccountInfo(response);
            break;
        case SM_DROPBOX_REQ_SHRDLNK:
            parseSharedLink(response);
            break;
        case SM_DROPBOX_REQ_BSHRDLN:
            parseBlockingSharedLink(response);
            break;
        case SM_DROPBOX_REQ_REVISIO:
            parseRevisions(response);
            break;
        case SM_DROPBOX_REQ_BREVISI:
            parseBlockingRevisions(response);
            break;
        case SM_DROPBOX_REQ_DELTA:
            parseDelta(response);
            break;
        case SM_DROPBOX_REQ_BDELTA:
            parseBlockingDelta(response);
            break;
        default:
            errorState  = SM_QDropbox::ResponseToUnknownRequest;
            errorText   = "Received a response to an unknown request";
            emit errorOccured(errorState);
            break;
        }
    }

    if(delayed_finish)
        delayMap[delayed_nr] = nr;
    else
    {
        if(delayMap[nr])
        {
            int drq = delayMap[nr];
            while(drq!=0)
            {
                emit operationFinished(delayMap[drq]);
                delayMap.remove(drq);
                drq = delayMap[drq];
            }
        }

        removeRequestFromMap(nr);
        emit operationFinished(nr);
    }

    return;
}
Ejemplo n.º 15
0
void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config) {
   char *name = NULL;
   mapcache_tileset *tileset = NULL;
   ezxml_t cur_node;
   char* value;
   int havewgs84bbox=0;
   if(config->mode == MAPCACHE_MODE_NORMAL) {
      name = (char*)ezxml_attr(node,"name");
   } else {
      name = "mirror";
   }
   if(!name || !strlen(name)) {
      ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <tileset>");
      return;
   }
   else {
      name = apr_pstrdup(ctx->pool, name);
      /* check we don't already have a cache defined with this name */
      if(mapcache_configuration_get_tileset(config, name)) {
         ctx->set_error(ctx, 400, "duplicate tileset with name \"%s\"",name);
         return;
      }
   }
   tileset = mapcache_tileset_create(ctx);
   tileset->name = name;
   
   if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
      parseMetadata(ctx, cur_node, tileset->metadata);
      GC_CHECK_ERROR(ctx);
   }
   
   
   if ((value = (char*)apr_table_get(tileset->metadata,"wgs84boundingbox")) != NULL) {
      double *values;
      int nvalues;
      value = apr_pstrdup(ctx->pool,value);
      if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
            nvalues != 4) {
         ctx->set_error(ctx, 400, "failed to parse extent array %s."
               "(expecting 4 space separated numbers, got %d (%f %f %f %f)"
               "eg <wgs84bbox>-180 -90 180 90</wgs84bbox>",
               value,nvalues,values[0],values[1],values[2],values[3]);
         return;
      }
      tileset->wgs84bbox[0] = values[0];
      tileset->wgs84bbox[1] = values[1];
      tileset->wgs84bbox[2] = values[2];
      tileset->wgs84bbox[3] = values[3];
      havewgs84bbox = 1;
   }

   for(cur_node = ezxml_child(node,"grid"); cur_node; cur_node = cur_node->next) {
      int i;
      mapcache_grid *grid;
      mapcache_grid_link *gridlink;
      char *restrictedExtent = NULL, *sTolerance = NULL;
      double *extent;
      int tolerance;

      if (tileset->grid_links == NULL) {
         tileset->grid_links = apr_array_make(ctx->pool,1,sizeof(mapcache_grid_link*));
      }
      grid = mapcache_configuration_get_grid(config, cur_node->txt);
      if(!grid) {
         ctx->set_error(ctx, 400, "tileset \"%s\" references grid \"%s\","
               " but it is not configured", name, cur_node->txt);
         return;
      }
      gridlink = apr_pcalloc(ctx->pool,sizeof(mapcache_grid_link));
      gridlink->grid = grid;
      gridlink->minz = 0;
      gridlink->maxz = grid->nlevels;
      gridlink->grid_limits = apr_pcalloc(ctx->pool,grid->nlevels*sizeof(int*));
      for(i=0;i<grid->nlevels;i++) {
         gridlink->grid_limits[i] = apr_pcalloc(ctx->pool,4*sizeof(int));
      }

      restrictedExtent = (char*)ezxml_attr(cur_node,"restricted_extent");
      if(restrictedExtent) {
         int nvalues;
         restrictedExtent = apr_pstrdup(ctx->pool,restrictedExtent);
         if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, restrictedExtent, NULL, &gridlink->restricted_extent, &nvalues) ||
               nvalues != 4) {
            ctx->set_error(ctx, 400, "failed to parse extent array %s."
                  "(expecting 4 space separated numbers, "
                  "eg <grid restricted_extent=\"-180 -90 180 90\">foo</grid>",
                  restrictedExtent);
            return;
         }
         extent = gridlink->restricted_extent;
      } else {
         extent = grid->extent;
      }

      tolerance = 5;
      sTolerance = (char*)ezxml_attr(cur_node,"tolerance");
      if(sTolerance) {
         char *endptr;
         tolerance = (int)strtol(sTolerance,&endptr,10);
         if(*endptr != 0 || tolerance < 0) {
            ctx->set_error(ctx, 400, "failed to parse grid tolerance %s (expecting a positive integer)",
                  sTolerance);  
            return;
         }
      }
      

      mapcache_grid_compute_limits(grid,extent,gridlink->grid_limits,tolerance);
      
      sTolerance = (char*)ezxml_attr(cur_node,"minzoom");
      if(sTolerance) {
         char *endptr;
         tolerance = (int)strtol(sTolerance,&endptr,10);
         if(*endptr != 0 || tolerance < 0) {
            ctx->set_error(ctx, 400, "failed to parse grid minzoom %s (expecting a positive integer)",
                  sTolerance);  
            return;
         }
         gridlink->minz = tolerance;
      }
      
      sTolerance = (char*)ezxml_attr(cur_node,"maxzoom");
      if(sTolerance) {
         char *endptr;
         tolerance = (int)strtol(sTolerance,&endptr,10);
         if(*endptr != 0 || tolerance < 0) {
            ctx->set_error(ctx, 400, "failed to parse grid maxzoom %s (expecting a positive integer)",
                  sTolerance);  
            return;
         }
         gridlink->maxz = tolerance + 1;
      }

      if(gridlink->minz<0 || gridlink->maxz>grid->nlevels || gridlink->minz>=gridlink->maxz) {
            ctx->set_error(ctx, 400, "invalid grid maxzoom/minzoom %d/%d", gridlink->minz,gridlink->maxz);
            return;
      }

      
      
      /* compute wgs84 bbox if it wasn't supplied already */
      if(!havewgs84bbox && !strcasecmp(grid->srs,"EPSG:4326")) {
         tileset->wgs84bbox[0] = extent[0];
         tileset->wgs84bbox[1] = extent[1];
         tileset->wgs84bbox[2] = extent[2];
         tileset->wgs84bbox[3] = extent[3];
      }
      APR_ARRAY_PUSH(tileset->grid_links,mapcache_grid_link*) = gridlink;
   }

   if ((cur_node = ezxml_child(node,"dimensions")) != NULL) {
      parseDimensions(ctx, cur_node, tileset);
      GC_CHECK_ERROR(ctx);
   }


   if ((cur_node = ezxml_child(node,"cache")) != NULL) {
         mapcache_cache *cache = mapcache_configuration_get_cache(config, cur_node->txt);
         if(!cache) {
            ctx->set_error(ctx, 400, "tileset \"%s\" references cache \"%s\","
                  " but it is not configured", name, cur_node->txt);
            return;
         }
         tileset->cache = cache;
   }

   if ((cur_node = ezxml_child(node,"source")) != NULL) {
         mapcache_source *source = mapcache_configuration_get_source(config, cur_node->txt);
         if(!source) {
            ctx->set_error(ctx, 400, "tileset \"%s\" references source \"%s\","
                  " but it is not configured", name, cur_node->txt);
            return;
         }
         tileset->source = source;
   }

   if ((cur_node = ezxml_child(node,"metatile")) != NULL) {
     int *values, nvalues;
      value = apr_pstrdup(ctx->pool,cur_node->txt);
         
         if(MAPCACHE_SUCCESS != mapcache_util_extract_int_list(ctx, cur_node->txt, NULL,
                  &values, &nvalues) ||
               nvalues != 2) {
            ctx->set_error(ctx, 400, "failed to parse metatile dimension %s."
                  "(expecting 2 space separated integers, "
                  "eg <metatile>5 5</metatile>",
                  cur_node->txt);
            return;
         }
         tileset->metasize_x = values[0];
         tileset->metasize_y = values[1];
   }
      

   if ((cur_node = ezxml_child(node,"watermark")) != NULL) {
         if(!*cur_node->txt) {
             ctx->set_error(ctx,400, "watermark config entry empty");
             return;
         }
         mapcache_tileset_add_watermark(ctx,tileset,cur_node->txt);
         GC_CHECK_ERROR(ctx);
   }
      

   if ((cur_node = ezxml_child(node,"expires")) != NULL) {
         char *endptr;
         tileset->expires = (int)strtol(cur_node->txt,&endptr,10);
         if(*endptr != 0) {
            ctx->set_error(ctx, 400, "failed to parse expires %s."
                  "(expecting an  integer, "
                  "eg <expires>3600</expires>",
                  cur_node->txt);  
            return;
         }
   }
   if ((cur_node = ezxml_child(node,"auto_expire")) != NULL) {
      char *endptr;
      tileset->auto_expire = (int)strtol(cur_node->txt,&endptr,10);
      if(*endptr != 0) {
         ctx->set_error(ctx, 400, "failed to parse auto_expire %s."
               "(expecting an  integer, "
               "eg <auto_expire>3600</auto_expire>",
               cur_node->txt);  
         return;
      }
   }

   if ((cur_node = ezxml_child(node,"metabuffer")) != NULL) {
         char *endptr;
         tileset->metabuffer = (int)strtol(cur_node->txt,&endptr,10);
         if(*endptr != 0) {
            ctx->set_error(ctx, 400, "failed to parse metabuffer %s."
                  "(expecting an  integer, "
                  "eg <metabuffer>1</metabuffer>",
                  cur_node->txt);
            return;
         }
   }
      
   if ((cur_node = ezxml_child(node,"format")) != NULL) {
         mapcache_image_format *format = mapcache_configuration_get_image_format(config,cur_node->txt);
         if(!format) {
            ctx->set_error(ctx, 400, "tileset \"%s\" references format \"%s\","
                  " but it is not configured",name,cur_node->txt);
            return;
         }
         tileset->format = format;
   }

   mapcache_tileset_configuration_check(ctx,tileset);
   GC_CHECK_ERROR(ctx);
   mapcache_configuration_add_tileset(config,tileset,name);
   return;
}
Ejemplo n.º 16
0
void MDAL::LoaderGdal::parseRasterBands( const MDAL::GdalDataset *cfGDALDataset )
{
  for ( unsigned int i = 1; i <= cfGDALDataset->mNBands; ++i ) // starts with 1 .... ehm....
  {
    // Get Band
    GDALRasterBandH gdalBand = GDALGetRasterBand( cfGDALDataset->mHDataset, static_cast<int>( i ) );
    if ( !gdalBand )
    {
      throw MDAL_Status::Err_InvalidData;
    }

    // Reference time
    metadata_hash global_metadata = parseMetadata( cfGDALDataset->mHDataset );
    parseGlobals( global_metadata );

    // Get metadata
    metadata_hash metadata = parseMetadata( gdalBand );

    std::string band_name;
    double time = std::numeric_limits<double>::min();
    bool is_vector;
    bool is_x;
    if ( parseBandInfo( cfGDALDataset, metadata, band_name, &time, &is_vector, &is_x ) )
    {
      continue;
    }

    // Add to data structures
    std::vector<GDALRasterBandH>::size_type data_count = is_vector ? 2 : 1;
    std::vector<GDALRasterBandH>::size_type data_index = is_x ? 0 : 1;
    if ( mBands.find( band_name ) == mBands.end() )
    {
      // this Face is not yet added at all
      // => create new map
      timestep_map qMap;
      std::vector<GDALRasterBandH> raster_bands( data_count );

      raster_bands[data_index] = gdalBand;
      qMap[time] = raster_bands;
      mBands[band_name] = qMap;

    }
    else
    {
      timestep_map::iterator timestep = mBands[band_name].find( time );
      if ( timestep == mBands[band_name].end() )
      {
        // Face is there, but new timestep
        // => create just new map entry
        std::vector<GDALRasterBandH> raster_bands( data_count );
        raster_bands[data_index] = gdalBand;
        mBands[band_name][time] = raster_bands;

      }
      else
      {
        // Face is there, and timestep too, this must be other part
        // of the existing vector
        timestep->second[data_index] = gdalBand;
      }
    }
  }
}
Ejemplo n.º 17
0
int erClXmlParseManifest(char *szContainerPath, clDisplayItem_t * displayItem)
{
    int      ret = -1;  // return value: 0 = ok, -1 = error

    xmlDoc  *doc            = NULL;
    xmlNode *rootElement    = NULL;
    xmlNode *cur            = NULL;
    xmlNode *symlinkElement = NULL;
    xmlChar *targetPath     = NULL;
    xmlChar *key;


    int n = strlen(szContainerPath) + 1 + strlen(MANIFEST_FILENAME) + 1;
    char *szFilename = alloca(n);
    g_assert(szFilename != NULL);
    snprintf(szFilename, n, "%s/" MANIFEST_FILENAME, szContainerPath);
    
    LIBXML_TEST_VERSION doc = xmlParseFile(szFilename);

    if (doc == NULL)
    {
        CL_ERRORPRINTF("Document not parsed successfully");
        return ret;
    }

    /* Get the root element node */
    rootElement = xmlDocGetRootElement(doc);

    // Check whether we have a document with the correct root (i.e. package)
    if (xmlStrcmp(rootElement->name, (const xmlChar *) "package"))
    {
        CL_ERRORPRINTF("Document of the wrong type, root node != package");
        xmlFreeDoc(doc);
        return ret;
    }

    
    // Check whether this manifest actually is a symlink
    symlinkElement = ermXmlGetChildNode(rootElement, "symlink");
    if (symlinkElement)
    {
        // check whether target must be extended with locale
        displayItem->fit = mdsFitManifestSymlink;
        key = xmlGetProp(symlinkElement, "add-locale");
        if (key)
        {
            if (xmlStrcmp(key, "true") == 0)
            {
                displayItem->fit = mdsFitManifestSymlinkLocale;
            }
            xmlFree(key);
        }

        // get target details
        targetPath = xmlNodeGetContent(symlinkElement);
        szFilename = getVerifiedPath(targetPath, szContainerPath);
        CL_WARNPRINTF("symlink [%s] [%s] --> [%s]", szContainerPath, targetPath, szFilename);
        if (szFilename)
        {
            strcpy(displayItem->szFilename, szFilename);
            free(szFilename);
        }
        else
        {
            CL_ERRORPRINTF("directory [%s] [%s] is incorrect", szContainerPath, targetPath);
            // display as a folder without manifest
            strcpy(displayItem->szFilename, szContainerPath);
            displayItem->fit = mdsFitFolder;
        }
    }
    else
    {
        cur = rootElement->xmlChildrenNode;
        while (cur != NULL)
        {
            if ((!xmlStrcmp(cur->name, (const xmlChar *) "metadata")))
            {
                CL_LOGPRINTF("Found node metadata");
                parseMetadata(doc, cur, displayItem, szContainerPath);
            }

            if ((!xmlStrcmp(cur->name, (const xmlChar *) "storage")))
            {
                CL_LOGPRINTF("Found node storage");
                parseStoragedata(doc, cur, displayItem, szContainerPath);
                //update the type of container, since this is a special type of container
                displayItem->fit = mdsFitStorage;
            }

            if ((!xmlStrcmp(cur->name, (const xmlChar *) "application")))
            {
                CL_LOGPRINTF("Found node application");
                parseApplicationdata(doc, cur, displayItem, szContainerPath);
                //update the type of container, since this is a special type of container
                displayItem->fit = mdsFitApplication;
            }

            if ((!xmlStrcmp(cur->name, (const xmlChar *) "directory")))
            {
                CL_LOGPRINTF("Found node directory");
                parseDirectorydata(doc, cur, displayItem, szContainerPath);
                //update the type of container, since this is a special type of container
                displayItem->fit = mdsFitManifestDirectory;
            }
            cur = cur->next;
        }
    }

    /* free the document */
    xmlFreeDoc(doc);

    /* Free the global variables that may have been allocated by the parser */
    xmlCleanupParser();

    return 0;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
void Playlist::checkForCachedMetadata() {
    if (QFile(_cachePath.filePath("metadata")).exists()) {
        parseMetadata();
    }
}
Ejemplo n.º 20
0
    bool parse()
    {
      class CloseFileClass
      {
      public:
        CloseFileClass(VirtualFile* f): mFile(f) {}
        ~CloseFileClass()
        {
          if (mFile)
            mFile->close();
        }
      private:
        ref<VirtualFile> mFile;
      } CloseFile(inputFile());

      inputFile()->close();
      inputFile()->open(OM_ReadOnly);

      // clear metadata
      mMetadata.clear();

      // read version and encoding
      mVersion = 0;
      mEncoding.clear();

      if (!parseHeader())
      {
        Log::error("VLXParserVLB : error parsing VLB header.\n");
        return false;
      }

      if (mVersion != 100)
      {
        Log::error("VLX version not supported.\n");
        return false;
      }

      if (mEncoding != "ascii")
      {
        Log::error("Encoding not supported.\n");
        return false;
      }

      unsigned char chunk;
      std::string str;

      while(readChunk(chunk))
      {
        if(chunk == VLB_ChunkStructure)
        {
          ref<VLXStructure> st = new VLXStructure;

          if (!parseStructure(st.get()))
          {
            Log::error( Say("Error parsing binary file at offset %n.\n") << inputFile()->position() );
            return false;
          }

          mStructures.push_back(st);
        }
        else
        {
          Log::error( Say("Error parsing binary file at offset %n. Expected chunk structure.\n") << inputFile()->position() );
          return false;
        }
      }

      parseMetadata();

      return true;
    }