Fix the mess with ldb includes.
[metze/samba/wip.git] / source4 / lib / ldb / common / ldb_debug.c
index 0a187cd62d48ebc18d3857ec1b978b3efbf8763b..f8009eb8a345403b64f85fe7985e45b5d22efe4b 100644 (file)
@@ -10,7 +10,7 @@
    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
-   version 2 of the License, or (at your option) any later version.
+   version 3 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +18,7 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -32,8 +31,7 @@
  *  Author: Andrew Tridgell
  */
 
-#include "includes.h"
-
+#include "ldb_private.h"
 
 /*
   this allows the user to choose their own debug function
@@ -77,10 +75,29 @@ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *
 {
        va_list ap;
        if (ldb->debug_ops.debug == NULL) {
-               return;
+               ldb_set_debug_stderr(ldb);
        }
        va_start(ap, fmt);
        ldb->debug_ops.debug(ldb->debug_ops.context, level, fmt, ap);
        va_end(ap);
 }
 
+
+/*
+  log a message, and set the ldb error string to the same message
+*/
+void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
+                  const char *fmt, ...)
+{
+       va_list ap;
+       char *msg;
+       va_start(ap, fmt);
+       msg = talloc_vasprintf(ldb, fmt, ap);
+       va_end(ap);
+       if (msg != NULL) {
+               ldb_set_errstring(ldb, msg);
+               ldb_debug(ldb, level, "%s", msg);
+       }
+       talloc_free(msg);
+}
+