Example #1
0
int
dbmnz_find(void *handle, uschar *filename, uschar *keystring, int length,
  uschar **result, uschar **errmsg, BOOL *do_cache)
{
return dbmdb_find(handle, filename, keystring, length-1, result, errmsg,
  do_cache);
}
Example #2
0
File: dbmdb.c Project: Chaohua/exim
static int
dbmjz_find(void *handle, uschar *filename, const uschar *keystring, int length,
  uschar **result, uschar **errmsg, BOOL *do_cache)
{
uschar *key_item, *key_buffer, *key_p;
const uschar *key_elems = keystring;
int buflen, bufleft, key_item_len, sep = 0;

/* To a first approximation, the size of the lookup key needs to be about,
or less than, the length of the delimited list passed in + 1. */

buflen = length + 3;
key_buffer = store_get(buflen);

key_buffer[0] = '\0';

key_p = key_buffer;
bufleft = buflen;

/* In all cases of an empty list item, we can set 1 and advance by 1 and then
pick up the trailing NUL from the previous list item, EXCEPT when at the
beginning of the output string, in which case we need to supply that NUL
ourselves.  */
while ((key_item = string_nextinlist(&key_elems, &sep, key_p, bufleft)) != NULL)
  {
  key_item_len = Ustrlen(key_item) + 1;
  if (key_item_len == 1)
    {
    key_p[0] = '\0';
    if (key_p == key_buffer)
      {
      key_p[1] = '\0';
      key_item_len += 1;
      }
    }

  bufleft -= key_item_len;
  if (bufleft <= 0)
    {
    /* The string_nextinlist() will stop at buffer size, but we should always
    have at least 1 character extra, so some assumption has failed. */
    *errmsg = string_copy(US"Ran out of buffer space for joining elements");
    return DEFER;
    }
  key_p += key_item_len;
  }

if (key_p == key_buffer)
  {
  *errmsg = string_copy(US"empty list key");
  return FAIL;
  }

/* We do not pass in the final NULL; if needed, the list should include an
empty element to put one in. Boundary: key length 1, is a NULL */
key_item_len = key_p - key_buffer - 1;

DEBUG(D_lookup) debug_printf("NUL-joined key length: %d\n", key_item_len);

/* beware that dbmdb_find() adds 1 to length to get back terminating NUL, so
because we've calculated the real length, we need to subtract one more here */
return dbmdb_find(handle, filename,
    key_buffer, key_item_len - 1,
    result, errmsg, do_cache);
}