Beispiel #1
0
void meta_free(META_ROOT **p)
{
    (void)p;
#ifdef HAVE_LIBXML2
    if (p && *p)
    {
        uint8_t i;
        for (i = 0; i < (*p)->dl_count; i++) {
            uint32_t t;
            for (t = 0; t < (*p)->dl_entries[i].toc_count; t++) {
                XML_FREE((*p)->dl_entries[i].toc_entries[t].title_name);
            }
            for (t = 0; t < (*p)->dl_entries[i].thumb_count; t++) {
                XML_FREE((*p)->dl_entries[i].thumbnails[t].path);
            }
            X_FREE((*p)->dl_entries[i].toc_entries);
            X_FREE((*p)->dl_entries[i].thumbnails);
            X_FREE((*p)->dl_entries[i].filename);
            XML_FREE((*p)->dl_entries[i].di_name);
            XML_FREE((*p)->dl_entries[i].di_alternative);
        }
        X_FREE((*p)->dl_entries);
        X_FREE(*p);
    }
#endif
}
Beispiel #2
0
static void _parseManifestNode(xmlNode * a_node, META_DL *disclib)
{
    xmlNode *cur_node = NULL;
    xmlChar *tmp;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "title")) {
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "name")) {
                    disclib->di_name = (char*)xmlNodeGetContent(cur_node);
                }
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "alternative")) {
                    disclib->di_alternative = (char*)xmlNodeGetContent(cur_node);
                }
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "numSets")) {
                    disclib->di_num_sets = atoi((char*)(tmp = xmlNodeGetContent(cur_node)));
                    XML_FREE(tmp);
                }
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "setNumber")) {
                    disclib->di_set_number = atoi((char*)(tmp = xmlNodeGetContent(cur_node)));
                    XML_FREE(tmp);
                }
            }
            else if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "tableOfContents")) {
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "titleName") && (tmp = xmlGetProp(cur_node, BAD_CAST_CONST "titleNumber"))) {
                    int i = disclib->toc_count;
                    disclib->toc_count++;
                    disclib->toc_entries = realloc(disclib->toc_entries, (disclib->toc_count*sizeof(META_TITLE)));
                    disclib->toc_entries[i].title_number = atoi((const char*)tmp);
                    disclib->toc_entries[i].title_name = (char*)xmlNodeGetContent(cur_node);
                    XML_FREE(tmp);
                }
            }
            else if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "description")) {
                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "thumbnail") && (tmp = xmlGetProp(cur_node, BAD_CAST_CONST "href"))) {
                    uint8_t i = disclib->thumb_count;
                    disclib->thumb_count++;
                    disclib->thumbnails = realloc(disclib->thumbnails, (disclib->thumb_count*sizeof(META_THUMBNAIL)));
                    disclib->thumbnails[i].path = (char *)tmp;
                    if ((tmp = xmlGetProp(cur_node, BAD_CAST_CONST "size"))) {
                        int x = 0, y = 0;
                        sscanf((const char*)tmp, "%ix%i", &x, &y);
                        disclib->thumbnails[i].xres = x;
                        disclib->thumbnails[i].yres = y;
                        XML_FREE(tmp);
                    }
                    else {
                        disclib->thumbnails[i].xres = disclib->thumbnails[i].yres = -1;
                    }
                }
            }
        }
        _parseManifestNode(cur_node->children, disclib);
    }
}
void Parse_XML_SpectralAdvanced (int rank, xmlDocPtr xmldoc, xmlNodePtr current_tag)
{
  xmlNodePtr tag, tag2;

  tag = current_tag;

  while (tag != NULL)
  {
    if (!xmlStrcasecmp (tag->name, xmlTEXT) || !xmlStrcasecmp (tag->name, xmlCOMMENT)) { /* Skip coments */ }

    else if (!xmlStrcasecmp (tag->name, RC_ONLINE_SPECTRAL_ADVANCED))
    {
      xmlChar *enabled = xmlGetProp (tag, TRACE_ENABLED);
      if (enabled != NULL && !xmlStrcasecmp (enabled, xmlYES))
      {
        xmlChar *burst_threshold = xmlGetProp (tag, SPECTRAL_BURST_THRESHOLD);
        Online_SetSpectralBurstThreshold( atof((const char *)burst_threshold) );
        XML_FREE(burst_threshold);

        tag2 = tag->xmlChildrenNode;

        while (tag2 != NULL)
        {
          if (!xmlStrcasecmp (tag2->name, xmlTEXT) || !xmlStrcasecmp (tag2->name, xmlCOMMENT)) { /* Skip coments */ }
          else if (!xmlStrcasecmp (tag2->name, RC_ONLINE_SPECTRAL_ADVANCED_PERIODIC_ZONE))
          {
            xmlChar *detail_level = xmlGetProp (tag2, SPECTRAL_DETAIL_LEVEL);

            Online_SetSpectralPeriodZoneLevel( detail_level );

            XML_FREE(detail_level);
          }
          else if (!xmlStrcasecmp (tag2->name, RC_ONLINE_SPECTRAL_ADVANCED_NON_PERIODIC_ZONE))
          {
            xmlChar *detail_level = xmlGetProp (tag2, SPECTRAL_DETAIL_LEVEL);
            xmlChar *min_duration = xmlGetProp (tag2, SPECTRAL_MIN_DURATION);

            Online_SetSpectralNonPeriodZoneLevel( detail_level );
            Online_SetSpectralNonPeriodZoneMinDuration( __Extrae_Utils_getTimeFromStr( min_duration, "<non_periodic_zone min_duration=\"..\" />", rank ) );

            XML_FREE(detail_level);
            XML_FREE(min_duration);
          }
          tag2 = tag2->next;
        }
      }
      XML_FREE(enabled);
    }
    tag = tag->next;
  }
}
Beispiel #4
0
META_ROOT *meta_parse(BD_DISC *disc)
{
#ifdef HAVE_LIBXML2
    META_ROOT *root = calloc(1, sizeof(META_ROOT));
    if (!root) {
        BD_DEBUG(DBG_CRIT, "out of memory\n");
        return NULL;
    }
    root->dl_count = 0;

    xmlDocPtr doc;
    _findMetaXMLfiles(root, disc);

    uint8_t i;
    for (i = 0; i < root->dl_count; i++) {
        uint8_t *data = NULL;
        size_t size;
        size = disc_read_file(disc, "BDMV" DIR_SEP "META" DIR_SEP "DL",
                              root->dl_entries[i].filename,
                              &data);
        if (!data || size == 0) {
            BD_DEBUG(DBG_DIR, "Failed to read BDMV/META/DL/%s\n", root->dl_entries[i].filename);
        } else {
                doc = xmlReadMemory((char*)data, (int)size, NULL, NULL, 0);
                if (doc == NULL) {
                    BD_DEBUG(DBG_DIR, "Failed to parse BDMV/META/DL/%s\n", root->dl_entries[i].filename);
                } else {
                    xmlNode *root_element = NULL;
                    root_element = xmlDocGetRootElement(doc);
                    root->dl_entries[i].di_name = root->dl_entries[i].di_alternative = NULL;
                    root->dl_entries[i].di_num_sets = root->dl_entries[i].di_set_number = -1;
                    root->dl_entries[i].toc_count = root->dl_entries[i].thumb_count = 0;
                    root->dl_entries[i].toc_entries = NULL;
                    root->dl_entries[i].thumbnails = NULL;
                    _parseManifestNode(root_element, &root->dl_entries[i]);
                    XML_FREE(doc);
                }
            X_FREE(data);
        }
    }
    xmlCleanupParser();
    return root;
#else
    (void)disc;
    BD_DEBUG(DBG_DIR, "configured without libxml2 - can't parse meta info\n");
    return NULL;
#endif
}
/**
 * Skip all the way up to the on-line section 
 */
