Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / lib / registry / patchfile_dotreg.c
index 5150c90291524e48d4ed1a8b5d14329131b6ecad..70437a1087a49a5ba2944fe2b1462119def88742 100644 (file)
@@ -3,7 +3,7 @@
    Reading .REG files
 
    Copyright (C) Jelmer Vernooij 2004-2007
-   Copyright (C) Wilco Baan Hofman 2006
+   Copyright (C) Wilco Baan Hofman 2006-2008
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-/* FIXME Newer .REG files, created by Windows XP and above use unicode UTF-16 */
+/* FIXME Newer .REG files, created by Windows XP and above use unicode UCS-2 */
 
 #include "includes.h"
-#include "lib/registry/patchfile.h"
 #include "lib/registry/registry.h"
 #include "system/filesys.h"
-#include "param/param.h"
 
 /**
  * @file
@@ -37,7 +35,6 @@
 
 struct dotreg_data {
        int fd;
-       struct smb_iconv_convenience *iconv_convenience;
 };
 
 static WERROR reg_dotreg_diff_add_key(void *_data, const char *key_name)
@@ -63,10 +60,12 @@ static WERROR reg_dotreg_diff_set_value(void *_data, const char *path,
                                        uint32_t value_type, DATA_BLOB value)
 {
        struct dotreg_data *data = (struct dotreg_data *)_data;
-
+       char *data_string = reg_val_data_string(NULL, 
+                                               value_type, value);
+       W_ERROR_HAVE_NO_MEMORY(data_string);
        fdprintf(data->fd, "\"%s\"=%s:%s\n",
-                       value_name, str_regtype(value_type),
-                       reg_val_data_string(NULL, data->iconv_convenience, value_type, value));
+                value_name, str_regtype(value_type), data_string);
+       talloc_free(data_string);
 
        return WERR_OK;
 }
@@ -101,7 +100,6 @@ static WERROR reg_dotreg_diff_del_all_values(void *callback_data,
  * Save registry diff
  */
 _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
-                                    struct smb_iconv_convenience *iconv_convenience,
                                     struct reg_diff_callbacks **callbacks,
                                     void **callback_data)
 {
@@ -110,11 +108,9 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
        data = talloc_zero(ctx, struct dotreg_data);
        *callback_data = data;
 
-       data->iconv_convenience = iconv_convenience;
-
        if (filename) {
-               data->fd = open(filename, O_CREAT, 0755);
-               if (data->fd == -1) {
+               data->fd = open(filename, O_CREAT|O_WRONLY, 0755);
+               if (data->fd < 0) {
                        DEBUG(0, ("Unable to open %s\n", filename));
                        return WERR_BADFILE;
                }
@@ -122,7 +118,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
                data->fd = STDOUT_FILENO;
        }
 
-       fdprintf(data->fd, "%s\n", HEADER_STRING);
+       fdprintf(data->fd, "%s\n\n", HEADER_STRING);
 
        *callbacks = talloc(ctx, struct reg_diff_callbacks);
 
@@ -140,7 +136,6 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
  * Load diff file
  */
 _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
-                                    struct smb_iconv_convenience *iconv_convenience,
                                     const struct reg_diff_callbacks *callbacks,
                                     void *callback_data)
 {
@@ -181,9 +176,11 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
                        /* Deleting key */
                        if (line[1] == '-') {
                                curkey = talloc_strndup(line, line+2, strlen(line)-3);
+                               W_ERROR_HAVE_NO_MEMORY(curkey);
 
                                error = callbacks->del_key(callback_data,
                                                           curkey);
+
                                if (!W_ERROR_IS_OK(error)) {
                                        DEBUG(0,("Error deleting key %s\n",
                                                curkey));
@@ -196,6 +193,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
                                continue;
                        }
                        curkey = talloc_strndup(mem_ctx, line+1, strlen(line)-2);
+                       W_ERROR_HAVE_NO_MEMORY(curkey);
 
                        error = callbacks->add_key(callback_data, curkey);
                        if (!W_ERROR_IS_OK(error)) {
@@ -245,7 +243,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
                        q++;
                }
 
-               reg_string_to_val(line, iconv_convenience, 
+               reg_string_to_val(line, 
                                  q?p:"REG_SZ", q?q:p,
                                  &value_type, &value);