From 1f1f048efca04e69d8a2390326a8e76d84480f36 Mon Sep 17 00:00:00 2001 From: Mark Haverkamp Date: Wed, 15 Jun 2005 21:09:42 +0000 Subject: [PATCH] Fix version handling code to be B spec compliant. BUG 623. (Logical change 1.206) git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@665 fd59a12c-fef9-0310-b244-a6a79926bd2f --- lib/util.c | 54 +++++++++++++++++++++++++++++++++++++++++++------- lib/util.h | 3 ++- test/testevt.c | 19 ++++++++---------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/lib/util.c b/lib/util.c index 569526ee..0f818776 100644 --- a/lib/util.c +++ b/lib/util.c @@ -566,23 +566,63 @@ saHandleInstancePut ( SaErrorT saVersionVerify ( - struct saVersionDatabase *versionDatabase, - const SaVersionT *version) + struct saVersionDatabase *versionDatabase, + SaVersionT *version) { - int found = 0; int i; + SaErrorT error = SA_AIS_ERR_VERSION; if (version == 0) { - return (SA_AIS_ERR_VERSION); + return (SA_AIS_ERR_INVALID_PARAM); } + /* + * Look for a release code that we support. If we find it then + * make sure that the supported major version is >= to the required one. + * In any case we return what we support in the version structure. + */ for (i = 0; i < versionDatabase->versionCount; i++) { - if (memcmp (&versionDatabase->versionsSupported[i], version, sizeof (SaVersionT)) == 0) { - found = 1; + + /* + * Check if the caller requires and old release code that we don't support. + */ + if (version->releaseCode < versionDatabase->versionsSupported[i].releaseCode) { + break; + } + + /* + * Check if we can support this release code. + */ + if (version->releaseCode == versionDatabase->versionsSupported[i].releaseCode) { + + /* + * Check if we can support the major version requested. + */ + if (versionDatabase->versionsSupported[i].major >= version->major) { + error = SA_AIS_OK; + break; + } + + /* + * We support the release code, but not the major version. + */ break; } } - return (found ? SA_AIS_OK : SA_AIS_ERR_VERSION); + + /* + * If we fall out of the if loop, the caller requires a release code + * beyond what we support. + */ + if (i == versionDatabase->versionCount) { + i = versionDatabase->versionCount - 1; + } + + /* + * Tell the caller what we support + */ + memcpy(version, &versionDatabase->versionsSupported[i], sizeof(*version)); + return (error); } diff --git a/lib/util.h b/lib/util.h index 2a17e6eb..1979019e 100644 --- a/lib/util.h +++ b/lib/util.h @@ -153,7 +153,7 @@ saHandleInstancePut ( SaErrorT saVersionVerify ( struct saVersionDatabase *versionDatabase, - const SaVersionT *version); + SaVersionT *version); SaErrorT saQueueInit ( @@ -188,3 +188,4 @@ SaTimeT clustTimeNow(void); #endif /* AIS_UTIL_H_DEFINED */ + diff --git a/test/testevt.c b/test/testevt.c index 7fcc1892..442b6b60 100644 --- a/test/testevt.c +++ b/test/testevt.c @@ -83,13 +83,10 @@ void testresult (SaAisErrorT result, SaAisErrorT expected, int test_no) } SaVersionT version1 = { 'B', 0x01, 0x01 }; -SaVersionT version2 = { 'b', 0x01, 0x01 }; -SaVersionT version3 = { 'c', 0x01, 0x01 }; -SaVersionT version4 = { 'b', 0x02, 0x01 }; -SaVersionT version5 = { 'b', 0xff, 0x01 }; -SaVersionT version6 = { 'b', 0x01, 0xff }; -SaVersionT version7 = { 'B', 0xff, 0xff }; -SaVersionT version8 = { 'C', 0xff, 0xff }; +SaVersionT version2 = { 'A', 0x01, 0x01 }; +SaVersionT version3 = { 'B', 0x02, 0x01 }; +SaVersionT version4 = { 'B', 0x01, 0xff }; +SaVersionT version5 = { 'C', 0xff, 0xff }; struct version_test { SaVersionT *version; @@ -98,11 +95,11 @@ struct version_test { struct version_test versions[] = { { &version1, SA_AIS_OK }, - { &version2, SA_AIS_OK }, + { &version2, SA_AIS_ERR_VERSION }, { &version3, SA_AIS_ERR_VERSION }, - { &version4, SA_AIS_ERR_VERSION}, - { &version8, SA_AIS_ERR_VERSION}, - { 0, SA_AIS_ERR_VERSION} + { &version4, SA_AIS_OK}, + { &version5, SA_AIS_ERR_VERSION}, + { 0, SA_AIS_ERR_INVALID_PARAM} }; int version_size = sizeof(versions) / sizeof(struct version_test);