The branch, master has been updated
       via  185d06e122f1da75f3b0fa03c56565ced27907c9 (commit)
      from  a28b499e80cbbd459d22050c1f19e750d6855604 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 185d06e122f1da75f3b0fa03c56565ced27907c9
Author: Simo Sorce <i...@samba.org>
Date:   Sun Aug 30 16:07:44 2009 -0400

    ldb: cosmetic changes in ldb_dn
    
    - remove trailing spaces and tabs
    - shorten some variable names for readability
    - try to break superlong lines for readability

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/ldb/common/ldb_dn.c |  485 +++++++++++++++++++++++----------------
 1 files changed, 292 insertions(+), 193 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index 6f462dd..d905f47 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/lib/ldb/common/ldb_dn.c
@@ -1,4 +1,4 @@
-/* 
+/*
    ldb database library
 
    Copyright (C) Simo Sorce 2005
@@ -6,7 +6,7 @@
      ** NOTE! The following LGPL license applies to the ldb
      ** library. This does NOT imply that all of Samba is released
      ** under the LGPL
-   
+
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
@@ -52,7 +52,7 @@ struct ldb_dn_component {
        struct ldb_val cf_value;
 };
 
-struct ldb_dn_extended_component {
+struct ldb_dn_ext_component {
 
        char *name;
        struct ldb_val value;
@@ -69,18 +69,20 @@ struct ldb_dn {
        bool valid_case;
 
        char *linearized;
-       char *extended_linearized;
+       char *ext_linearized;
        char *casefold;
 
        unsigned int comp_num;
        struct ldb_dn_component *components;
 
-       unsigned int extended_comp_num;
-       struct ldb_dn_extended_component *extended_components;
+       unsigned int ext_comp_num;
+       struct ldb_dn_ext_component *ext_components;
 };
 
 /* strdn may be NULL */
-struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct ldb_context *ldb, 
const struct ldb_val *strdn)
+struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx,
+                                   struct ldb_context *ldb,
+                                   const struct ldb_val *strdn)
 {
        struct ldb_dn *dn;
 
@@ -92,14 +94,17 @@ struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct 
ldb_context *ldb, const
        dn->ldb = ldb;
 
        if (strdn->data && strdn->length) {
-               if (strdn->data[0] == '@') {
+               const char *data = (const char *)strdn->data;
+               size_t length = strdn->length;
+
+               if (data[0] == '@') {
                        dn->special = true;
-               } 
-               dn->extended_linearized = talloc_strndup(dn, (const char 
*)strdn->data, strdn->length);
-               LDB_DN_NULL_FAILED(dn->extended_linearized);
-       
-               if (strdn->data[0] == '<') {
-                       const char *p_save, *p = dn->extended_linearized;
+               }
+               dn->ext_linearized = talloc_strndup(dn, data, length);
+               LDB_DN_NULL_FAILED(dn->ext_linearized);
+
+               if (data[0] == '<') {
+                       const char *p_save, *p = dn->ext_linearized;
                        do {
                                p_save = p;
                                p = strstr(p, ">;");
@@ -107,16 +112,16 @@ struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct 
ldb_context *ldb, const
                                        p = p + 2;
                                }
                        } while (p);
-                       
-                       if (p_save == dn->extended_linearized) {
+
+                       if (p_save == dn->ext_linearized) {
                                dn->linearized = talloc_strdup(dn, "");
                        } else {
                                dn->linearized = talloc_strdup(dn, p_save);
                        }
                        LDB_DN_NULL_FAILED(dn->linearized);
                } else {
-                       dn->linearized = dn->extended_linearized;
-                       dn->extended_linearized = NULL;
+                       dn->linearized = dn->ext_linearized;
+                       dn->ext_linearized = NULL;
                }
        } else {
                dn->linearized = talloc_strdup(dn, "");
@@ -131,7 +136,9 @@ failed:
 }
 
 /* strdn may be NULL */
-struct ldb_dn *ldb_dn_new(void *mem_ctx, struct ldb_context *ldb, const char 
*strdn)
+struct ldb_dn *ldb_dn_new(void *mem_ctx,
+                         struct ldb_context *ldb,
+                         const char *strdn)
 {
        struct ldb_val blob;
        blob.data = strdn;
@@ -139,7 +146,9 @@ struct ldb_dn *ldb_dn_new(void *mem_ctx, struct ldb_context 
*ldb, const char *st
        return ldb_dn_from_ldb_val(mem_ctx, ldb, &blob);
 }
 
-struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx, struct ldb_context *ldb, const 
char *new_fmt, ...)
+struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx,
+                             struct ldb_context *ldb,
+                             const char *new_fmt, ...)
 {
        char *strdn;
        va_list ap;
@@ -155,7 +164,7 @@ struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx, struct 
ldb_context *ldb, const char
                talloc_free(strdn);
                return dn;
        }
-       
+
        return NULL;
 }
 
