diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-11-22 10:31:06 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-11-22 10:31:06 -0800 |
commit | 07bb297329b9e9754d09dcb6d70417272a626619 (patch) | |
tree | c1bdcad5f080f8cfe2e876604177670061cdc101 /src/buffer.c | |
parent | f251dedaa31b48f7c05a4b53c112b40ebca890ef (diff) | |
download | xmlsec1-07bb297329b9e9754d09dcb6d70417272a626619.tar.gz xmlsec1-07bb297329b9e9754d09dcb6d70417272a626619.tar.bz2 xmlsec1-07bb297329b9e9754d09dcb6d70417272a626619.zip |
Imported Upstream version 1.2.14upstream/1.2.14
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 508 |
1 files changed, 254 insertions, 254 deletions
diff --git a/src/buffer.c b/src/buffer.c index 0efbfed2..c13fe44f 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,11 +1,11 @@ -/** +/** * XML Security Library (http://www.aleksey.com/xmlsec). * * Memory buffer. * * This is free software; see Copyright file in the source * distribution for preciese wording. - * + * * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> */ #include "globals.h" @@ -33,22 +33,22 @@ static xmlSecSize gInitialSize = 1024; /** * xmlSecBufferSetDefaultAllocMode: - * @defAllocMode: the new default buffer allocation mode. - * @defInitialSize: the new default buffer minimal intial size. - * + * @defAllocMode: the new default buffer allocation mode. + * @defInitialSize: the new default buffer minimal intial size. + * * Sets new global default allocation mode and minimal intial size. */ -void +void xmlSecBufferSetDefaultAllocMode(xmlSecAllocMode defAllocMode, xmlSecSize defInitialSize) { xmlSecAssert(defInitialSize > 0); - + gAllocMode = defAllocMode; gInitialSize = defInitialSize; } /** * xmlSecBufferCreate: - * @size: the intial size. + * @size: the intial size. * * Allocates and initalizes new memory buffer with given size. * Caller is responsible for calling #xmlSecBufferDestroy function @@ -56,83 +56,83 @@ xmlSecBufferSetDefaultAllocMode(xmlSecAllocMode defAllocMode, xmlSecSize defInit * * Returns: pointer to newly allocated buffer or NULL if an error occurs. */ -xmlSecBufferPtr +xmlSecBufferPtr xmlSecBufferCreate(xmlSecSize size) { xmlSecBufferPtr buf; int ret; - + buf = (xmlSecBufferPtr)xmlMalloc(sizeof(xmlSecBuffer)); if(buf == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "sizeof(xmlSecBuffer)=%d", sizeof(xmlSecBuffer)); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_MALLOC_FAILED, + "sizeof(xmlSecBuffer)=%d", sizeof(xmlSecBuffer)); + return(NULL); } - + ret = xmlSecBufferInitialize(buf, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); - xmlSecBufferDestroy(buf); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", size); + xmlSecBufferDestroy(buf); + return(NULL); } return(buf); } /** * xmlSecBufferDestroy: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Desrtoys buffer object created with #xmlSecBufferCreate function. */ -void +void xmlSecBufferDestroy(xmlSecBufferPtr buf) { xmlSecAssert(buf != NULL); - + xmlSecBufferFinalize(buf); xmlFree(buf); } /** * xmlSecBufferInitialize: - * @buf: the pointer to buffer object. - * @size: the initial buffer size. + * @buf: the pointer to buffer object. + * @size: the initial buffer size. * * Initializes buffer object @buf. Caller is responsible for calling * #xmlSecBufferFinalize function to free allocated resources. - * + * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferInitialize(xmlSecBufferPtr buf, xmlSecSize size) { xmlSecAssert2(buf != NULL, -1); buf->data = NULL; buf->size = buf->maxSize = 0; buf->allocMode = gAllocMode; - + return(xmlSecBufferSetMaxSize(buf, size)); } /** * xmlSecBufferFinalize: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Frees allocated resource for a buffer intialized with #xmlSecBufferInitialize * function. */ -void +void xmlSecBufferFinalize(xmlSecBufferPtr buf) { xmlSecAssert(buf != NULL); - xmlSecBufferEmpty(buf); + xmlSecBufferEmpty(buf); if(buf->data != 0) { - xmlFree(buf->data); + xmlFree(buf->data); } buf->data = NULL; buf->size = buf->maxSize = 0; @@ -140,83 +140,83 @@ xmlSecBufferFinalize(xmlSecBufferPtr buf) { /** * xmlSecBufferEmpty: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Empties the buffer. */ void xmlSecBufferEmpty(xmlSecBufferPtr buf) { xmlSecAssert(buf != NULL); - + if(buf->data != 0) { - xmlSecAssert(buf->maxSize > 0); + xmlSecAssert(buf->maxSize > 0); - memset(buf->data, 0, buf->maxSize); + memset(buf->data, 0, buf->maxSize); } buf->size = 0; } /** * xmlSecBufferGetData: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Gets pointer to buffer's data. * * Returns: pointer to buffer's data. */ -xmlSecByte* +xmlSecByte* xmlSecBufferGetData(xmlSecBufferPtr buf) { xmlSecAssert2(buf != NULL, NULL); - + return(buf->data); } /** * xmlSecBufferSetData: - * @buf: the pointer to buffer object. - * @data: the data. - * @size: the data size. + * @buf: the pointer to buffer object. + * @data: the data. + * @size: the data size. * * Sets the value of the buffer to @data. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferSetData(xmlSecBufferPtr buf, const xmlSecByte* data, xmlSecSize size) { int ret; - + xmlSecAssert2(buf != NULL, -1); xmlSecBufferEmpty(buf); if(size > 0) { - xmlSecAssert2(data != NULL, -1); - - ret = xmlSecBufferSetMaxSize(buf, size); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); - return(-1); + xmlSecAssert2(data != NULL, -1); + + ret = xmlSecBufferSetMaxSize(buf, size); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", size); + return(-1); } - - memcpy(buf->data, data, size); + + memcpy(buf->data, data, size); } - - buf->size = size; + + buf->size = size; return(0); } /** * xmlSecBufferGetSize: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Gets the current buffer data size. * * Returns: the current data size. */ -xmlSecSize +xmlSecSize xmlSecBufferGetSize(xmlSecBufferPtr buf) { xmlSecAssert2(buf != NULL, 0); @@ -225,44 +225,44 @@ xmlSecBufferGetSize(xmlSecBufferPtr buf) { /** * xmlSecBufferSetSize: - * @buf: the pointer to buffer object. - * @size: the new data size. + * @buf: the pointer to buffer object. + * @size: the new data size. * - * Sets new buffer data size. If necessary, buffer grows to - * have at least @size bytes. + * Sets new buffer data size. If necessary, buffer grows to + * have at least @size bytes. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferSetSize(xmlSecBufferPtr buf, xmlSecSize size) { int ret; - + xmlSecAssert2(buf != NULL, -1); ret = xmlSecBufferSetMaxSize(buf, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", size); + return(-1); } - - + + buf->size = size; return(0); } /** * xmlSecBufferGetMaxSize: - * @buf: the pointer to buffer object. + * @buf: the pointer to buffer object. * * Gets the maximum (allocated) buffer size. * * Returns: the maximum (allocated) buffer size. */ -xmlSecSize +xmlSecSize xmlSecBufferGetMaxSize(xmlSecBufferPtr buf) { xmlSecAssert2(buf != NULL, 0); @@ -271,104 +271,104 @@ xmlSecBufferGetMaxSize(xmlSecBufferPtr buf) { /** * xmlSecBufferSetMaxSize: - * @buf: the pointer to buffer object. - * @size: the new maximum size. + * @buf: the pointer to buffer object. + * @size: the new maximum size. * - * Sets new buffer maximum size. If necessary, buffer grows to - * have at least @size bytes. + * Sets new buffer maximum size. If necessary, buffer grows to + * have at least @size bytes. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferSetMaxSize(xmlSecBufferPtr buf, xmlSecSize size) { xmlSecByte* newData; xmlSecSize newSize = 0; - + xmlSecAssert2(buf != NULL, -1); if(size <= buf->maxSize) { - return(0); + return(0); } - + switch(buf->allocMode) { - case xmlSecAllocModeExact: - newSize = size + 8; - break; - case xmlSecAllocModeDouble: - newSize = 2 * size + 32; - break; + case xmlSecAllocModeExact: + newSize = size + 8; + break; + case xmlSecAllocModeDouble: + newSize = 2 * size + 32; + break; } if(newSize < gInitialSize) { - newSize = gInitialSize; + newSize = gInitialSize; } - + if(buf->data != NULL) { - newData = (xmlSecByte*)xmlRealloc(buf->data, newSize); + newData = (xmlSecByte*)xmlRealloc(buf->data, newSize); } else { - newData = (xmlSecByte*)xmlMalloc(newSize); + newData = (xmlSecByte*)xmlMalloc(newSize); } if(newData == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "size=%d", newSize); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_MALLOC_FAILED, + "size=%d", newSize); + return(-1); } - + buf->data = newData; buf->maxSize = newSize; if(buf->size < buf->maxSize) { - xmlSecAssert2(buf->data != NULL, -1); - memset(buf->data + buf->size, 0, buf->maxSize - buf->size); + xmlSecAssert2(buf->data != NULL, -1); + memset(buf->data + buf->size, 0, buf->maxSize - buf->size); } - + return(0); } /** * xmlSecBufferAppend: - * @buf: the pointer to buffer object. - * @data: the data. - * @size: the data size. + * @buf: the pointer to buffer object. + * @data: the data. + * @size: the data size. * * Appends the @data after the current data stored in the buffer. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferAppend(xmlSecBufferPtr buf, const xmlSecByte* data, xmlSecSize size) { int ret; - + xmlSecAssert2(buf != NULL, -1); if(size > 0) { - xmlSecAssert2(data != NULL, -1); - + xmlSecAssert2(data != NULL, -1); + ret = xmlSecBufferSetMaxSize(buf, buf->size + size); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", buf->size + size); - return(-1); - } - - memcpy(buf->data + buf->size, data, size); - buf->size += size; + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", buf->size + size); + return(-1); + } + + memcpy(buf->data + buf->size, data, size); + buf->size += size; } - + return(0); } /** * xmlSecBufferPrepend: - * @buf: the pointer to buffer object. - * @data: the data. - * @size: the data size. + * @buf: the pointer to buffer object. + * @data: the data. + * @size: the data size. * * Prepends the @data before the current data stored in the buffer. * @@ -377,93 +377,93 @@ xmlSecBufferAppend(xmlSecBufferPtr buf, const xmlSecByte* data, xmlSecSize size) int xmlSecBufferPrepend(xmlSecBufferPtr buf, const xmlSecByte* data, xmlSecSize size) { int ret; - + xmlSecAssert2(buf != NULL, -1); if(size > 0) { - xmlSecAssert2(data != NULL, -1); - - ret = xmlSecBufferSetMaxSize(buf, buf->size + size); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", buf->size + size); - return(-1); - } - - memmove(buf->data + size, buf->data, buf->size); - memcpy(buf->data, data, size); - buf->size += size; + xmlSecAssert2(data != NULL, -1); + + ret = xmlSecBufferSetMaxSize(buf, buf->size + size); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", buf->size + size); + return(-1); + } + + memmove(buf->data + size, buf->data, buf->size); + memcpy(buf->data, data, size); + buf->size += size; } - + return(0); } /** * xmlSecBufferRemoveHead: - * @buf: the pointer to buffer object. - * @size: the number of bytes to be removed. + * @buf: the pointer to buffer object. + * @size: the number of bytes to be removed. * * Removes @size bytes from the beginning of the current buffer. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferRemoveHead(xmlSecBufferPtr buf, xmlSecSize size) { xmlSecAssert2(buf != NULL, -1); - + if(size < buf->size) { - xmlSecAssert2(buf->data != NULL, -1); - - buf->size -= size; - memmove(buf->data, buf->data + size, buf->size); + xmlSecAssert2(buf->data != NULL, -1); + + buf->size -= size; + memmove(buf->data, buf->data + size, buf->size); } else { - buf->size = 0; + buf->size = 0; } if(buf->size < buf->maxSize) { - xmlSecAssert2(buf->data != NULL, -1); - memset(buf->data + buf->size, 0, buf->maxSize - buf->size); + xmlSecAssert2(buf->data != NULL, -1); + memset(buf->data + buf->size, 0, buf->maxSize - buf->size); } return(0); } /** * xmlSecBufferRemoveTail: - * @buf: the pointer to buffer object. - * @size: the number of bytes to be removed. + * @buf: the pointer to buffer object. + * @size: the number of bytes to be removed. * * Removes @size bytes from the end of current buffer. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferRemoveTail(xmlSecBufferPtr buf, xmlSecSize size) { xmlSecAssert2(buf != NULL, -1); if(size < buf->size) { - buf->size -= size; + buf->size -= size; } else { - buf->size = 0; + buf->size = 0; } if(buf->size < buf->maxSize) { - xmlSecAssert2(buf->data != NULL, -1); - memset(buf->data + buf->size, 0, buf->maxSize - buf->size); + xmlSecAssert2(buf->data != NULL, -1); + memset(buf->data + buf->size, 0, buf->maxSize - buf->size); } return(0); } /** * xmlSecBufferReadFile: - * @buf: the pointer to buffer object. - * @filename: the filename. + * @buf: the pointer to buffer object. + * @filename: the filename. * * Reads the content of the file @filename in the buffer. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferReadFile(xmlSecBufferPtr buf, const char* filename) { xmlSecByte buffer[1024]; FILE* f; @@ -474,43 +474,43 @@ xmlSecBufferReadFile(xmlSecBufferPtr buf, const char* filename) { f = fopen(filename, "rb"); if(f == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "fopen", - XMLSEC_ERRORS_R_IO_FAILED, - "filename=%s;errno=%d", - xmlSecErrorsSafeString(filename), - errno); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "fopen", + XMLSEC_ERRORS_R_IO_FAILED, + "filename=%s;errno=%d", + xmlSecErrorsSafeString(filename), + errno); + return(-1); } while(1) { len = fread(buffer, 1, sizeof(buffer), f); - if(len == 0) { + if(len == 0) { break; }else if(len < 0) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "fread", XMLSEC_ERRORS_R_IO_FAILED, - "filename=%s;errno=%d", + "filename=%s;errno=%d", xmlSecErrorsSafeString(filename), - errno); + errno); fclose(f); return(-1); } - ret = xmlSecBufferAppend(buf, buffer, len); - if(ret < 0) { + ret = xmlSecBufferAppend(buf, buffer, len); + if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecBufferAppend", XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", + "size=%d", len); fclose(f); return(-1); - } + } } fclose(f); @@ -519,101 +519,101 @@ xmlSecBufferReadFile(xmlSecBufferPtr buf, const char* filename) { /** * xmlSecBufferBase64NodeContentRead: - * @buf: the pointer to buffer object. - * @node: the pointer to node. + * @buf: the pointer to buffer object. + * @node: the pointer to node. * * Reads the content of the @node, base64 decodes it and stores the * result in the buffer. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferBase64NodeContentRead(xmlSecBufferPtr buf, xmlNodePtr node) { xmlChar* content; xmlSecSize size; int ret; - + xmlSecAssert2(buf != NULL, -1); xmlSecAssert2(node != NULL, -1); content = xmlNodeGetContent(node); if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeGetName(node)), - XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + xmlSecErrorsSafeString(xmlSecNodeGetName(node)), + XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } - + /* base64 decode size is less than input size */ ret = xmlSecBufferSetMaxSize(buf, xmlStrlen(content)); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); } - + ret = xmlSecBase64Decode(content, xmlSecBufferGetData(buf), xmlSecBufferGetMaxSize(buf)); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64Decode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64Decode", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); } size = ret; ret = xmlSecBufferSetSize(buf, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferSetSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); - xmlFree(content); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferSetSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", size); + xmlFree(content); + return(-1); } xmlFree(content); - + return(0); } /** * xmlSecBufferBase64NodeContentWrite: - * @buf: the pointer to buffer object. - * @node: the pointer to a node. - * @columns: the max line size fro base64 encoded data. + * @buf: the pointer to buffer object. + * @node: the pointer to a node. + * @columns: the max line size fro base64 encoded data. * * Sets the content of the @node to the base64 encoded buffer data. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBufferBase64NodeContentWrite(xmlSecBufferPtr buf, xmlNodePtr node, int columns) { xmlChar* content; - + xmlSecAssert2(buf != NULL, -1); xmlSecAssert2(node != NULL, -1); content = xmlSecBase64Encode(xmlSecBufferGetData(buf), xmlSecBufferGetSize(buf), columns); if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64Encode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64Encode", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } xmlNodeAddContent(node, content); xmlFree(content); - + return(0); } @@ -621,54 +621,54 @@ xmlSecBufferBase64NodeContentWrite(xmlSecBufferPtr buf, xmlNodePtr node, int col * * IO buffer * - ************************************************************************/ -static int xmlSecBufferIOWrite (xmlSecBufferPtr buf, - const xmlSecByte *data, - xmlSecSize size); -static int xmlSecBufferIOClose (xmlSecBufferPtr buf); + ************************************************************************/ +static int xmlSecBufferIOWrite (xmlSecBufferPtr buf, + const xmlSecByte *data, + xmlSecSize size); +static int xmlSecBufferIOClose (xmlSecBufferPtr buf); /** * xmlSecBufferCreateOutputBuffer: - * @buf: the pointer to buffer. + * @buf: the pointer to buffer. * - * Creates new LibXML output buffer to store data in the @buf. Caller is - * responsible for destroying @buf when processing is done. + * Creates new LibXML output buffer to store data in the @buf. Caller is + * responsible for destroying @buf when processing is done. * * Returns: pointer to newly allocated output buffer or NULL if an error * occurs. */ -xmlOutputBufferPtr +xmlOutputBufferPtr xmlSecBufferCreateOutputBuffer(xmlSecBufferPtr buf) { return(xmlOutputBufferCreateIO((xmlOutputWriteCallback)xmlSecBufferIOWrite, - (xmlOutputCloseCallback)xmlSecBufferIOClose, - buf, - NULL)); + (xmlOutputCloseCallback)xmlSecBufferIOClose, + buf, + NULL)); } -static int +static int xmlSecBufferIOWrite(xmlSecBufferPtr buf, const xmlSecByte *data, xmlSecSize size) { int ret; - + xmlSecAssert2(buf != NULL, -1); xmlSecAssert2(data != NULL, -1); - + ret = xmlSecBufferAppend(buf, data, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferAppend", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferAppend", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", size); + return(-1); } - - return(size); + + return(size); } -static int +static int xmlSecBufferIOClose(xmlSecBufferPtr buf) { xmlSecAssert2(buf != NULL, -1); - + /* just do nothing */ return(0); } |