libxml2(capi)是否提供了一种方法来删除已注册的xmlOutputCallbacks集,而不删除所有已注册的输出回调?

libxml2(capi)是否提供了一种方法来删除已注册的xmlOutputCallbacks集,而不删除所有已注册的输出回调?,c,libxml2,C,Libxml2,我正在为libxml2开发一个定制的I/O层,在取消注册输出回调时遇到了一个奇怪的问题。似乎没有办法只删除一组输出回调。我错过什么了吗?如果下面的伪代码没有澄清这个问题,我可以提供一个工作示例 static int _in_matcher(const char* URI) {...} static void* _in_opener(const char* URI) {...} static int _in_reader(void *ctxt, char *in_buf, int buf_len

我正在为libxml2开发一个定制的I/O层,在取消注册输出回调时遇到了一个奇怪的问题。似乎没有办法只删除一组输出回调。我错过什么了吗?如果下面的伪代码没有澄清这个问题,我可以提供一个工作示例

static int _in_matcher(const char* URI)  {...}
static void* _in_opener(const char* URI) {...}
static int _in_reader(void *ctxt, char *in_buf, int buf_len) {...}
static int _in_closer(void *ctxt) {...}

int test_input_callbacks(const char *file_name)
{
    int handler = xmlRegisterInputCallbacks(
      _in_matcher,
      _in_opener,
      _in_reader,
      _in_closer,
    );

    ...
    xmlDocPtr doc = xmlParseFile(file_name);
    xmlFree(doc);
    ...
    xmlPopInputCallbacks();
}


static int   _out_matcher( const char *URI) {...}
static void* _out_opener( const char *URI) {...}
static int   _out_writer( void *ctxt, const char *out_buf, int buf_len) {...}
static int   _outcloser( void *ctxt) {...}

int test_output_callbacks(const char *file_name)
{
    int handler = xmlRegisterOutputCallbacks(
      _out_matcher,
      _out_opener,
      _out_writer,
      _out_closer,
    );

    ...
    int result = xmlSaveFormatFileEnc(URI, doc, NULL, 0);
    xmlFree(doc);
    ...

    /* There does not appear to be a function that 
    * removes _only_ the last output callbacks
    * registered!
    */
    ==> ?? xmlPopOutputCallbacks() ?? <==
}
static int\u in_matcher(const char*URI){…}
静态void*_在_opener(const char*URI){…}
静态int-in-u读取器(void*ctxt,char*in-u-buf,int-buf-len){…}
静态int _in _closer(void*ctxt){…}
int测试输入回调(常量字符*文件名)
{
int handler=xmlRegisterInputCallbacks(
_在比彻,
_在开场白中,
_在"读者"中,,
_再近一点,
);
...
xmlDocPtr doc=xmlParseFile(文件名);
xmlFree(doc);
...
xmlPopInputCallbacks();
}
静态整型输出匹配器(const char*URI){…}
静态void*\u out\u opener(const char*URI){…}
静态整数输出写入程序(void*ctxt,const char*out\u buf,int buf\u len){…}
静态int_outcloser(void*ctxt){…}
int测试输出回调(常量字符*文件名)
{
int handler=xmlRegisterOutputCallbacks(
_我们的对手,
_开瓶器,
_我们的作者,
_走近一点,
);
...
int result=xmlSaveFormatFileEnc(URI,doc,NULL,0);
xmlFree(doc);
...
/*似乎没有一个函数
*仅删除最后一次输出回调
*注册!
*/

==>?xmlPopOutputCallbacks()?除了参与API设计的人员之外,其他人可能无法回答此问题。我对API的设计没有深入了解,但这可能是一件复杂的事情。Pop对您有用,但一般情况下需要插入和删除逻辑,这会使API复杂化,从而带来有限的好处(如果你是唯一的消费者,那么你肯定知道你想要注册/重新注册的所有回调)。让我感兴趣的是,在代码库中有注册和弹出输入回调集的测试(libxm2-2.9.10/runtest.c:2950);以及安装和使用自定义I/O层的示例(in:,out:);和(IMHO)这是一种处理插入/删除逻辑的非常简单的方法,用于in/out。这让我想知道这是否是一个安全问题,以及为什么他们不提供只删除一个输出集的功能。我还将这个问题发布到了libxml2的bug跟踪器上。感谢您的回复!
int
xmlPopOutputCallbacks(void)
{                                                                                                                                                                                 
    if (!xmlOutputCallbackInitialized)
        return(-1);

    if (xmlOutputCallbackNr <= 0)
        return(-1);

    xmlOutputCallbackNr--;
    xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = NULL;
    xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = NULL;
    xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = NULL;
    xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = NULL;

    return(xmlOutputCallbackNr);
}