Add support for double type in pidl.
[ira/wip.git] / librpc / ndr / ndr_basic.c
index 1d2b47c850b4e246c47f6ad07723fad79c35903b..d46590f0cb55e629c1a6b811d58b219660a835fc 100644 (file)
@@ -125,6 +125,18 @@ _PUBLIC_ enum ndr_err_code ndr_pull_uint32(struct ndr_pull *ndr, int ndr_flags,
        return NDR_ERR_SUCCESS;
 }
 
+/*
+  parse a double
+*/
+_PUBLIC_ enum ndr_err_code ndr_pull_double(struct ndr_pull *ndr, int ndr_flags, double *v)
+{
+       NDR_PULL_ALIGN(ndr, 8);
+       NDR_PULL_NEED_BYTES(ndr, 8);
+       memcpy(v, ndr->data+ndr->offset, 8);
+       ndr->offset += 8;
+       return NDR_ERR_SUCCESS;
+}
+
 /*
   parse a pointer referent identifier
 */
@@ -388,6 +400,18 @@ _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, int ndr_flags, u
        return ndr_push_udlong(ndr, NDR_SCALARS, v);
 }
 
+/*
+  push a double
+*/
+_PUBLIC_ enum ndr_err_code ndr_push_double(struct ndr_push *ndr, int ndr_flags, double v)
+{
+       NDR_PUSH_ALIGN(ndr, 8);
+       NDR_PUSH_NEED_BYTES(ndr, 8);
+       memcpy(ndr->data+ndr->offset, &v, 8);
+       ndr->offset += 8;
+       return NDR_ERR_SUCCESS;
+}
+
 /*
   push a pointer
 */
@@ -506,7 +530,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME(struct ndr_pull *ndr, int ndr_flags,
 }
 
 /*
-  push a NTTIME
+  push a NTTIME_1sec
 */
 _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec(struct ndr_push *ndr, int ndr_flags, NTTIME t)
 {
@@ -568,9 +592,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_time_t(struct ndr_pull *ndr, int ndr_flags,
 */
 _PUBLIC_ enum ndr_err_code ndr_pull_ipv4address(struct ndr_pull *ndr, int ndr_flags, const char **address)
 {
+       uint32_t addr;
        struct in_addr in;
-       NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &in.s_addr));
-       in.s_addr = htonl(in.s_addr);
+       NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &addr));
+       in.s_addr = htonl(addr);
        *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in));
        NDR_ERR_HAVE_NO_MEMORY(*address);
        return NDR_ERR_SUCCESS;
@@ -678,6 +703,11 @@ _PUBLIC_ void ndr_print_dlong(struct ndr_print *ndr, const char *name, int64_t v
        ndr->print(ndr, "%-25s: 0x%016llx (%lld)", name, (unsigned long long)v, (long long)v);
 }
 
+_PUBLIC_ void ndr_print_double(struct ndr_print *ndr, const char *name, double v)
+{
+       ndr->print(ndr, "%-25s: %f", name, v);
+}
+
 _PUBLIC_ void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t v)
 {
        ndr_print_dlong(ndr, name, v);
@@ -757,8 +787,7 @@ _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
        ndr->depth++;
        for (i=0;i<count;i++) {
                char *idx=NULL;
-               asprintf(&idx, "[%d]", i);
-               if (idx) {
+               if (asprintf(&idx, "[%d]", i) != -1) {
                        ndr_print_uint8(ndr, idx, data[i]);
                        free(idx);
                }