@@ -175,7 +184,8 @@ static int ldb_dn_escape_internal(char *dst, const char 
*src, int len)
                if (p - src == len) /* found no escapable chars */
                        break;
 
-               memcpy(d, s, p - s); /* copy the part of the string before the 
stop */
+               /* copy the part of the string before the stop */
+               memcpy(d, s, p - s);
                d += (p - s); /* move to current position */
 
                if (*p) { /* it is a normal escapable character */
@@ -195,7 +205,7 @@ static int ldb_dn_escape_internal(char *dst, const char 
*src, int len)
 
        /* return the length of the resulting string */
        return (l + (d - dst));
-} 
+}
 
 char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value)
 {
@@ -244,8 +254,8 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                return true;
        }
 
-       if (dn->extended_linearized) {
-               parse_dn = dn->extended_linearized;
+       if (dn->ext_linearized) {
+               parse_dn = dn->ext_linearized;
        } else {
                parse_dn = dn->linearized;
        }
@@ -267,11 +277,11 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
        /* make sure we free this if alloced previously before replacing */
        talloc_free(dn->components);
 
-       talloc_free(dn->extended_components);
-       dn->extended_components = NULL;
+       talloc_free(dn->ext_components);
+       dn->ext_components = NULL;
 
        /* in the common case we have 3 or more components */
-       /* make sure all components are zeroed, other functions depend on this 
*/
+       /* make sure all components are zeroed, other functions depend on it */
        dn->components = talloc_zero_array(dn, struct ldb_dn_component, 3);
        if ( ! dn->components) {
                return false;
@@ -313,7 +323,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                                        continue;
                                }
                        }