void Parse_XML_Online_From_File (char *filename)
{
  xmlDocPtr  xmldoc;
  xmlNodePtr current_tag;
  xmlNodePtr root_tag;

  int online_config_parsed = 0;

  /*
   * This initialize the library and check potential ABI mismatches
   * between the version it was compiled for and the actual shared
   * library used.
   */
  LIBXML_TEST_VERSION;

  xmldoc = xmlParseFile (filename);
  if (xmldoc != NULL)
  {
    root_tag = xmlDocGetRootElement (xmldoc);
    if (root_tag != NULL)
    {

      current_tag = root_tag->xmlChildrenNode;
      while ((current_tag != NULL) && (!online_config_parsed))
      {
        if (!xmlStrcasecmp (current_tag->name, TRACE_CONTROL))
        {
          xmlChar *enabled = xmlGetProp (current_tag, TRACE_ENABLED);
          if (enabled != NULL && !xmlStrcasecmp (enabled, xmlYES))
          {
            current_tag = current_tag->xmlChildrenNode;
          }
          XML_FREE(enabled);
        }
        else if (!xmlStrcasecmp (current_tag->name, TRACE_REMOTE_CONTROL))
        {
          xmlChar *enabled = xmlGetProp (current_tag, TRACE_ENABLED);
          if (enabled != NULL && !xmlStrcasecmp (enabled, xmlYES))
          {
            current_tag = current_tag->xmlChildrenNode;
          }
          XML_FREE(enabled);
        }
        else if (!xmlStrcasecmp (current_tag->name, REMOTE_CONTROL_METHOD_ONLINE))
        {
          xmlChar *enabled = xmlGetProp (current_tag, TRACE_ENABLED);
          if (enabled != NULL && !xmlStrcasecmp (enabled, xmlYES))
          {
            /* Enable the on-line analysis */
            Online_Enable();

            /* Parse the on-line analysis configuration */
            Parse_XML_Online(0, xmldoc, current_tag);
            online_config_parsed = 1;
          }
          else
          {
            return;
          }
        }
        else
        {
          current_tag = current_tag->next;
        }
      }
    }
  }
}
void Parse_XML_Online (int rank, xmlDocPtr xmldoc, xmlNodePtr current_tag)
{
  xmlNodePtr tag;

  tag = current_tag;

  xmlChar *analysis  = xmlGetProp (tag, RC_ONLINE_TYPE);
  xmlChar *frequency = xmlGetProp (tag, RC_ONLINE_FREQ);
  xmlChar *topology  = xmlGetProp (tag, RC_ONLINE_TOPO);

  /* Configure the type of analysis */
  if (analysis != NULL)
  {
    if (xmlStrcasecmp(analysis, RC_ONLINE_CLUSTERING) == 0)
    {
      Online_SetAnalysis(ONLINE_DO_CLUSTERING);
    }
    else if (xmlStrcasecmp(analysis, RC_ONLINE_SPECTRAL) == 0)
    {
      Online_SetAnalysis(ONLINE_DO_SPECTRAL);
    }
    else if (xmlStrcasecmp(analysis, RC_ONLINE_GREMLINS) == 0)
    {
      Online_SetAnalysis(ONLINE_DO_GREMLINS);
    }
    else
    {
      mfprintf(stderr, PACKAGE_NAME": XML Error: Value '%s' is not valid for property '<%s>'%s'\n",
        analysis, REMOTE_CONTROL_METHOD_ONLINE, RC_ONLINE_TYPE);
      exit(-1);
    }
  }

  /* Configure the frequency of the analysis */
  if (frequency != NULL)
  {
    Online_SetFrequencyString(frequency);
  }

  /* Configure the topology */
  if (topology != NULL)
  {
    Online_SetTopology((char *)topology);
  }
  XML_FREE(analysis);
  XML_FREE(frequency);

  tag = current_tag->xmlChildrenNode;
  while (tag != NULL)
  {
    if (!xmlStrcasecmp (tag->name, xmlTEXT) || !xmlStrcasecmp (tag->name, xmlCOMMENT)) { /* Skip coments */ }
#if defined(HAVE_CLUSTERING)
    else if (!xmlStrcasecmp (tag->name, RC_ONLINE_CLUSTERING))
    {
      xmlChar *clustering_config_str = xmlGetProp (tag, CLUSTERING_CONFIG);

      Online_SetClusteringConfig( (char *)clustering_config_str );

      XML_FREE(clustering_config_str);
    }
#endif
#if defined(HAVE_SPECTRAL)
    else if (!xmlStrcasecmp (tag->name, RC_ONLINE_SPECTRAL))
    {
      xmlChar *max_periods_str  = xmlGetProp (tag, SPECTRAL_MAX_PERIODS);
      xmlChar *num_iters_str    = xmlGetProp (tag, SPECTRAL_NUM_ITERS);
      xmlChar *min_seen_str     = xmlGetProp (tag, SPECTRAL_MIN_SEEN);
      xmlChar *min_likeness_str = xmlGetProp (tag, SPECTRAL_MIN_LIKENESS);
      int max_periods  = 0;

      if (max_periods_str != NULL)
      {
        if (strcmp((const char *)max_periods_str, "all") == 0) max_periods = 0;
        else max_periods = atoi((const char *)max_periods_str);
        Online_SetSpectralMaxPeriods ( max_periods );
      }
      if (num_iters_str    != NULL) 
      {
        Online_SetSpectralNumIters   ( atoi((const char *)num_iters_str) );
      }
      if (min_seen_str     != NULL) 
      {
        Online_SetSpectralMinSeen    ( atoi((const char *)min_seen_str) );
      }
      if (min_likeness_str != NULL) 
      {
        Online_SetSpectralMinLikeness( (atof((const char *)min_likeness_str) / 100.0) );
      }

      XML_FREE(max_periods_str);
      XML_FREE(num_iters_str);
      XML_FREE(min_seen_str);
      XML_FREE(min_likeness_str);

      Parse_XML_SpectralAdvanced(rank, xmldoc, tag->xmlChildrenNode);
    }
#endif
    else if (!xmlStrcasecmp (tag->name, RC_ONLINE_GREMLINS))
    {
      xmlChar *start_str     = xmlGetProp(tag, GREMLINS_START);
      xmlChar *increment_str = xmlGetProp(tag, GREMLINS_INCREMENT);
      xmlChar *roundtrip_str = xmlGetProp(tag, GREMLINS_ROUNDTRIP);
      xmlChar *loop_str      = xmlGetProp(tag, GREMLINS_LOOP);

      if (start_str != NULL)
      {
        Online_SetGremlinsStartCount ( atoi((const char *)start_str) );
      }
      if (increment_str != NULL)
      {
        Online_SetGremlinsIncrement ( atoi((const char *)increment_str) );
      }
      if (roundtrip_str != NULL)
      {
        if (strcmp((const char *)roundtrip_str, "yes") == 0)
        {
          Online_SetGremlinsRoundtrip ( 1 );
        }
      }
      if (loop_str != NULL)
      {
        if (strcmp((const char *)loop_str, "yes") == 0)
        {
          Online_SetGremlinsLoop( 1 );
        }
      }
    }
    tag = tag->next;
  }
}
Beispiel #7
0
/*  7.4  */
WML_STATUS WML_GetDTDID(UINT32      iBytes,
                        const BYTE* wmlDoc,
                        const char* iCharEnc,
                        UINT16      idBufLenU16,
                        UINT16    * publicID,
                        UINT16    * systemID)
{
/*
-----------------------------------------------------------------------------
*/
/*  Data structures */

  WML_STATUS	rc = WML_OK;
  SEncBuffers _buffers;
  WCHAR*		_uBuffer;

/* Code */

  /***** CHECK ARGUMENTS *****/
  if(!s_isInitialized) {
      wmlLOGs(WSL_LOG_ERROR, "Not initialized");
      return WML_ERROR_NOT_INITIALIZED;
  }

  if(!wmlDoc || !iCharEnc || !publicID || !systemID) {
      wmlLOGs(WSL_LOG_ERROR, "WML_GetDTDID: NULL pointer as argument");
      return WML_ERROR_EMPTY_ARG;
  }

  if((!iBytes) || (iBytes>=XML_BUFFER_SIZE)) {
      wmlLOGs(WSL_LOG_ERROR, "WML_GetDTDID: Invalid buffer size.");
      return WML_ERROR_INVALID_BUFFER_SIZE;
  }


  if(!getCharEncoding(iCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR, "Unknown character encoding: ",iCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  /***** PREPARE THE BUFFERS *****/
  _uBuffer           = XML_ALLOC((sizeof(WCHAR)*iBytes)+20);
  _buffers.m_enc     = getCharEncoding(iCharEnc);
  _buffers.m_src     = wmlDoc;
  _buffers.m_srcSize = iBytes;
  _buffers.m_dst     = _uBuffer;
  _buffers.m_dstSize = iBytes+(20/sizeof(WCHAR));

  /***** CONVERT *****/
  if(!convertToUnicode(&_buffers)) {
      rc = WML_ERROR_CONVERSION_FAILED;
  }
  /***** XML *****/
  else if(!getDTDID(0,
                    _uBuffer,
                    _buffers.m_dstSize,
                    idBufLenU16,
                    publicID,
                    systemID)) {
      rc = WML_ERROR_XMLPARSER_FAILED;
  }
  else {
      rc = WML_OK;
  }

  /***** RELEASE MEMORY *****/

  XML_FREE(_uBuffer);

  return rc;
}
Beispiel #8
0
/*  7.3  */
WML_STATUS WML_Encode(UINT32        iBytes,
                      const BYTE *  wmlDoc,
                      const char *  iCharEnc,
                      UINT32     *  oBytes,
                      BYTE       *  binDoc,
                      const char *  oCharEnc,
                      int        *  arraySize,
                      UINT16     ** metaHttpEquiv,
                      int        *  stringLength,
                      UINT16     ** metaContent,
                      const char *  altDTDID,
                      const BYTE *  URLofDoc)
{
/*
-----------------------------------------------------------------------------
*/
/*  Data structures */

  WML_STATUS	rc = WML_OK;
  SEncBuffers _buffers;
  WCHAR*		_uBuffer;
  SDocData   * _pWmlData;
  UINT32       _oSize = 0;

/* Code */

  if(oBytes) {
      _oSize  = *oBytes;
      *oBytes = 0;
  }


  /***** CHECK ARGUMENTS *****/
  if(!s_isInitialized) {
      wmlLOGs(WSL_LOG_ERROR, "Not initialized");
      return WML_ERROR_NOT_INITIALIZED;
  }

  if( !wmlDoc || !binDoc || !iCharEnc || !oCharEnc || !oBytes) {
      wmlLOGs(WSL_LOG_ERROR, "WML_Encode: NULL pointer as argument");
      return WML_ERROR_EMPTY_ARG;
  }

  if(!iBytes ||  !_oSize || (iBytes>=XML_BUFFER_SIZE)) {
      wmlLOGs(WSL_LOG_ERROR, "WML_Encode: Invalid buffer size.");
      return WML_ERROR_INVALID_BUFFER_SIZE;
  }

  if(!getCharEncoding(iCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR,
             "WML_Encode: Character set does not exist: ",iCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  if(!getCharEncoding(oCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR,
             "WML_Encode: Character set does not exist: ",oCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  /***** PREPARE THE BUFFERS *****/
  _uBuffer           = XML_ALLOC(sizeof(WCHAR)*iBytes);
  _buffers.m_enc     = getCharEncoding(iCharEnc);
  _buffers.m_src     = wmlDoc;
  _buffers.m_srcSize = iBytes;
  _buffers.m_dst     = _uBuffer;
  _buffers.m_dstSize = iBytes;

  /***** CONVERT *****/
  if(!convertToUnicode(&_buffers)) {
      XML_FREE(_uBuffer);
      return WML_ERROR_CONVERSION_FAILED;
  }

  /***** DATA STRUCTURES FOR CALLBACK FUNCTIONS *****/
  _pWmlData = newSDocData(oCharEnc,
                          oBytes,
                          binDoc,
                          arraySize,
                          metaHttpEquiv,
                          stringLength,
                          metaContent,
                          URLofDoc);

  /***** XML - WML *****/
  if (parseXML(_pWmlData,
               _uBuffer,
               _buffers.m_dstSize,
               TokenHandler,
               ErrorHandler,
               altDTDID,
               URLofDoc) != 0) {

      if(_pWmlData->m_error) {
          rc = _pWmlData->m_error;
      }
      else if(FIFO_EMPTY(_pWmlData->m_eventList)) {
          rc = WML_ERROR_XMLPARSER_FAILED;
      }
      else {
          *oBytes = _oSize;
          rc = isValidWMLDocument(_pWmlData);
          if(rc!=WML_OK) {
              *oBytes = 0;
          }
      }
  }
  else {
      rc = WML_ERROR_XMLPARSER_FAILED;
      if(_pWmlData->m_error) {
          rc = _pWmlData->m_error;
      }
  }

  /***** RELEASE MEMORY *****/
  deleteSDocData(_pWmlData);

  XML_FREE(_uBuffer);

  return rc;
}