2 Unix SMB/Netbios implementation.
4 Samba memory buffer functions
5 Copyright (C) Andrew Tridgell 1992-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 extern int DEBUGLEVEL
;
28 /*******************************************************************
29 debug output for parsing info.
30 ********************************************************************/
31 void prs_debug(prs_struct
*ps
, int depth
, const char *desc
,
36 ("%s%06x %s %s\n", tab_depth(depth
), ps
->offset
, fn_name
,
40 /*******************************************************************
41 debug a parse structure
42 ********************************************************************/
43 void prs_debug_out(const prs_struct
*ps
, char *msg
, int level
)
46 DEBUG(level
, ("%s ps: io %s align %d offset %d err %d data %p\n",
47 msg
, BOOLSTR(ps
->io
), ps
->align
, ps
->offset
, ps
->error
,
52 dump_data(level
, ps
->data
, prs_buf_len(ps
));
56 /*******************************************************************
57 initialise a parse structure
58 ********************************************************************/
59 BOOL
prs_init(prs_struct
*ps
, uint32 size
, uint8 align
, BOOL io
)
61 ps
->struct_start
= 0xfefefefe;
66 ps
->bigendian
= False
;
76 ps
->struct_end
= 0xdcdcdcdc;
80 prs_realloc_data(ps
, size
);
88 /*******************************************************************
89 set the packed data representation type in a parse structure
90 ********************************************************************/
91 void prs_set_packtype(prs_struct
*ps
, const uint8
*pack_type
)
94 ps
->bigendian
= pack_type
[0] == 0x0;
96 ("prs_set_packtype: bigendian: %s\n", BOOLSTR(ps
->bigendian
)));
99 /*******************************************************************
100 create a parse structure
101 ********************************************************************/
102 void prs_create(prs_struct
*ps
, char *data
, uint32 size
, uint8 align
, BOOL io
)
104 DEBUG(200, ("prs_create: data:%p size:%d align:%d io:%s\n",
105 data
, size
, align
, BOOLSTR(io
)));
107 prs_init(ps
, 0, align
, io
);
109 ps
->data_size
= size
;
115 /*******************************************************************
116 copy a parse structure
117 ********************************************************************/
118 BOOL
prs_copy(prs_struct
*ps
, const prs_struct
*from
)
120 int len
= prs_buf_len(from
);
123 prs_init(ps
, len
, from
->align
, from
->io
);
124 ps
->bigendian
= from
->bigendian
;
127 if (ps
->data
== NULL
)
131 if (!prs_buf_copy(ps
->data
, from
, 0, len
))
137 prs_link(NULL
, ps
, NULL
);
141 /*******************************************************************
142 allocate a memory buffer. assume it's empty
143 ********************************************************************/
144 BOOL
prs_alloc_data(prs_struct
*buf
, int size
)
148 buf
->data_size
= size
;
149 buf
->data
= (char *)malloc(buf
->data_size
);
151 if (buf
->data
== NULL
&& size
!= 0)
153 DEBUG(3, ("prs_alloc: could not malloc size %d\n",
160 memset(buf
->data
, 0, buf
->data_size
);
161 buf
->end
= buf
->start
+ size
;
167 /*******************************************************************
168 search for a memory buffer that falls within the specified offset
169 ********************************************************************/
170 static const prs_struct
*prs_find(const prs_struct
*buf
, uint32 offset
)
179 DEBUG(200, ("prs_find: data[%d..%d] offset: %d\n",
180 f
->start
, f
->end
, offset
));
182 while (f
!= NULL
&& offset
>= f
->end
)
184 DEBUG(200, ("prs_find: next[%d..%d]\n", f
->start
, f
->end
));
192 ("prs_find: found data[%d..%d]\n", f
->start
, f
->end
));
198 /*******************************************************************
199 allocates a memory buffer structure
200 ********************************************************************/
201 BOOL
prs_buf_copy(char *copy_into
, const prs_struct
*buf
,
202 uint32 offset
, uint32 len
)
204 uint32 end
= offset
+ len
;
206 uint32 start_offset
= offset
;
207 const prs_struct
*bcp
= buf
;
209 if (buf
== NULL
|| copy_into
== NULL
)
215 DEBUG(200, ("prs_struct_copy: data[%d..%d] offset %d len %d\n",
216 buf
->start
, prs_buf_len(buf
), offset
, len
));
219 prs_debug_out(bcp
, "prs_struct_copy", 200);
221 while (offset
< end
&& ((q
= prs_data(bcp
, offset
)) != NULL
))
224 bcp
= prs_find(bcp
, offset
);
225 copy_len
= bcp
->end
- offset
;
227 DEBUG(200, ("\tdata[%d..%d] - offset %d len %d\n",
228 bcp
->start
, bcp
->end
, offset
, copy_len
));
230 memcpy(copy_into
, q
, copy_len
);
233 copy_into
+= copy_len
;
239 ("prs_struct_copy: copied %d bytes\n",
240 offset
- start_offset
));
244 DEBUG(200, ("prs_struct_copy: failed\n"));
250 /*******************************************************************
251 frees up a memory buffer.
252 ********************************************************************/
253 void prs_struct_free(prs_struct
**buf
)
261 prs_free_data(*buf
); /* delete memory data */
262 free(*buf
); /* delete item */
266 /*******************************************************************
267 frees a memory buffer chain. assumes that all items are malloced.
268 ********************************************************************/
269 static void prs_free_chain(prs_struct
**buf
)
277 if ((*buf
)->next
!= NULL
)
279 prs_free_chain(&((*buf
)->next
)); /* delete all other items in chain */
281 prs_struct_free(buf
);
284 /*******************************************************************
285 frees a memory buffer.
286 ********************************************************************/
287 void prs_free_data(prs_struct
*buf
)
292 if (buf
->data
!= NULL
)
295 safe_free(buf
->data
); /* delete data in this structure */
301 /*******************************************************************
302 reallocate a memory buffer
303 ********************************************************************/
304 BOOL
prs_realloc_data(prs_struct
*buf
, size_t new_size
)
310 prs_debug_out(buf
, "prs_realloc_data - before", 200);
318 new_data
= (char *)Realloc(buf
->data
, new_size
);
320 if (new_data
!= NULL
)
322 if (new_size
> buf
->data_size
)
324 memset(&new_data
[buf
->data_size
], 0,
325 new_size
- buf
->data_size
);
327 buf
->data
= new_data
;
328 buf
->data_size
= new_size
;
330 else if (buf
->data_size
>= new_size
)
333 ("prs_realloc_data: warning - could not realloc to %d\n",
339 ("prs_realloc_data: error - could not realloc to %d\n",
347 buf
->end
= buf
->start
+ new_size
;
349 prs_debug_out(buf
, "prs_realloc_data - after", 200);
353 /*******************************************************************
354 reallocate a memory buffer, retrospectively :-)
355 ********************************************************************/
356 BOOL
prs_grow_data(prs_struct
*buf
, BOOL io
, int new_size
, BOOL force_grow
)
365 if (new_size
> buf
->data_size
)
367 if (!io
|| force_grow
)
369 /* writing or forge realloc */
370 return prs_realloc_data(buf
, new_size
);
375 * reading, there is just not that much
378 DEBUG(1, ("prs_grow_data: %d > %d\n",
379 new_size
, buf
->data_size
));
387 /*******************************************************************
388 add up the lengths of all sections.
389 ********************************************************************/
390 uint32
prs_buf_len(const prs_struct
*buf
)
396 len
+= buf
->end
- buf
->start
;
402 /*******************************************************************
403 return the memory location specified by may return NULL.
404 ********************************************************************/
405 char *prs_data(const prs_struct
*buf
, uint32 offset
)
408 buf
= prs_find(buf
, offset
);
411 return &(buf
->data
[offset
- buf
->start
]);
417 /*******************************************************************
418 link one parsing structure to another
419 ********************************************************************/
420 void prs_link(prs_struct
*prev
, prs_struct
*ps
, prs_struct
*next
)
431 ps
->start
= prev
!= NULL
? prev
->end
: 0;
432 ps
->end
= ps
->start
+ ps
->offset
;
436 DEBUG(150, ("prs_link: start %d end %d\n", ps
->start
, ps
->end
));
439 /*******************************************************************
440 align a pointer to a multiple of align_offset bytes. looks like it
441 will work for offsets of 0, 2 and 4...
442 ********************************************************************/
443 BOOL
prs_align(prs_struct
*ps
)
449 mod
= ps
->offset
& (ps
->align
- 1);
450 if (ps
->align
!= 0 && mod
!= 0)
452 ps
->offset
+= ps
->align
- mod
;
453 if (!prs_grow(ps
, ps
->offset
))
461 /*******************************************************************
462 attempt, if appropriate, to grow a data buffer.
464 depends on the data stream mode (io)
465 ********************************************************************/
466 BOOL
prs_grow(prs_struct
*ps
, uint32 new_size
)
471 return prs_grow_data(ps
, ps
->io
, new_size
, False
);
474 /*******************************************************************
475 lengthens a buffer by len bytes and copies data into it.
476 ********************************************************************/
477 BOOL
prs_append_data(prs_struct
*ps
, const char *data
, int len
)
479 int prev_size
= ps
->data_size
;
480 int new_size
= prev_size
+ len
;
483 DEBUG(200, ("prs_append_data: prev_size: %d new_size: %d\n",
484 prev_size
, new_size
));
487 prs_realloc_data(ps
, new_size
);
488 to
= prs_data(ps
, prev_size
);
490 if (to
== NULL
|| ps
->data_size
!= new_size
)
494 memcpy(to
, data
, len
);
499 BOOL
prs_add_data(prs_struct
*ps
, const char *data
, int len
)
507 if (ps
->data
== NULL
)
509 DEBUG(10, ("prs_add_data: new_size: %d\n", len
));
510 prs_init(ps
, len
, 4, True
);
513 if (ps
->data
== NULL
)
520 prev_size
= ps
->data_size
;
521 new_size
= prev_size
+ len
;
522 DEBUG(10, ("prs_add_data: prev_size: %d new_size: %d\n",
523 prev_size
, new_size
));
524 if (!prs_realloc_data(ps
, new_size
))
530 DEBUG(10, ("ps->start: %d\n", ps
->start
));
533 to
= prs_data(ps
, prev_size
);
536 DEBUG(10, ("prs_add_data: data could not be found\n"));
539 if (ps
->data_size
!= new_size
)
541 DEBUG(10, ("prs_add_data: ERROR: data used %d new_size %d\n",
542 ps
->data_size
, new_size
));
545 memcpy(to
, data
, len
);
549 /*******************************************************************
550 Change the struct type.
551 ********************************************************************/
553 void prs_switch_type(prs_struct
*ps
, BOOL io
)
555 if ((ps
->io
^ io
) == True
)
559 /*******************************************************************
560 Force a prs_struct to be dynamic even when its size is 0.
561 ********************************************************************/
563 void prs_force_dynamic(prs_struct
*ps
)
567 /*******************************************************************
568 Fetch the current offset (external interface).
569 ********************************************************************/
570 uint32
prs_data_size(prs_struct
*ps
)
572 return ps
->data_size
;
575 /*******************************************************************
576 Fetch the current offset (external interface).
577 ********************************************************************/
578 uint32
prs_offset(prs_struct
*ps
)
583 /*******************************************************************
584 Set the current offset (external interface).
585 ********************************************************************/
586 BOOL
prs_set_offset(prs_struct
*ps
, uint32 offset
)
588 if (offset
<= ps
->offset
)
594 if (!prs_grow(ps
, offset
))
603 /*******************************************************************
604 Delete the memory in a parse structure - if we own it.
605 ********************************************************************/
607 void prs_mem_free(prs_struct
*ps
)
615 /*******************************************************************
616 Append some data from one parse_struct into another.
617 ********************************************************************/
619 BOOL
prs_append_some_prs_data(prs_struct
*dst
, prs_struct
*src
, int32 start
,
625 * ok, it looks like shit. It smells like shit.
626 * summary: it's shit.
628 * I'm not proud of that code. I mae that ugly hack to
629 * a) not change luke's prs memory managment
630 * b) not change the spoolss parsing code
632 * mail me, call me, hit me before changing that piece of code.
636 prs_add_data(dst
, src
->data
, len
);
640 prs_add_data(dst
, src
->data
+ start
, len
);
643 dst
->offset
= dst
->data_size
;
647 /*******************************************************************
649 ********************************************************************/
650 BOOL
_prs_uint8(char *name
, prs_struct
*ps
, int depth
, uint8
*data8
)
656 if (!prs_grow(ps
, ps
->offset
+ 1))
660 q
= prs_data(ps
, ps
->offset
);
664 prs_debug_out(ps
, "_prs_uint8 error", 5);
668 DBG_RW_CVAL(name
, depth
, ps
->offset
, ps
->io
, q
, *data8
);
674 /*******************************************************************
676 ********************************************************************/
677 BOOL
_prs_uint16(char *name
, prs_struct
*ps
, int depth
, uint16
*data16
)
683 if (!prs_grow(ps
, ps
->offset
+ 2))
687 q
= prs_data(ps
, ps
->offset
);
691 prs_debug_out(ps
, "_prs_uint16 error", 5);
695 DBG_RW_SVAL(name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
, q
,
702 /*******************************************************************
704 ********************************************************************/
705 BOOL
_prs_hash1(prs_struct
*ps
, uint32 offset
, uint8 sess_key
[16])
711 q
= prs_data(ps
, ps
->offset
);
715 prs_debug_out(ps
, "_prs_hash1 error", 5);
719 #ifdef DEBUG_PASSWORD
720 DEBUG(100, ("prs_hash1\n"));
721 dump_data(100, sess_key
, 16);
722 dump_data(100, q
, 68);
724 SamOEMhash((uchar
*) q
, sess_key
, 2);
725 #ifdef DEBUG_PASSWORD
726 dump_data(100, q
, 68);
732 /*******************************************************************
734 ********************************************************************/
735 BOOL
_prs_uint32(char *name
, prs_struct
*ps
, int depth
, uint32
*data32
)
741 if (!prs_grow(ps
, ps
->offset
+ 4))
745 q
= prs_data(ps
, ps
->offset
);
749 slprintf(str
, sizeof(str
) - 1, "_prs_uint32 error (%s)",
752 prs_debug_out(ps
, str
, 5);
756 DBG_RW_IVAL(name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
, q
,
764 /******************************************************************
765 stream an array of uint8s. length is number of uint8s
766 ********************************************************************/
767 BOOL
_prs_uint8s(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
768 uint8
*data8s
, int len
)
782 end_offset
= ps
->offset
+ len
* sizeof(uint8
);
783 if (!prs_grow(ps
, end_offset
))
787 q
= prs_data(ps
, ps
->offset
);
788 e
= prs_data(ps
, end_offset
- 1);
790 if (q
== NULL
|| e
== NULL
)
793 prs_debug_out(ps
, "_prs_uint8s error", 5);
797 DBG_RW_PCVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, q
, data8s
,
799 ps
->offset
= end_offset
;
804 /******************************************************************
805 stream an array of uint16s. length is number of uint16s
806 ********************************************************************/
807 BOOL
_prs_uint16s(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
808 uint16
*data16s
, int len
)
822 end_offset
= ps
->offset
+ len
* sizeof(uint16
);
823 if (!prs_grow(ps
, end_offset
))
827 q
= prs_data(ps
, ps
->offset
);
828 e
= prs_data(ps
, end_offset
- 1);
830 if (q
== NULL
|| e
== NULL
)
833 prs_debug_out(ps
, "_prs_uint16s error", 5);
837 DBG_RW_PSVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
,
839 ps
->offset
= end_offset
;
844 /******************************************************************
845 stream an array of uint32s. length is number of uint32s
846 ********************************************************************/
847 BOOL
_prs_uint32s(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
848 uint32
*data32s
, int len
)
862 end_offset
= ps
->offset
+ len
* sizeof(uint32
);
863 if (!prs_grow(ps
, end_offset
))
867 q
= prs_data(ps
, ps
->offset
);
868 e
= prs_data(ps
, end_offset
- 1);
870 if (q
== NULL
|| e
== NULL
)
873 prs_debug_out(ps
, "_prs_uint32s error", 5);
877 DBG_RW_PIVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
,
879 ps
->offset
= end_offset
;
884 /******************************************************************
885 stream a "not" unicode string, length/buffer specified separately,
887 ********************************************************************/
888 BOOL
_prs_buffer2(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
898 if (str
->buf_len
== 0)
903 end_offset
= ps
->offset
+ str
->buf_len
* sizeof(uint8
);
904 if (!prs_grow(ps
, end_offset
))
908 q
= prs_data(ps
, ps
->offset
);
909 e
= prs_data(ps
, end_offset
- 1);
911 if (q
== NULL
|| e
== NULL
)
914 prs_debug_out(ps
, "_prs_buffer2 error", 5);
918 DBG_RW_PCVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, q
,
919 str
->buffer
, str
->buf_len
);
920 ps
->offset
= end_offset
;
925 /******************************************************************
926 stream a string, length/buffer specified separately,
928 ********************************************************************/
929 BOOL
_prs_string2(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
939 if (str
->str_str_len
== 0)
944 end_offset
= ps
->offset
+ str
->str_str_len
* sizeof(uint8
);
945 if (!prs_grow(ps
, end_offset
))
949 q
= prs_data(ps
, ps
->offset
);
950 e
= prs_data(ps
, end_offset
- 1);
952 if (q
== NULL
|| e
== NULL
)
955 prs_debug_out(ps
, "_prs_string2 error", 5);
959 DBG_RW_PCVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, q
,
960 str
->buffer
, str
->str_str_len
);
961 ps
->offset
= end_offset
;
966 /******************************************************************
967 stream a unicode string, length/buffer specified separately,
969 ********************************************************************/
970 BOOL
_prs_unistr2(BOOL charmode
, char *name
, prs_struct
*ps
, int depth
,
980 if (str
->uni_str_len
== 0)
985 end_offset
= ps
->offset
+ str
->uni_str_len
* sizeof(uint16
);
986 if (!prs_grow(ps
, end_offset
))
990 q
= prs_data(ps
, ps
->offset
);
991 e
= prs_data(ps
, end_offset
- 1);
993 if (q
== NULL
|| e
== NULL
)
996 prs_debug_out(ps
, "_prs_unistr2 error", 5);
1000 DBG_RW_PSVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
,
1001 q
, str
->buffer
, str
->uni_str_len
);
1002 ps
->offset
= end_offset
;
1007 /******************************************************************
1008 stream a unicode string, length/buffer specified separately,
1010 ********************************************************************/
1011 BOOL
_prs_unistr3(BOOL charmode
, char *name
, UNISTR3
* str
, prs_struct
*ps
,
1021 if (str
->uni_str_len
== 0)
1026 end_offset
= ps
->offset
+ str
->uni_str_len
* sizeof(uint16
);
1027 if (!prs_grow(ps
, end_offset
))
1031 q
= prs_data(ps
, ps
->offset
);
1032 e
= prs_data(ps
, end_offset
- 1);
1034 if (q
== NULL
|| e
== NULL
)
1037 prs_debug_out(ps
, "_prs_unistr3 error", 5);
1041 DBG_RW_PSVAL(charmode
, name
, depth
, ps
->offset
, ps
->io
, ps
->bigendian
,
1042 q
, str
->str
.buffer
, str
->uni_str_len
);
1043 ps
->offset
= end_offset
;
1048 /*******************************************************************
1049 stream a unicode null-terminated string
1050 ********************************************************************/
1051 BOOL
_prs_unistr(char *name
, prs_struct
*ps
, int depth
, UNISTR
* str
)
1058 start
= (uint8
*)prs_data(ps
, ps
->offset
);
1064 if (!prs_grow(ps
, ps
->offset
+ (i
+ 1) * 2))
1068 q
= prs_data(ps
, ps
->offset
+ i
* 2);
1072 prs_debug_out(ps
, "_prs_unistr error", 5);
1075 RW_SVAL(ps
->io
, ps
->bigendian
, q
, str
->buffer
[i
], 0);
1077 while ((((size_t) i
) < sizeof(str
->buffer
) / sizeof(str
->buffer
[0]))
1078 && (str
->buffer
[i
] != 0));
1081 ps
->offset
+= (i
+ 1) * 2;
1083 dump_data(5 + depth
, (char *)start
, i
* 2);
1088 /*******************************************************************
1089 stream a null-terminated string. len is strlen, and therefore does
1090 not include the null-termination character.
1092 len == 0 indicates variable length string
1093 (up to max size of pstring - 1024 chars).
1095 ********************************************************************/
1096 BOOL
_prs_string(char *name
, prs_struct
*ps
, int depth
, char *str
,
1097 uint16 len
, uint16 max_buf_size
)
1099 int i
= -1; /* start off at zero after 1st i++ */
1106 len_limited
= len
== 0 || !ps
->io
;
1108 DEBUG(200, ("_prs_string: string %s len %d max %d\n",
1109 str
, len
, max_buf_size
));
1112 ("%s%04x %s: ", tab_depth(depth
), ps
->offset
,
1113 name
!= NULL
? name
: ""));
1119 if (!prs_grow(ps
, ps
->offset
+ i
+ 1))
1123 q
= prs_data(ps
, ps
->offset
+ i
);
1127 DEBUG(5+depth
, ("%s\n", str
));
1128 prs_debug_out(ps
, "_prs_string error", 5);
1132 if (i
< len
|| len_limited
)
1134 RW_CVAL(ps
->io
, q
, str
[i
], 0);
1139 RW_CVAL(ps
->io
, q
, dummy
, 0);
1143 while (i
< max_buf_size
&& (len_limited
? str
[i
] != 0 : i
< len
));
1145 ps
->offset
+= i
+ 1;
1147 DEBUG(5+depth
, ("%s\n", str
));
1152 /*******************************************************************
1153 prs_uint16 wrapper. call this and it sets up a pointer to where the
1154 uint16 should be stored, or gets the size if reading
1155 ********************************************************************/
1156 BOOL
_prs_uint16_pre(char *name
, prs_struct
*ps
, int depth
, uint16
*data16
,
1162 (*offset
) = ps
->offset
;
1166 return _prs_uint16(name
, ps
, depth
, data16
);
1170 ps
->offset
+= sizeof(uint16
);
1175 /*******************************************************************
1176 prs_uint16 wrapper. call this and it retrospectively stores the size.
1177 does nothing on reading, as that is already handled by ...._pre()
1178 ********************************************************************/
1179 BOOL
_prs_uint16_post(char *name
, prs_struct
*ps
, int depth
, uint16
*data16
,
1180 uint32 ptr_uint16
, uint32 start_offset
)
1187 /* storing: go back and do a retrospective job. i hate this */
1188 uint16 data_size
= ps
->offset
- start_offset
;
1189 uint32 old_offset
= ps
->offset
;
1191 ps
->offset
= ptr_uint16
;
1192 prs_uint16(name
, ps
, depth
, &data_size
);
1193 ps
->offset
= old_offset
;
1197 ps
->offset
= start_offset
+ (*data16
);
1202 /*******************************************************************
1203 prs_uint32 wrapper. call this and it sets up a pointer to where the
1204 uint32 should be stored, or gets the size if reading
1205 ********************************************************************/
1206 BOOL
_prs_uint32_pre(char *name
, prs_struct
*ps
, int depth
, uint32
*data32
,
1212 (*offset
) = ps
->offset
;
1216 return _prs_uint32(name
, ps
, depth
, data32
);
1220 ps
->offset
+= sizeof(uint32
);
1225 /*******************************************************************
1226 prs_uint32 wrapper. call this and it retrospectively stores the size.
1227 does nothing on reading, as that is already handled by ...._pre()
1228 ********************************************************************/
1229 BOOL
_prs_uint32_post(char *name
, prs_struct
*ps
, int depth
, uint32
*data32
,
1230 uint32 ptr_uint32
, uint32 data_size
)
1237 /* storing: go back and do a retrospective job. i hate this */
1238 uint32 old_offset
= ps
->offset
;
1239 ps
->offset
= ptr_uint32
;
1240 prs_uint32(name
, ps
, depth
, &data_size
);
1241 ps
->offset
= old_offset
;
1245 ps
->offset
= data_size
+ (*data32
);
1250 /*******************************************************************
1251 prs_tdb_store. stores prs_struct data by prs_struct key
1252 ********************************************************************/
1253 int prs_tdb_delete(TDB_CONTEXT
* tdb
, prs_struct
*pk
)
1257 key
.dptr
= (char *)prs_data(pk
, 0);
1258 key
.dsize
= prs_buf_len(pk
);
1260 return tdb_delete(tdb
, key
);
1263 /*******************************************************************
1264 prs_tdb_store. stores prs_struct data by prs_struct key
1265 ********************************************************************/
1266 int prs_tdb_store(TDB_CONTEXT
* tdb
, int flgs
, prs_struct
*pk
, prs_struct
*pd
)
1271 key
.dptr
= (char *)prs_data(pk
, 0);
1272 key
.dsize
= prs_buf_len(pk
);
1274 data
.dptr
= prs_data(pd
, 0);
1275 data
.dsize
= prs_buf_len(pd
);
1277 return tdb_store(tdb
, key
, data
, flgs
);
1280 /*******************************************************************
1281 prs_tdb_fetch. fetches prs_struct data by prs_struct key
1282 ********************************************************************/
1283 void prs_tdb_fetch(TDB_CONTEXT
* tdb
, prs_struct
*pk
, prs_struct
*pd
)
1288 key
.dptr
= (char *)prs_data(pk
, 0);
1289 key
.dsize
= prs_buf_len(pk
);
1291 data
= tdb_fetch(tdb
, key
);
1293 prs_create(pd
, data
.dptr
, data
.dsize
, 4, True
);