-                       
+
                        if (in_ex_name && *p == '=') {
                                *d++ = '\0';
                                p++;
@@ -324,46 +334,46 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                        }
 
                        if (in_ex_value && *p == '>') {
-                               const struct ldb_dn_extended_syntax 
*extended_syntax;
+                               const struct ldb_dn_extended_syntax *ext_syntax;
                                struct ldb_val ex_val = {
-                                       .data = ex_value,
+                                       .data = (uint8_t *)ex_value,
                                        .length = d - ex_value
                                };
-                                       
+
                                *d++ = '\0';
                                p++;
                                in_ex_value = false;
 
                                /* Process name and ex_value */
 
-                               dn->extended_components = talloc_realloc(dn,
-                                                                        
dn->extended_components,
-                                                                        struct 
ldb_dn_extended_component,
-                                                                        
dn->extended_comp_num + 1);
-                               if ( ! dn->extended_components) {
+                               dn->ext_components = talloc_realloc(dn,
+                                                                   
dn->ext_components,
+                                                                   struct 
ldb_dn_ext_component,
+                                                                   
dn->ext_comp_num + 1);
+                               if ( ! dn->ext_components) {
                                        /* ouch ! */
                                        goto failed;
                                }
 
-                               extended_syntax = 
ldb_dn_extended_syntax_by_name(dn->ldb, ex_name);
-                               if (!extended_syntax) {
+                               ext_syntax = 
ldb_dn_extended_syntax_by_name(dn->ldb, ex_name);
+                               if (!ext_syntax) {
                                        /* We don't know about this type of 
extended DN */
                                        goto failed;
                                }
 
-                               
dn->extended_components[dn->extended_comp_num].name = 
talloc_strdup(dn->extended_components, ex_name);
-                               if 
(!dn->extended_components[dn->extended_comp_num].name) {
+                               dn->ext_components[dn->ext_comp_num].name = 
talloc_strdup(dn->ext_components, ex_name);
+                               if (!dn->ext_components[dn->ext_comp_num].name) 
{
                                        /* ouch */
                                        goto failed;
                                }
-                               ret = extended_syntax->read_fn(dn->ldb, 
dn->extended_components,
-                                                              &ex_val, 
&dn->extended_components[dn->extended_comp_num].value);
+                               ret = ext_syntax->read_fn(dn->ldb, 
dn->ext_components,
+                                                         &ex_val, 
&dn->ext_components[dn->ext_comp_num].value);
                                if (ret != LDB_SUCCESS) {
                                        dn->invalid = true;
                                        goto failed;
                                }
 
-                               dn->extended_comp_num++;
+                               dn->ext_comp_num++;
 
                                if (*p == '\0') {
                                        /* We have reached the end (extended 
component only)! */
@@ -402,12 +412,14 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                                        is_oid = true;
                                } else
                                if ( ! isalpha(*p)) {
-                                       /* not a digit nor an alpha, invalid 
attribute name */
+                                       /* not a digit nor an alpha,
+                                        * invalid attribute name */
                                        dn->invalid = true;
                                        goto failed;
                                }
-                               
-                               /* Copy this character across from parse_dn, 
now we have trimmed out spaces */
+
+                               /* Copy this character across from parse_dn,
+                                * now we have trimmed out spaces */
                                *d++ = *p++;
                                continue;
                        }
@@ -420,7 +432,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                        }
 
                        if (trim && (*p != '=')) {
-                               /* spaces/tabs are not allowed in attribute 
names */
+                               /* spaces/tabs are not allowed */
                                dn->invalid = true;
                                goto failed;
                        }
@@ -432,7 +444,9 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                                trim = true;
                                l = 0;
 
-                               /* Terminate this string in d (which is a copy 
of parse_dn with spaces trimmed) */
+                               /* Terminate this string in d
+                                * (which is a copy of parse_dn
+                                *  with spaces trimmed) */
                                *d++ = '\0';
                                dn->components[dn->comp_num].name = 
talloc_strdup(dn->components, dt);
                                if ( ! dn->components[dn->comp_num].name) {
@@ -453,7 +467,8 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                        }
 
                        if (is_oid && ( ! (isdigit(*p) || (*p == '.')))) {
-                               /* not a digit nor a dot, invalid attribute oid 
*/
+                               /* not a digit nor a dot,
+                                * invalid attribute oid */
                                dn->invalid = true;
                                goto failed;
                        } else
@@ -601,7 +616,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                                        break;
                                }
 
-                               if (*p == ' ') { 
+                               if (*p == ' ') {
                                        if ( ! t) t = p;
                                } else {
                                        if ( t ) t = NULL;
@@ -609,7 +624,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
 
                                *d++ = *p++;
                                l++;
-                               
+
                                break;
                        }
 
@@ -630,9 +645,9 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
        }
 
        *d++ = '\0';
-       dn->components[dn->comp_num].value.data = (uint8_t 
*)talloc_strdup(dn->components, dt);
        dn->components[dn->comp_num].value.length = l;
-
+       dn->components[dn->comp_num].value.data =
+                               (uint8_t *)talloc_strdup(dn->components, dt);
        if ( ! dn->components[dn->comp_num].value.data) {
                /* ouch */
                goto failed;
@@ -676,8 +691,10 @@ const char *ldb_dn_get_linearized(struct ldb_dn *dn)
 
        /* calculate maximum possible length of DN */
        for (len = 0, i = 0; i < dn->comp_num; i++) {
-               len += strlen(dn->components[i].name); /* name len */
-               len += (dn->components[i].value.length * 3); /* max escaped 
data len */
+               /* name len */
+               len += strlen(dn->components[i].name);
+               /* max escaped data len */
+               len += (dn->components[i].value.length * 3);
                len += 2; /* '=' and ',' */
        }
        dn->linearized = talloc_array(dn, char, len);
@@ -703,7 +720,8 @@ const char *ldb_dn_get_linearized(struct ldb_dn *dn)
        *(--d) = '\0';
 
        /* don't waste more memory than necessary */
-       dn->linearized = talloc_realloc(dn, dn->linearized, char, (d - 
dn->linearized + 1));
+       dn->linearized = talloc_realloc(dn, dn->linearized,
+                                       char, (d - dn->linearized + 1));
 
        return dn->linearized;
 }
@@ -721,27 +739,26 @@ char *ldb_dn_get_extended_linearized(void *mem_ctx, 
struct ldb_dn *dn, int mode)
        if (!ldb_dn_has_extended(dn)) {
                return talloc_strdup(mem_ctx, linearized);
        }
-       
+
        if (!ldb_dn_validate(dn)) {
                return NULL;
        }
 
-       for (i=0; i < dn->extended_comp_num; i++) {
+       for (i = 0; i < dn->ext_comp_num; i++) {
+               const struct ldb_dn_extended_syntax *ext_syntax;
+               const char *name = dn->ext_components[i].name;
+               struct ldb_val ec_val = dn->ext_components[i].value;
                struct ldb_val val;
                int ret;
-               const struct ldb_dn_extended_syntax *extended_syntax;
-               const char *name = dn->extended_components[i].name;
-               
-               extended_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name);
+
+               ext_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name);
 
                if (mode == 1) {
-                       ret = extended_syntax->write_clear_fn(dn->ldb, mem_ctx,
-                                                             
&dn->extended_components[i].value,
-                                                             &val);
+                       ret = ext_syntax->write_clear_fn(dn->ldb, mem_ctx,
+                                                       &ec_val, &val);
                } else if (mode == 0) {
-                       ret = extended_syntax->write_hex_fn(dn->ldb, mem_ctx,
-                                                             
&dn->extended_components[i].value,
-                                                             &val);
+                       ret = ext_syntax->write_hex_fn(dn->ldb, mem_ctx,
+                                                       &ec_val, &val);
                } else {
                        ret = -1;
                }
@@ -751,9 +768,11 @@ char *ldb_dn_get_extended_linearized(void *mem_ctx, struct 
ldb_dn *dn, int mode)
                }
 
                if (i == 0) {
-                       p = talloc_asprintf(mem_ctx, "<%s=%s>", 
dn->extended_components[i].name, val.data);
+                       p = talloc_asprintf(mem_ctx, "<%s=%s>",
+                                                       name, val.data);
                } else {
-                       p = talloc_asprintf_append(p, ";<%s=%s>",  
dn->extended_components[i].name, val.data);
+                       p = talloc_asprintf_append(p, ";<%s=%s>",
+                                                       name, val.data);
                }
 
                talloc_free(val.data);
