lib: Pass blob instead of &blob to gencache_set_data_blob
authorVolker Lendecke <vl@samba.org>
Wed, 2 Aug 2017 15:52:40 +0000 (17:52 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 29 Nov 2017 15:59:16 +0000 (16:59 +0100)
Passing a whole DATA_BLOB is cheap enough to simplify the callers: A caller
does not have to create a separate variable.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/gencache.c
source3/lib/gencache.h
source3/libsmb/dsgetdcname.c
source3/torture/torture.c
source3/winbindd/wb_dsgetdcname.c

index e73d1c52a0e346b01bad38641c393ce47470e99f..ab12fc1c531c29fd246a7bf44e395a0e8c46e59e 100644 (file)
@@ -252,7 +252,7 @@ static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
  * @retval false on failure
  **/
 
-bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
+bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
                            time_t timeout)
 {
        int ret;
@@ -268,7 +268,7 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
                return false;
        }
 
-       if ((keystr == NULL) || (blob == NULL)) {
+       if ((keystr == NULL) || (blob.data == NULL)) {
                return false;
        }
 
@@ -276,7 +276,7 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
                return false;
        }
 
-       if ((timeout != 0) && gencache_have_val(keystr, blob, timeout)) {
+       if ((timeout != 0) && gencache_have_val(keystr, &blob, timeout)) {
                DEBUG(10, ("Did not store value for %s, we already got it\n",
                           keystr));
                return true;
@@ -287,12 +287,12 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
        if (hdr_len == -1) {
                return false;
        }
-       if ((blob->length + (size_t)hdr_len) < blob->length) {
+       if ((blob.length + (size_t)hdr_len) < blob.length) {
                return false;
        }
 
        dbufs[0] = (TDB_DATA) { .dptr = (uint8_t *)hdr, .dsize = hdr_len };
-       dbufs[1] = (TDB_DATA) { .dptr = blob->data, .dsize = blob->length };
+       dbufs[1] = (TDB_DATA) { .dptr = blob.data, .dsize = blob.length };
 
        DEBUG(10, ("Adding cache entry with key=[%s] and timeout="
                   "[%s] (%d seconds %s)\n", keystr,
@@ -784,7 +784,7 @@ bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value,
 bool gencache_set(const char *keystr, const char *value, time_t timeout)
 {
        DATA_BLOB blob = data_blob_const(value, strlen(value)+1);
-       return gencache_set_data_blob(keystr, &blob, timeout);
+       return gencache_set_data_blob(keystr, blob, timeout);
 }
 
 struct gencache_iterate_blobs_state {
index 4371835599da8ea41bca05764768699fd8a3f10d..fa72a4aa466f35bbad9e4f5d6a7e94a9708bb0d0 100644 (file)
@@ -40,7 +40,7 @@ bool gencache_get_data_blob(const char *keystr, TALLOC_CTX *mem_ctx,
                            DATA_BLOB *blob,
                            time_t *timeout, bool *was_expired);
 bool gencache_stabilize(void);
-bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
+bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
                            time_t timeout);
 void gencache_iterate_blobs(void (*fn)(const char *key, DATA_BLOB value,
                                       time_t timeout, void *private_data),
index 92fc312c6a493e9a6f18fa9233987d5680b2a44b..ce0cc89899c0113c99972ada73690e75ebc1ab89 100644 (file)
@@ -154,7 +154,7 @@ static NTSTATUS dsgetdcname_cache_delete(TALLOC_CTX *mem_ctx,
 
 static NTSTATUS dsgetdcname_cache_store(TALLOC_CTX *mem_ctx,
                                        const char *domain_name,
-                                       const DATA_BLOB *blob)
+                                       DATA_BLOB blob)
 {
        time_t expire_time;
        char *key;
@@ -200,7 +200,8 @@ static NTSTATUS store_cldap_reply(TALLOC_CTX *mem_ctx,
        }
 
        if (r->domain_name) {
-               status = dsgetdcname_cache_store(mem_ctx, r->domain_name, &blob);
+               status = dsgetdcname_cache_store(mem_ctx, r->domain_name,
+                                                blob);
                if (!NT_STATUS_IS_OK(status)) {
                        goto done;
                }
@@ -209,7 +210,7 @@ static NTSTATUS store_cldap_reply(TALLOC_CTX *mem_ctx,
                }
        }
        if (r->dns_domain) {
-               status = dsgetdcname_cache_store(mem_ctx, r->dns_domain, &blob);
+               status = dsgetdcname_cache_store(mem_ctx, r->dns_domain, blob);
                if (!NT_STATUS_IS_OK(status)) {
                        goto done;
                }
index 5a29f7969ad52db5fe60ec5a4e6b85ea5beba125..f2363900b26061f50c64177993a3becdcfcf05f4 100644 (file)
@@ -10034,7 +10034,7 @@ static bool run_local_gencache(int dummy)
        blob = data_blob_string_const_null("bar");
        tm = time(NULL) + 60;
 
-       if (!gencache_set_data_blob("foo", &blob, tm)) {
+       if (!gencache_set_data_blob("foo", blob, tm)) {
                d_printf("%s: gencache_set_data_blob() failed\n", __location__);
                return False;
        }
@@ -10073,7 +10073,7 @@ static bool run_local_gencache(int dummy)
        blob.data = (uint8_t *)&v;
        blob.length = sizeof(v);
 
-       if (!gencache_set_data_blob("blob", &blob, tm)) {
+       if (!gencache_set_data_blob("blob", blob, tm)) {
                d_printf("%s: gencache_set_data_blob() failed\n",
                         __location__);
                return false;
index 125e98ade74f34717fd84cd7695357d6a144a4a8..8bd74198bcb0900b2c32948877d3319c6711b6ac 100644 (file)
@@ -153,7 +153,7 @@ NTSTATUS wb_dsgetdcname_gencache_set(const char *domname,
                return status;
        }
 
-       ok = gencache_set_data_blob(key, &blob, time(NULL)+3600);
+       ok = gencache_set_data_blob(key, blob, time(NULL)+3600);
 
        if (!ok) {
                DBG_WARNING("gencache_set_data_blob for key %s failed\n", key);