summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_erl_driver.c
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-04-20 18:17:15 +0000
committerDamien F. Katz <damien@apache.org>2008-04-20 18:17:15 +0000
commitfb5b6bbc5aa941478d700e8fb3011c2a24c4d2d4 (patch)
treebcc23ed4869f395e894f76ec3fb5e76f75a5ba98 /src/couchdb/couch_erl_driver.c
parentad230e67fb09883e2171291d5a42635f5e2addb9 (diff)
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
Diffstat (limited to 'src/couchdb/couch_erl_driver.c')
-rw-r--r--src/couchdb/couch_erl_driver.c99
1 files changed, 57 insertions, 42 deletions
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 <string.h> // for memcpy
#endif
+#include <uuid/uuid.h>
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 = {