From fb5b6bbc5aa941478d700e8fb3011c2a24c4d2d4 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Sun, 20 Apr 2008 18:17:15 +0000 Subject: Added proper UUID generation and changed the details of how way debug logging is done to now use a more effcient macro instead of a function call. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@649948 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_erl_driver.c | 99 ++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 42 deletions(-) (limited to 'src/couchdb/couch_erl_driver.c') diff --git a/src/couchdb/couch_erl_driver.c b/src/couchdb/couch_erl_driver.c index b5703f09..550cff9e 100644 --- a/src/couchdb/couch_erl_driver.c +++ b/src/couchdb/couch_erl_driver.c @@ -23,6 +23,7 @@ specific language governing permissions and limitations under the License. #ifndef WIN32 #include // for memcpy #endif +#include typedef struct { ErlDrvPort port; @@ -92,51 +93,65 @@ static int couch_drv_control(ErlDrvData drv_data, unsigned int command, const ch { #define COLLATE 0 #define COLLATE_NO_CASE 1 + #define UUID 2 couch_drv_data* pData = (couch_drv_data*)drv_data; - - UErrorCode status = U_ZERO_ERROR; - int collResult; - char response; - UCharIterator iterA; - UCharIterator iterB; - int32_t length; - - // 2 strings are in the buffer, consecutively - // The strings begin first with a 32 bit integer byte length, then the actual - // string bytes follow. - - // first 32bits are the length - memcpy(&length, pBuf, sizeof(length)); - pBuf += sizeof(length); - - // point the iterator at it. - uiter_setUTF8(&iterA, pBuf, length); - - pBuf += length; // now on to string b - - // first 32bits are the length - memcpy(&length, pBuf, sizeof(length)); - pBuf += sizeof(length); - - // point the iterator at it. - uiter_setUTF8(&iterB, pBuf, length); - - if (command == COLLATE) - collResult = ucol_strcollIter(pData->coll, &iterA, &iterB, &status); - else if (command == COLLATE_NO_CASE) - collResult = ucol_strcollIter(pData->collNoCase, &iterA, &iterB, &status); - else + switch(command) { + case UUID: + { + uuid_t uuid; + uuid_generate(uuid); + return return_control_result(&uuid, sizeof(uuid), rbuf, rlen); + } + + case COLLATE: + case COLLATE_NO_CASE: + { + UErrorCode status = U_ZERO_ERROR; + int collResult; + char response; + UCharIterator iterA; + UCharIterator iterB; + int32_t length; + + // 2 strings are in the buffer, consecutively + // The strings begin first with a 32 bit integer byte length, then the actual + // string bytes follow. + + // first 32bits are the length + memcpy(&length, pBuf, sizeof(length)); + pBuf += sizeof(length); + + // point the iterator at it. + uiter_setUTF8(&iterA, pBuf, length); + + pBuf += length; // now on to string b + + // first 32bits are the length + memcpy(&length, pBuf, sizeof(length)); + pBuf += sizeof(length); + + // point the iterator at it. + uiter_setUTF8(&iterB, pBuf, length); + + if (command == COLLATE) + collResult = ucol_strcollIter(pData->coll, &iterA, &iterB, &status); + else if (command == COLLATE_NO_CASE) + collResult = ucol_strcollIter(pData->collNoCase, &iterA, &iterB, &status); + + if (collResult < 0) + response = 0; //lt + else if (collResult > 0) + response = 1; //gt + else + response = 2; //eq + + return return_control_result(&response, sizeof(response), rbuf, rlen); + } + + default: return -1; - - if (collResult < 0) - response = 0; //lt - else if (collResult > 0) - response = 1; //gt - else - response = 2; //eq - - return return_control_result(&response, sizeof(response), rbuf, rlen); + } } ErlDrvEntry couch_driver_entry = { -- cgit v1.2.3