Index: ossp-pkg/xds/TODO RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/TODO,v rcsdiff -q -kk '-r1.29' '-r1.30' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/TODO,v' 2>/dev/null --- TODO 2002/03/17 10:25:52 1.29 +++ TODO 2003/02/17 12:27:51 1.30 @@ -1,3 +1 @@ - change xds_init() to return xds_rc_t - Index: ossp-pkg/xds/xds.c RCS File: /v/ossp/cvs/ossp-pkg/xds/xds.c,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/xds/xds.c,v' 2>/dev/null --- xds.c 2002/03/17 10:25:53 1.9 +++ xds.c 2003/02/17 12:27:51 1.10 @@ -33,20 +33,21 @@ #include "xds_p.h" -xds_t *xds_init(xds_mode_t mode) +int xds_init(xds_t **xds, xds_mode_t mode) { xds_t *ctx; /* Sanity check parameter. */ + assert(xds != NULL); + if (xds == NULL) + return XDS_ERR_INVALID_ARG; assert(mode == XDS_ENCODE || mode == XDS_DECODE); - if (mode != XDS_ENCODE && mode != XDS_DECODE) { - errno = EINVAL; - return NULL; - } + if (mode != XDS_ENCODE && mode != XDS_DECODE) + return XDS_ERR_INVALID_ARG; /* Allocate context structure. */ if ((ctx = malloc(sizeof (struct xds_context))) == NULL) - return NULL; /* errno set by malloc(3) */ + return XDS_ERR_SYSTEM; /* errno set by malloc(3) */ /* Set mode of operation in context. */ ctx->mode = mode; @@ -62,17 +63,19 @@ ctx->engines_len = 0; ctx->engines_capacity = 0; - return ctx; + *xds = ctx; + + return XDS_OK; } -void xds_destroy(xds_t *xds) +int xds_destroy(xds_t *xds) { size_t i; /* Sanity check parameter. */ assert(xds != NULL); if (xds == NULL) - return; + return XDS_ERR_INVALID_ARG; /* Free allocated memory. */ assert(xds->buffer != NULL @@ -89,7 +92,7 @@ } free(xds); - return; + return XDS_OK; } int xds_setbuffer(xds_t *xds, xds_scope_t flag, void *buffer, Index: ossp-pkg/xds/xds.h.in RCS File: /v/ossp/cvs/ossp-pkg/xds/xds.h.in,v rcsdiff -q -kk '-r1.20' '-r1.21' -u '/v/ossp/cvs/ossp-pkg/xds/xds.h.in,v' 2>/dev/null --- xds.h.in 2002/03/17 10:25:53 1.20 +++ xds.h.in 2003/02/17 12:27:51 1.21 @@ -62,7 +62,8 @@ XDS_ERR_UNKNOWN_ENGINE = -5, XDS_ERR_INVALID_MODE = -6, XDS_ERR_UNDERFLOW = -7, - XDS_ERR_UNKNOWN = -8 + XDS_ERR_UNKNOWN = -8, + XDS_ERR_SYSTEM = -9 }; typedef enum { XDS_ENCODE, XDS_DECODE } xds_mode_t; @@ -75,8 +76,8 @@ void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args); -xds_t *xds_init (xds_mode_t); -void xds_destroy (xds_t *xds); +int xds_init (xds_t **xds, xds_mode_t); +int xds_destroy (xds_t *xds); int xds_register (xds_t *xds, const char *name, xds_engine_t engine, void *engine_context); int xds_unregister(xds_t *xds, const char *name); int xds_setbuffer (xds_t *xds, xds_scope_t flag, void *buffer, size_t buffer_len); @@ -91,7 +92,7 @@ assert(condition); \ if (!(condition)) \ return XDS_ERR_INVALID_ARG; \ - } while(XDS_FALSE) + } while (XDS_FALSE) #define xds_init_encoding_engine(size) \ do { \ @@ -103,7 +104,7 @@ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_OVERFLOW; \ - } while(XDS_FALSE) + } while (XDS_FALSE) #define xds_init_decoding_engine(size) \ do { \ @@ -115,7 +116,7 @@ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_UNDERFLOW; \ - } while(XDS_FALSE) + } while (XDS_FALSE) #define xds_declare_formatting_engine(func) \ int func(xds_t *, void *, void *, size_t, size_t *, va_list *) @@ -163,3 +164,4 @@ xds_declare_formatting_engine(xml_decode_string); #endif /* __XDS_H__ */ + Index: ossp-pkg/xds/xds_test_lib.c RCS File: /v/ossp/cvs/ossp-pkg/xds/xds_test_lib.c,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/xds/xds_test_lib.c,v' 2>/dev/null --- xds_test_lib.c 2002/03/17 10:25:53 1.9 +++ xds_test_lib.c 2003/02/17 12:27:51 1.10 @@ -42,9 +42,9 @@ /* Open a bunch of contextes and close them again. */ for (i = 0; i < sizeof (ctx) / sizeof (xds_t *); ++i) { if (i % 2 == 0) - ctx[i] = xds_init(XDS_ENCODE); + xds_init(&ctx[i], XDS_ENCODE); else - ctx[i] = xds_init(XDS_DECODE); + xds_init(&ctx[i], XDS_DECODE); if (ctx[i] == 0) { printf("Failed to initialize xds context: i = %d\n", i); @@ -57,7 +57,7 @@ #ifdef NDEBUG /* Check how the library deals with errorneous arguments. */ - if (xds_init((xds_mode_t) 42) != NULL || errno != EINVAL) { + if (xds_init(NULL, (xds_mode_t)42) != NULL || errno != EINVAL) { printf ("Called xds_init() with invalid mode but didn't get EINVAL.\n"); return 1; @@ -98,8 +98,7 @@ size_t i; /* Create context. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -199,8 +198,7 @@ size_t buffer_size; /* Create XDS context. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -288,8 +286,7 @@ size_t new_len; /* Create XDS context. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -411,8 +408,7 @@ xds_t *xds; /* Create XDS context. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -493,8 +489,7 @@ char buffer[] = "Hallo!Hallo!Hallo!"; /* Create XDS context. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -578,8 +573,7 @@ complain if it sees the second value -- what would mean that the args parameter was not resetted to the original value before the engine is restarted after buffer enlargement. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -658,8 +652,7 @@ /* Encode our copy of mystruct using our encoding callback. Then get a the buffer and destroy the context again. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -695,8 +688,7 @@ xds_destroy(xds); /* Now create a decoding context and decode the whole thing again. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } Index: ossp-pkg/xds/xds_test_xdr.c RCS File: /v/ossp/cvs/ossp-pkg/xds/xds_test_xdr.c,v rcsdiff -q -kk '-r1.10' '-r1.11' -u '/v/ossp/cvs/ossp-pkg/xds/xds_test_xdr.c,v' 2>/dev/null --- xds_test_xdr.c 2002/03/17 10:25:53 1.10 +++ xds_test_xdr.c 2003/02/17 12:27:51 1.11 @@ -66,8 +66,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -102,8 +101,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -171,8 +169,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -207,8 +204,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -272,8 +268,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -308,8 +303,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -381,8 +375,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -417,8 +410,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -464,8 +456,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -488,8 +479,7 @@ return 1; } - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -535,8 +525,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -559,8 +548,7 @@ return 1; } - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -603,8 +591,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -628,8 +615,7 @@ return 1; } - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -676,8 +662,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -700,8 +685,7 @@ return 1; } - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -767,8 +751,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -803,8 +786,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -868,8 +850,7 @@ xdr_destroy(&xdrs); /* Encode the values array using the XDS implementation. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -904,8 +885,7 @@ /* Now we decode the values again using the XDS implementation and compare them to our original values. Obviously, they should not differ. */ - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } Index: ossp-pkg/xds/xds_test_xml.c RCS File: /v/ossp/cvs/ossp-pkg/xds/xds_test_xml.c,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/xds/xds_test_xml.c,v' 2>/dev/null --- xds_test_xml.c 2002/03/17 10:25:53 1.8 +++ xds_test_xml.c 2003/02/17 12:27:52 1.9 @@ -53,8 +53,7 @@ size_t i; /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -85,8 +84,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -148,8 +146,7 @@ size_t i; /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -170,8 +167,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -226,8 +222,7 @@ size_t i; /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -248,8 +243,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -303,8 +297,7 @@ size_t i; /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -325,8 +318,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -380,8 +372,7 @@ /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -416,8 +407,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -482,8 +472,7 @@ /* Encode the values array, then decode it back and compare the numbers. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -518,8 +507,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -576,8 +564,7 @@ /* Encode the string, then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -598,8 +585,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -647,8 +633,7 @@ /* Encode the string, then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -669,8 +654,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -719,8 +703,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -741,8 +724,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -791,8 +773,7 @@ /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ - xds = xds_init(XDS_ENCODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } @@ -813,8 +794,7 @@ } xds_destroy(xds); - xds = xds_init(XDS_DECODE); - if (xds == NULL) { + if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; }