@@ -763,7 +782,7 @@ char *ldb_dn_get_extended_linearized(void *mem_ctx, struct 
ldb_dn *dn, int mode)
                }
        }
 
-       if (dn->extended_comp_num && *linearized) {
+       if (dn->ext_comp_num && *linearized) {
                p = talloc_asprintf_append(p, ";%s", linearized);
        }
 
@@ -782,7 +801,7 @@ char *ldb_dn_alloc_linearized(void *mem_ctx, struct ldb_dn 
*dn)
 }
 
 /*
-  casefold a dn. We need to casefold the attribute names, and canonicalize 
+  casefold a dn. We need to casefold the attribute names, and canonicalize
   attribute values of case insensitive attributes.
 */
 
@@ -801,12 +820,16 @@ static bool ldb_dn_casefold_internal(struct ldb_dn *dn)
        for (i = 0; i < dn->comp_num; i++) {
                const struct ldb_schema_attribute *a;
 
-               dn->components[i].cf_name = ldb_attr_casefold(dn->components, 
dn->components[i].name);
+               dn->components[i].cf_name =
+                       ldb_attr_casefold(dn->components,
+                                         dn->components[i].name);
                if (!dn->components[i].cf_name) {
                        goto failed;
                }
 
-               a = ldb_schema_attribute_by_name(dn->ldb, 
dn->components[i].cf_name);
+               a = ldb_schema_attribute_by_name(dn->ldb,
+                                                dn->components[i].cf_name);
+
                ret = a->syntax->canonicalise_fn(dn->ldb, dn->components,
                                                 &(dn->components[i].value),
                                                 &(dn->components[i].cf_value));
@@ -834,7 +857,7 @@ const char *ldb_dn_get_casefold(struct ldb_dn *dn)
 
        if (dn->casefold) return dn->casefold;
 
-       if (dn->special) { 
+       if (dn->special) {
                dn->casefold = talloc_strdup(dn, dn->linearized);
                if (!dn->casefold) return NULL;
                dn->valid_case = true;
@@ -852,8 +875,10 @@ const char *ldb_dn_get_casefold(struct ldb_dn *dn)
 
        /* calculate maximum possible length of DN */
        for (len = 0, i = 0; i < dn->comp_num; i++) {
-               len += strlen(dn->components[i].cf_name); /* name len */
-               len += (dn->components[i].cf_value.length * 3); /* max escaped 
data len */
+               /* name len */
+               len += strlen(dn->components[i].cf_name);
+               /* max escaped data len */
+               len += (dn->components[i].cf_value.length * 3);
                len += 2; /* '=' and ',' */
        }
        dn->casefold = talloc_array(dn, char, len);
@@ -878,7 +903,8 @@ const char *ldb_dn_get_casefold(struct ldb_dn *dn)
        *(--d) = '\0';
 
        /* don't waste more memory than necessary */
-       dn->casefold = talloc_realloc(dn, dn->casefold, char, 
strlen(dn->casefold) + 1);
+       dn->casefold = talloc_realloc(dn, dn->casefold,
+                                     char, strlen(dn->casefold) + 1);
 
        return dn->casefold;
 }
@@ -907,8 +933,13 @@ int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn 
*dn)
                         * we will avoid exploding and casfolding */
                        int dif;
                        dif = strlen(dn->linearized) - strlen(base->linearized);
-                       if (dif < 0) return dif;
-                       if (strcmp(base->linearized, &dn->linearized[dif]) == 
0) return 0;
+                       if (dif < 0) {
+                               return dif;
+                       }
+                       if (strcmp(base->linearized,
+                                  &dn->linearized[dif]) == 0) {
+                               return 0;
+                       }
                }
 
                if ( ! ldb_dn_casefold_internal(base)) {
@@ -943,15 +974,24 @@ int ldb_dn_compare_base(struct ldb_dn *base, struct 
ldb_dn *dn)
        n_dn = dn->comp_num - 1;
 
        while (n_base >= 0) {
+               char *b_name = base->components[n_base].cf_name;
+               char *dn_name = dn->components[n_dn].cf_name;
+
+               char *b_vdata = (char *)base->components[n_base].cf_value.data;
+               char *dn_vdata = (char *)dn->components[n_dn].cf_value.data;
+
+               size_t b_vlen = base->components[n_base].cf_value.length;
+               size_t dn_vlen = dn->components[n_dn].cf_value.length;
+
                /* compare attr names */
-               ret = strcmp(base->components[n_base].cf_name, 
dn->components[n_dn].cf_name);


-- 
Samba Shared Repository

Reply via email to