Ejemplo n.º 1
0
xmlChar *
xmlCharStrdup(const char *cur) {
    const char *p = cur;

    if (cur == NULL) return(NULL);
    while (*p != '\0') p++; /* non input consuming */
    return(xmlCharStrndup(cur, p - cur));
}
Ejemplo n.º 2
0
bool DTDParser::parse()
{
  QString fileName = QString::null;
  if (!KIO::NetAccess::download(m_dtdURL, fileName))
  {
    KMessageBox::error(0, i18n("<qt>Cannot download the DTD from <b>%1</b>.</qt>").arg( m_dtdURL.prettyURL(0, KURL::StripFileProtocol)));
    return false;
  }
  DTD::dtd_ptr = xmlParseDTD(NULL, xmlCharStrndup(fileName.utf8(), fileName.utf8().length()));
  if( DTD::dtd_ptr == NULL )
  {
     KMessageBox::error(0, i18n("Error while parsing the DTD.\nThe error message is:\n%1").arg("x"));
     return false;
//          xmlGenericError(xmlGenericErrorContext,                          "Could not parse %s\n", argv[1]);
  }
  KDialogBase dlg(0L, 0L, true, i18n("DTD - > DTEP Conversion"), KDialogBase::Ok | KDialogBase::Cancel);
  DTEPCreationDlg w(&dlg);
  dlg.setMainWidget(&w);
  QString name = QString((const char*)DTD::dtd_ptr->name);
  if (name == "none")
    name = QFileInfo(m_dtdURL.fileName()).baseName();
  w.dtdName->setText(name);
  w.nickName->setText(name);
  w.directory->setText(QFileInfo(m_dtdURL.fileName()).baseName());
  w.doctype->setText(QString((const char*)DTD::dtd_ptr->ExternalID));
  w.dtdURL->setText(QString((const char*)DTD::dtd_ptr->SystemID));
  if (!dlg.exec())
      return false;
  m_name = w.dtdName->text();
  m_nickName = w.nickName->text();
  m_doctype = w.doctype->text();
  m_doctype.replace(QRegExp("<!doctype", false), "");
  m_doctype = m_doctype.left(m_doctype.findRev(">"));
  m_dtdURLLine = w.dtdURL->text();
  m_defaultExtension = w.defaultExtension->text();
  m_caseSensitive = w.caseSensitive->isChecked();
  DTD::dirName = m_dtepDir + "/" + w.directory->text();
  KURL u;
  u.setPath(DTD::dirName);
  if (!QExtFileInfo::createDir(DTD::dirName)) {
    QuantaCommon::dirCreationError(0, u);
    return false;
  }
  DTD::dirName.append("/");
  if (DTD::dtd_ptr->elements)
  {
    xmlHashScan((xmlElementTablePtr)DTD::dtd_ptr->elements, (xmlHashScanner)saveElement, 0);
  } else
  {
     KMessageBox::error(0, i18n("No elements were found in the DTD."));
     return false;
  }
  xmlFreeDtd(DTD::dtd_ptr);
  writeDescriptionRC();

  return true;
}
Ejemplo n.º 3
0
static void
xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
    xmlURIPtr uri;
    int len;

    /*
     * Clear any existing data from the context
     */
    if (ctxt->protocol != NULL) {
        xmlFree(ctxt->protocol);
	ctxt->protocol = NULL;
    }
    if (ctxt->hostname != NULL) {
        xmlFree(ctxt->hostname);
	ctxt->hostname = NULL;
    }
    if (ctxt->path != NULL) {
        xmlFree(ctxt->path);
	ctxt->path = NULL;
    }
    if (ctxt->query != NULL) {
        xmlFree(ctxt->query);
	ctxt->query = NULL;
    }
    if (URL == NULL) return;

    uri = xmlParseURIRaw(URL, 1);
    if (uri == NULL)
	return;

    if ((uri->scheme == NULL) || (uri->server == NULL)) {
	xmlFreeURI(uri);
	return;
    }

    ctxt->protocol = xmlMemStrdup(uri->scheme);
    /* special case of IPv6 addresses, the [] need to be removed */
    if ((uri->server != NULL) && (*uri->server == '[')) {
        len = strlen(uri->server);
	if ((len > 2) && (uri->server[len - 1] == ']')) {
	    ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2);
	} else
	    ctxt->hostname = xmlMemStrdup(uri->server);
    } else
	ctxt->hostname = xmlMemStrdup(uri->server);
    if (uri->path != NULL)
	ctxt->path = xmlMemStrdup(uri->path);
    else
	ctxt->path = xmlMemStrdup("/");
    if (uri->query != NULL)
	ctxt->query = xmlMemStrdup(uri->query);
    if (uri->port != 0)
	ctxt->port = uri->port;

    xmlFreeURI(uri);
}
Ejemplo n.º 4
0
xmlChar*
PmmFastDecodeString( int charset,
                     const xmlChar *string,
                     const xmlChar *encoding)
{
    xmlCharEncodingHandlerPtr coder = NULL;
    xmlChar *retval = NULL;
    xmlBufferPtr in = NULL, out = NULL;

    if ( charset == XML_CHAR_ENCODING_UTF8 ) {
        return xmlStrdup( string );
    }
    else if ( charset == XML_CHAR_ENCODING_ERROR ) {
        coder = xmlFindCharEncodingHandler( (const char *) encoding );
    }
    else if ( charset == XML_CHAR_ENCODING_NONE ) {
        xs_warn("PmmFastDecodeString: no encoding found\n");
    }
    else {
        coder= xmlGetCharEncodingHandler( charset );
    }

    if ( coder != NULL ) {
        /* warn( "do encoding %s", string ); */
        in  = xmlBufferCreate();
        out = xmlBufferCreate();

        xmlBufferCat( in, string );
        if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) {
            retval = xmlCharStrndup((const char *)xmlBufferContent(out), xmlBufferLength(out));
        }
        else {
            xs_warn("PmmFastEncodeString: decoding error\n");
        }

        xmlBufferFree( in );
        xmlBufferFree( out );
        xmlCharEncCloseFunc( coder );
    }
    return retval;
}