Fix up GArrayFindSorted. This is why our arrays suck; we don't differentiate between reference arrays and value arrays.
This commit is contained in:
+1
-1
@@ -356,7 +356,7 @@ int BongoListVoidToInt (void * ptr);
|
||||
typedef int (*ArrayCompareFunc)(const void *, const void *);
|
||||
|
||||
int GArrayFindUnsorted(GArray *array, void *needle, ArrayCompareFunc compare);
|
||||
int GArrayFindSorted(GArray *array, void *needle, ArrayCompareFunc compare);
|
||||
int GArrayFindSorted(GArray *array, void *needle, ssize_t type_size, ArrayCompareFunc compare);
|
||||
|
||||
#if 0
|
||||
typedef struct _BongoArray BongoArray;
|
||||
|
||||
@@ -313,7 +313,7 @@ AddPushAgent(QueueClient *client,
|
||||
|
||||
/* first look through the list to find the right queue */
|
||||
tempQueue.queue = queue;
|
||||
ItemIndex = GArrayFindSorted(Queue.PushClients.queues, &p_tempQueue, FindQueue);
|
||||
ItemIndex = GArrayFindSorted(Queue.PushClients.queues, &p_tempQueue, sizeof(QueueList *), FindQueue);
|
||||
if (ItemIndex < 0) {
|
||||
/* there is no queue item in the array yet. we need to initialize one */
|
||||
CurrentQueue = MemNew0(QueueList, 1);
|
||||
@@ -326,7 +326,7 @@ AddPushAgent(QueueClient *client,
|
||||
|
||||
/* CurrentQueue should be set now */
|
||||
strncpy(tempPool.identifier, identifier, 100);
|
||||
ItemIndex = GArrayFindSorted(CurrentQueue->pools, &p_tempPool, FindPool);
|
||||
ItemIndex = GArrayFindSorted(CurrentQueue->pools, &p_tempPool, sizeof(QueuePoolList *), FindPool);
|
||||
if (ItemIndex < 0) {
|
||||
/* there is no pool already. we need to initialize one */
|
||||
CurrentPool = MemNew0(QueuePoolList, 1);
|
||||
@@ -1432,7 +1432,7 @@ StartOver:
|
||||
|
||||
/* i want to get the current queue and iterate over its pools if there are any */
|
||||
tempQueue.queue = queue;
|
||||
ItemIndex = GArrayFindSorted(Queue.PushClients.queues, &p_tempQueue, FindQueue);
|
||||
ItemIndex = GArrayFindSorted(Queue.PushClients.queues, &p_tempQueue, sizeof(QueueList *), FindQueue);
|
||||
if (ItemIndex >= 0) {
|
||||
QueueList *CurrentQueue = g_array_index(Queue.PushClients.queues, QueueList *, ItemIndex);
|
||||
for (iter_p=0; iter_p < CurrentQueue->pools->len; iter_p++) {
|
||||
|
||||
@@ -158,7 +158,7 @@ BOOL aliasing(char *addr, int *cnt, unsigned char *buffer) {
|
||||
}
|
||||
|
||||
/* if i get here, i've got a domain name that i can look up in the alias system */
|
||||
i = GArrayFindSorted(Conf.aliasList, domain, (ArrayCompareFunc)aliasFindFunc);
|
||||
i = GArrayFindSorted(Conf.aliasList, domain, sizeof(struct _AliasStruct), (ArrayCompareFunc)aliasFindFunc);
|
||||
if (i > -1) {
|
||||
char new_addr[1000]; /* FIXME: seems a bit large */
|
||||
AliasStruct a;
|
||||
@@ -167,7 +167,7 @@ BOOL aliasing(char *addr, int *cnt, unsigned char *buffer) {
|
||||
a = g_array_index(Conf.aliasList, AliasStruct, i);
|
||||
|
||||
/* user aliases should take precedence over domain aliases. check for one of those first */
|
||||
if (a.aliases && a.aliases->len && ((i = GArrayFindSorted(a.aliases, local, (ArrayCompareFunc)aliasFindFunc)) > -1)) {
|
||||
if (a.aliases && a.aliases->len && ((i = GArrayFindSorted(a.aliases, local, sizeof(struct _AliasStruct), (ArrayCompareFunc)aliasFindFunc)) > -1)) {
|
||||
AliasStruct b;
|
||||
b = g_array_index(a.aliases, AliasStruct, i);
|
||||
result = aliasing(b.to, cnt, buffer);
|
||||
@@ -253,10 +253,11 @@ int CommandAddressResolve(void *param) {
|
||||
|
||||
int CommandDomainLocation(void *param) {
|
||||
QueueClient *client = (QueueClient *)param;
|
||||
|
||||
// FIXME: is this actually used at all with our current aliasing stuff?
|
||||
/* first find the domain in the request */
|
||||
unsigned char *domain = client->buffer + 16;
|
||||
|
||||
|
||||
#if 0
|
||||
/* now search for it */
|
||||
int idx = GArrayFindSorted(Conf.hostedDomains, domain, (ArrayCompareFunc)hostedFindFunc);
|
||||
if (idx > -1) {
|
||||
@@ -265,6 +266,8 @@ int CommandDomainLocation(void *param) {
|
||||
/* TODO: add the relay domain stuff */
|
||||
ConnWriteF(client->conn, MSG1002REMOTE"\r\n", domain);
|
||||
}
|
||||
#endif
|
||||
ConnWriteF(client->conn, MSG1000LOCAL"\r\n", domain);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -428,7 +431,7 @@ CheckTrustedHost(QueueClient *client)
|
||||
if (Conf.trustedHosts) {
|
||||
/* TODO: this can be optimized a little bit */
|
||||
XplRWReadLockAcquire(&Conf.lock);
|
||||
i = GArrayFindSorted(Conf.trustedHosts, inet_ntoa(client->conn->socketAddress.sin_addr), (ArrayCompareFunc)hostedFindFunc);
|
||||
i = GArrayFindSorted(Conf.trustedHosts, inet_ntoa(client->conn->socketAddress.sin_addr), sizeof (char *), (ArrayCompareFunc)hostedFindFunc);
|
||||
XplRWReadLockRelease(&Conf.lock);
|
||||
}
|
||||
return (i > -1);
|
||||
|
||||
@@ -596,7 +596,7 @@ BongoCalObjectGetInstance(BongoCalObject *cal, const char *uid, BongoCalTime rec
|
||||
data.uid = uid;
|
||||
data.recurid = recurid;
|
||||
|
||||
i = GArrayFindSorted(cal->instances, &data, FindInstanceById);
|
||||
i = GArrayFindSorted(cal->instances, &data, sizeof(BongoCalInstance *), FindInstanceById);
|
||||
if (i != -1) {
|
||||
return g_array_index(cal->instances, BongoCalInstance *, i);
|
||||
} else {
|
||||
|
||||
@@ -20,9 +20,8 @@ GArrayFindUnsorted(GArray *array, void *needle, ArrayCompareFunc compare)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: the old function had a char *. should this be more generic somehow? */
|
||||
int
|
||||
GArrayFindSorted(GArray *array, void *needle, ArrayCompareFunc compare)
|
||||
GArrayFindSorted(GArray *array, void *needle, ssize_t type_size, ArrayCompareFunc compare)
|
||||
{
|
||||
void *data;
|
||||
|
||||
@@ -30,10 +29,10 @@ GArrayFindSorted(GArray *array, void *needle, ArrayCompareFunc compare)
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = bsearch(needle, array->data, array->len, sizeof(char *), compare);
|
||||
data = bsearch(needle, array->data, array->len, type_size, compare);
|
||||
|
||||
if (data) {
|
||||
return ((char*)data - (char*)array->data) / sizeof(char *);
|
||||
return ((void *)data - (void *)array->data) / type_size;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user