LCOV - code coverage report
Current view: top level - lib/ldb/common - ldb_options.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 27 32 84.4 %
Date: 2024-01-11 09:59:51 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    ldb database library
       3             : 
       4             :    Copyright (C) Andrew Tridgell  2010
       5             : 
       6             :      ** NOTE! The following LGPL license applies to the ldb
       7             :      ** library. This does NOT imply that all of Samba is released
       8             :      ** under the LGPL
       9             : 
      10             :    This library is free software; you can redistribute it and/or
      11             :    modify it under the terms of the GNU Lesser General Public
      12             :    License as published by the Free Software Foundation; either
      13             :    version 3 of the License, or (at your option) any later version.
      14             : 
      15             :    This library is distributed in the hope that it will be useful,
      16             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      17             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18             :    Lesser General Public License for more details.
      19             : 
      20             :    You should have received a copy of the GNU Lesser General Public
      21             :    License along with this library; if not, see <http://www.gnu.org/licenses/>.
      22             : */
      23             : 
      24             : /*
      25             :  *  Name: ldb
      26             :  *
      27             :  *  Component: ldb options[] handling
      28             :  *
      29             :  *  Author: Andrew Tridgell
      30             :  */
      31             : 
      32             : #include "ldb_private.h"
      33             : 
      34             : /*
      35             :   find an option within an options array
      36             : 
      37             :   accepts the following forms:
      38             : 
      39             :      NAME
      40             :      NAME:value
      41             :      NAME=value
      42             : 
      43             :   returns a pointer into an element of the options[] array, or NULL is
      44             :   not found.
      45             : 
      46             :   For the NAME form, returns a pointer to an empty string (thus
      47             :   allowing for boolean options).
      48             :  */
      49    14250881 : const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
      50             :                                        const char *option_name)
      51             : {
      52    14250881 :         size_t len = strlen(option_name);
      53      270750 :         int i;
      54             : 
      55    14250881 :         if (options == NULL) {
      56    13941900 :                 return NULL;
      57             :         }
      58             : 
      59       68849 :         for (i=0; options[i]; i++) {
      60       37142 :                 if (strncmp(option_name, options[i], len) != 0) {
      61       29435 :                         continue;
      62             :                 }
      63        7707 :                 if (options[i][len] == ':' || options[i][len] == '=') {
      64        7707 :                         return &options[i][len+1];
      65             :                 }
      66           0 :                 if (options[i][len] == 0) {
      67           0 :                         return &options[i][len];
      68             :                 }
      69             :         }
      70             : 
      71       30627 :         return NULL;
      72             : }
      73             : 
      74      765871 : const char **ldb_options_copy(TALLOC_CTX *ctx, const char *options[])
      75             : {
      76             : 
      77      765871 :         size_t num_options = 0;
      78      765871 :         const char **copy = NULL;
      79      765871 :         size_t i = 0;
      80             : 
      81      765871 :         if (options == NULL) {
      82      746419 :                 return copy;
      83             :         }
      84             : 
      85       13262 :         for (i=0; options[i]; i++) {
      86        6864 :                 num_options++;
      87             :         }
      88             : 
      89        6398 :         copy = talloc_zero_array(ctx, const char *, num_options + 1);
      90        6398 :         if (copy == NULL) {
      91           0 :                 return copy;
      92             :         }
      93             : 
      94       13262 :         for (i=0; options[i]; i++) {
      95        6864 :                 copy[i] = talloc_strdup(copy, options[i]);
      96        6864 :                 if (copy[i] == NULL) {
      97           0 :                         TALLOC_FREE(copy);
      98           0 :                         return copy;
      99             :                 }
     100             :         }
     101        6317 :         return copy;
     102             : }
     103             : 
     104     2009206 : const char **ldb_options_get(struct ldb_context *ldb)
     105             : {
     106     2009206 :         return ldb->options;
     107             : }

Generated by: LCOV version 1.14