r6572: add "string_array" as new scalar type for handling SPOOLSS string array's
authorStefan Metzmacher <metze@samba.org>
Mon, 2 May 2005 13:37:05 +0000 (13:37 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:26 +0000 (13:16 -0500)
metze

source/build/pidl/ndr_header.pm
source/build/pidl/typelist.pm
source/librpc/idl/idl_types.h
source/librpc/idl/spoolss.idl
source/librpc/ndr/ndr_string.c

index ddd4fa1eb34041ef860f849cefe1b41fbf2a76cf..f40810a84d822921f8729d45589dd6dfd253da5f 100644 (file)
@@ -60,7 +60,7 @@ sub HeaderElement($)
     pidl tabs();
     HeaderType($element, $element->{TYPE}, "");
     pidl " ";
-    if ($element->{POINTERS} && $element->{TYPE} ne "string") {
+    if ($element->{POINTERS} && not $element->{TYPE} =~ "string") {
            for (my($i)=$element->{POINTERS}; $i > 0; $i--) {
                    pidl "*";
            }
index d9d545f0609f03964e5ac901fb7be2d9cad85561..9045e86bfdddf6634b981da5f6f1e00f547ec473 100644 (file)
@@ -86,6 +86,10 @@ my $scalars = {
                                C_TYPE          => "const char *",
                                NDR_ALIGN       => 4 #???
                        },
+       "string_array"  => {
+                               C_TYPE          => "const char **",
+                               NDR_ALIGN       => 4 #???
+                       },
 
        # time types
        "time_t"        => {
index 65489100afab4a679df2269615192390d1b7e14a..024b5632d341582067c16515372ea9c640d2a8c3 100644 (file)
 */
 #define utf8string     [flag(STR_UTF8|STR_NULLTERM)] string
 
+/*
+  a null terminated UCS2 string
+*/
+#define nstring_array  [flag(STR_NULLTERM)] string_array
+
 #define NDR_NOALIGN       LIBNDR_FLAG_NOALIGN
 #define NDR_REMAINING     LIBNDR_FLAG_REMAINING
 #define NDR_ALIGN2        LIBNDR_FLAG_ALIGN2
index 5d909b4bedd00c04489061fbaf99b14f4b66a840..5d4e957f071ada73046f631c8ce4497879c18bf9 100644 (file)
                [relative] nstring *data_file;
                [relative] nstring *config_file;
                [relative] nstring *help_file;
-               [relative] nstring *dependent_files; /* array */
+               [relative] nstring_array *dependent_files;
                [relative] nstring *monitor_name;
                [relative] nstring *default_datatype;
        } spoolss_DriverInfo3;
                [relative] nstring *data_file;
                [relative] nstring *config_file;
                [relative] nstring *help_file;
-               [relative] nstring *dependent_files; /* array */
+               [relative] nstring_array *dependent_files;
                [relative] nstring *monitor_name;
                [relative] nstring *default_datatype;
-               [relative] nstring *previous_names; /* array */
+               [relative] nstring_array *previous_names;
        } spoolss_DriverInfo4;
 
        typedef struct {
                [relative] nstring *data_file;
                [relative] nstring *config_file;
                [relative] nstring *help_file;
-               [relative] nstring *dependent_files; /* array */
+               [relative] nstring_array *dependent_files;
                [relative] nstring *monitor_name;
                [relative] nstring *default_datatype;
-               [relative] nstring *previous_names; /* array */
+               [relative] nstring_array *previous_names;
                NTTIME driver_data;
                hyper driver_version;
                [relative] nstring *manufacturer_name;
index ee76508393ae24d51677521f24f84a26f1516534..aa612eca38bdda4d017b2a0cf14e98bdefca7314 100644 (file)
@@ -497,3 +497,75 @@ uint32_t ndr_size_string(int ret, const char * const* string, int flags)
        if(!(*string)) return ret;
        return ret+strlen(*string)+1;
 }
+
+/*
+  pull a general string array from the wire
+*/
+NTSTATUS ndr_pull_string_array(struct ndr_pull *ndr, int ndr_flags, const char ***_a)
+{
+       const char **a = *_a;
+       uint32_t count;
+
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+
+       for (count = 0;; count++) {
+               const char *s = NULL;
+               a = talloc_realloc(ndr, a, const char *, count + 2);
+               NT_STATUS_HAVE_NO_MEMORY(a);
+               a[count]   = NULL;
+               a[count+1]   = NULL;
+
+               NDR_CHECK(ndr_pull_string(ndr, ndr_flags, &s));
+               if (strcmp("", s)==0) {
+                       a[count] = NULL;
+                       break;
+               } else {
+                       a[count] = s;
+               }
+       }
+
+       *_a =a;
+       return NT_STATUS_OK;
+}
+
+/*
+  push a general string array onto the wire
+*/
+NTSTATUS ndr_push_string_array(struct ndr_push *ndr, int ndr_flags, const char **a)
+{
+       uint32_t count;
+
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+
+       for (count = 0; a && a[count]; count++) {
+               NDR_CHECK(ndr_push_string(ndr, ndr_flags, a[count]));
+       }
+
+       NDR_CHECK(ndr_push_string(ndr, ndr_flags, ""));
+
+       return NT_STATUS_OK;
+}
+
+void ndr_print_string_array(struct ndr_print *ndr, const char *name, const char **a)
+{
+       uint32_t count;
+       uint32_t i;
+
+       for (count = 0; a && a[count]; count++) {}
+
+       ndr->print(ndr, "%s: ARRAY(%d)", name, count);
+       ndr->depth++;
+       for (i=0;i<count;i++) {
+               char *idx=NULL;
+               asprintf(&idx, "[%d]", i);
+               if (idx) {
+                       ndr_print_string(ndr, idx, a[i]);
+                       free(idx);
+               }
+       }
+       ndr->depth--;
+}