Logo Search packages:      
Sourcecode: ldb version File versions  Download package

char* ldb_binary_encode ( void *  ctx,
struct ldb_val  val 
)

Encode a binary blob

This function encodes a binary blob using the encoding rules in RFC 2254 (Section 4). This function also escapes any non-printable characters.

Parameters:
ctx the memory context to allocate the return string in.
val the (potentially) binary data to be encoded
Returns:
the encoded data as a null terminated string
See also:
RFC 2252.

Definition at line 98 of file ldb_parse.c.

References ldb_val::data, and ldb_val::length.

{
      int i;
      char *ret;
      int len = val.length;
      unsigned char *buf = val.data;

      for (i=0;i<val.length;i++) {
            if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) {
                  len += 2;
            }
      }
      ret = talloc_array(mem_ctx, char, len+1);
      if (ret == NULL) return NULL;

      len = 0;
      for (i=0;i<val.length;i++) {
            if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) {
                  snprintf(ret+len, 4, "\\%02X", buf[i]);
                  len += 3;
            } else {
                  ret[len++] = buf[i];
            }
      }

      ret[len] = 0;

      return ret; 
}


Generated by  Doxygen 1.6.0   Back to index