コード例 #1
0
HarvestResult processHarvestFromFd(int fd, HarvestProcessor* harvestProcessor,
                                   bool shouldProcessData) {
    MwsHarvest_SaxUserData user_data;
    xmlSAXHandler saxHandler;
    xmlParserCtxtPtr ctxtPtr;
    HarvestResult result;
    result.status = -1;

    user_data.harvestProcessor = harvestProcessor;
    user_data.shouldProcessData = shouldProcessData;
    memset(&saxHandler, 0, sizeof(xmlSAXHandler));

    // Registering Sax callbacks
    saxHandler.endDocument = my_endDocument;
    saxHandler.startElement = my_startElement;
    saxHandler.endElement = my_endElement;
    saxHandler.characters = my_characters;
    saxHandler.warning = my_warning;
    saxHandler.error = my_error;
    saxHandler.fatalError = my_fatalError;

    // Locking libXML -- to allow multi-threaded use
    xmlLockLibrary();
    // Creating the IOParser context
    if ((ctxtPtr = xmlCreateIOParserCtxt(&saxHandler, &user_data,
                                         fdXmlInputReadCallback, nullptr, &fd,
                                         XML_CHAR_ENCODING_UTF8)) ==
        nullptr) {
        PRINT_WARN("Error while creating the ParserContext\n");
    }
        // Parsing the document
        else if ((result.status = xmlParseDocument(ctxtPtr)) == -1) {
        PRINT_WARN("Parsing XML document failed\n");
    }

    // Freeing the parser context
    if (ctxtPtr) {
        xmlFreeParserCtxt(ctxtPtr);
    }

    // Unlocking libXML -- to allow multi-threaded use
    xmlUnlockLibrary();

    result.numExpressions = user_data.parsedExpr;

    return result;
}
コード例 #2
0
ファイル: crypto.c プロジェクト: Ashod/WinCairoRequirements
static void
exsltCryptoGcryptInit (void) {
    static int gcrypt_init;
    xmlLockLibrary ();

    if (!gcrypt_init) {
/* The function `gcry_check_version' must be called before any other
	 function in the library, because it initializes the thread support
	 subsystem in Libgcrypt. To achieve this in all generality, it is
	 necessary to synchronize the call to this function with all other calls
	 to functions in the library, using the synchronization mechanisms
	 available in your thread library. (from gcrypt.info)
*/
	gcry_check_version (GCRYPT_VERSION);
	gcrypt_init = 1;
    }

    xmlUnlockLibrary ();
}
コード例 #3
0
ファイル: readMwsQueryFromFd.cpp プロジェクト: KWARC/tema-mws
MwsQuery* readMwsQueryFromFd(int fd)
{
    MwsQuery_SaxUserData user_data;
    xmlSAXHandler        saxHandler;
    xmlParserCtxtPtr     ctxtPtr;
    int                  ret;

    // Initializing the SAX Handler
    memset(&saxHandler, 0, sizeof(xmlSAXHandler));

    // Registering Sax callbacks with defined ones

    //internalSubsetSAXFunc        internalSubset;
    //isStandaloneSAXFunc          isStandalone;
    //hasInternalSubsetSAXFunc     hasInternalSubset;
    //hasExternalSubsetSAXFunc     hasExternalSubset;
    //resolveEntitySAXFunc         resolveEntity;
    saxHandler.getEntity     = my_getEntity;               // STUB
    //entityDeclSAXFunc            entityDecl;
    //notationDeclSAXFunc          notationDecl;
    //attributeDeclSAXFunc         attributeDecl;
    //elementDeclSAXFunc           elementDecl;
    //unparsedEntityDeclSAXFunc    unparsedEntityDecl;
    //setDocumentLocatorSAXFunc    setDocumentLocator;
    saxHandler.startDocument = my_startDocument;
    saxHandler.endDocument   = my_endDocument;
    saxHandler.startElement  = my_startElement;
    saxHandler.endElement    = my_endElement;
    //referenceSAXFunc             reference;
    saxHandler.characters    = my_characters;
    //ignorableWhitespaceSAXFunc   ignorableWhitespace;
    //processingInstructionSAXFunc processingInstruction;
    //commentSAXFunc               comment;
    saxHandler.warning       = my_warning;
    saxHandler.error         = my_error;
    saxHandler.fatalError    = my_fatalError;

    // Locking libXML -- to allow multi-threaded use
    xmlLockLibrary();
    
    // Creating the IOParser context
    ctxtPtr = xmlCreateIOParserCtxt(&saxHandler,
                                    &user_data,
                                    fdXmlInputReadCallback,
                                    NULL,
                                    &fd,
                                    XML_CHAR_ENCODING_UTF8);
    if (ctxtPtr == NULL)
    {
        fprintf(stderr, "Error while creating the ParserContext\n");
        xmlUnlockLibrary();
        return NULL;
    }
  
    ret = xmlParseDocument(ctxtPtr);
    if (ret == -1)
    {
        fprintf(stderr, "Parsing failed\n");
    }

    if (!ctxtPtr->wellFormed)
    {
        fprintf(stderr, "Bad XML document\n");
    }

    // Freeing the parser context
    xmlFreeParserCtxt(ctxtPtr);

    // Unlocking libXML -- to allow multi-threaded use
    xmlUnlockLibrary();

    return user_data.result;
}
コード例 #4
0
string
verifyMwsMessageTypeFromFd(int fd)
{
#ifdef TRACE_FUNC_CALLS
    LOG_TRACE_IN;
#endif

    MwsMessage_SaxUserData user_data;
    xmlSAXHandler          saxHandler;
    xmlParserCtxtPtr       ctxtPtr;
    int                    ret;

    // Initializing the SAX Handler
    memset(&saxHandler, 0, sizeof(xmlSAXHandler));

    // Registering Sax callbacks with defined ones

    //internalSubsetSAXFunc        internalSubset;
    //isStandaloneSAXFunc          isStandalone;
    //hasInternalSubsetSAXFunc     hasInternalSubset;
    //hasExternalSubsetSAXFunc     hasExternalSubset;
    //resolveEntitySAXFunc         resolveEntity;
    //saxHandler.getEntity     = my_getEntity;               // STUB
    //entityDeclSAXFunc            entityDecl;
    //notationDeclSAXFunc          notationDecl;
    //attributeDeclSAXFunc         attributeDecl;
    //elementDeclSAXFunc           elementDecl;
    //unparsedEntityDeclSAXFunc    unparsedEntityDecl;
    //setDocumentLocatorSAXFunc    setDocumentLocator;
    saxHandler.startDocument = my_startDocument;
    //saxHandler.endDocument   = my_endDocument;
    saxHandler.startElement  = my_startElement;
    //saxHandler.endElement    = my_endElement;
    //referenceSAXFunc             reference;
    //saxHandler.characters    = my_characters;
    //ignorableWhitespaceSAXFunc   ignorableWhitespace;
    //processingInstructionSAXFunc processingInstruction;
    //commentSAXFunc               comment;
    //saxHandler.warning       = my_warning;
    //saxHandler.error         = my_error;
    //saxHandler.fatalError    = my_fatalError;

    // Locking libXML -- to allow multi-threaded use
    xmlLockLibrary();
    
    // Creating the IOParser context
    if ((ctxtPtr = xmlCreateIOParserCtxt(&saxHandler,
                                         &user_data,
                                         fdXmlInputReadCallback,
                                         NULL,
                                         &fd,
                                         XML_CHAR_ENCODING_UTF8))
            == NULL)
    {
        fprintf(stderr, "Error while creating the ParserContext\n");
    }
    // Parsing the document
    else if ((ret = xmlParseDocument(ctxtPtr))
            == -1)
    {
        fprintf(stderr, "Parsing XML document failed\n");
    }

    // Freeing the parser context
    if (ctxtPtr)
        xmlFreeParserCtxt(ctxtPtr);

    // Unlocking libXML -- to allow multi-threaded use
    xmlUnlockLibrary();

    // Checking for found messages
    if (!user_data.messageTypeFound)
    {
      fprintf(stderr, "The message is not a known MWS message type\n");
    }

#ifdef TRACE_FUNC_CALLS
    LOG_TRACE_OUT;
#endif

    return user_data.messageType;
}