Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/util/data_blob.c

    r414 r745  
    3434_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name)
    3535{
     36        return data_blob_talloc_named(NULL, p, length, name);
     37}
     38
     39/**
     40 construct a data blob, using supplied TALLOC_CTX
     41**/
     42_PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name)
     43{
    3644        DATA_BLOB ret;
    3745
     
    4250
    4351        if (p) {
    44                 ret.data = (uint8_t *)talloc_memdup(NULL, p, length);
     52                ret.data = (uint8_t *)talloc_memdup(mem_ctx, p, length);
    4553        } else {
    46                 ret.data = talloc_array(NULL, uint8_t, length);
     54                ret.data = talloc_array(mem_ctx, uint8_t, length);
    4755        }
    4856        if (ret.data == NULL) {
     
    5260        talloc_set_name_const(ret.data, name);
    5361        ret.length = length;
    54         return ret;
    55 }
    56 
    57 /**
    58  construct a data blob, using supplied TALLOC_CTX
    59 **/
    60 _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name)
    61 {
    62         DATA_BLOB ret = data_blob_named(p, length, name);
    63 
    64         if (ret.data) {
    65                 talloc_steal(mem_ctx, ret.data);
    66         }
    67         return ret;
    68 }
    69 
    70 
    71 /**
    72  reference a data blob, to the supplied TALLOC_CTX. 
    73  Returns a NULL DATA_BLOB on failure
    74 **/
    75 _PUBLIC_ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob)
    76 {
    77         DATA_BLOB ret = *blob;
    78 
    79         ret.data = talloc_reference(mem_ctx, blob->data);
    80 
    81         if (!ret.data) {
    82                 return data_blob(NULL, 0);
    83         }
    8462        return ret;
    8563}
     
    154132print the data_blob as hex string
    155133**/
    156 _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
     134_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
    157135{
    158136        int i;
     
    174152}
    175153
     154_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
     155{
     156        int i;
     157        char *hex_string;
     158
     159        hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
     160        if (!hex_string) {
     161                return NULL;
     162        }
     163
     164        for (i = 0; i < blob->length; i++)
     165                slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]);
     166
     167        hex_string[(blob->length*2)] = '\0';
     168        return hex_string;
     169}
     170
    176171/**
    177172  useful for constructing data blobs in test suites, while
Note: See TracChangeset for help on using the changeset viewer.