summaryrefslogtreecommitdiff
path: root/source3/rpc_parse/parse_prs.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-07-07 06:20:46 +0000
committerGerald Carter <jerry@samba.org>2000-07-07 06:20:46 +0000
commitd2b40a7de259377d937492acedd39988ddd108a4 (patch)
treef0849ba6679575e80500b43b8989b3dddf16e2a4 /source3/rpc_parse/parse_prs.c
parent9de93aa8188293671a92e84b2b9dc104cc7eb64c (diff)
downloadsamba-d2b40a7de259377d937492acedd39988ddd108a4.tar.gz
samba-d2b40a7de259377d937492acedd39988ddd108a4.tar.bz2
samba-d2b40a7de259377d937492acedd39988ddd108a4.zip
More rpcclient merge issues:
* fixes some readline bugs from the merge * first attempt at commands (spoolenum almost works) * no changes to existing functions in HEAD; only additions of new functions. I'll weed out what I can as I go. --jerry (This used to be commit 61d2aad5dc2b212b11c981f1eca47efa627e9fc8)
Diffstat (limited to 'source3/rpc_parse/parse_prs.c')
-rw-r--r--source3/rpc_parse/parse_prs.c114
1 files changed, 113 insertions, 1 deletions
diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c
index 94a6100aa1..3b17f51c95 100644
--- a/source3/rpc_parse/parse_prs.c
+++ b/source3/rpc_parse/parse_prs.c
@@ -27,6 +27,35 @@ extern int DEBUGLEVEL;
/*******************************************************************
+ search for a memory buffer that falls within the specified offset
+ ********************************************************************/
+static const prs_struct *prs_find(const prs_struct *buf, uint32 offset)
+{
+ const prs_struct *f = NULL;
+
+#if 0 /* comment out by JERRY */
+ if (buf == NULL)
+ return False;
+
+ f = buf;
+
+ while (f != NULL && offset >= f->end)
+ {
+ DEBUG(200, ("prs_find: next[%d..%d]\n", f->start, f->end));
+
+ f = f->next;
+ }
+
+ if (f != NULL)
+ {
+ DEBUG(200, ("prs_find: found [%d..%d]\n", f->start, f->end));
+ }
+
+#endif
+ return f;
+}
+
+/*******************************************************************
dump a prs to a file
********************************************************************/
void prs_dump(char *name, int v, prs_struct *ps)
@@ -63,10 +92,10 @@ void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name)
DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->data_offset, fn_name, desc));
}
+
/*******************************************************************
Initialise a parse structure - malloc the data if requested.
********************************************************************/
-
BOOL prs_init(prs_struct *ps, uint32 size, uint8 align, BOOL io)
{
ZERO_STRUCTP(ps);
@@ -805,6 +834,89 @@ BOOL prs_uint32_post(char *name, prs_struct *ps, int depth, uint32 *data32,
return True;
}
+/*******************************************************************
+ frees a memory buffer.
+ ********************************************************************/
+void prs_free_data(prs_struct *buf)
+{
+ if (buf == NULL)
+ return;
+
+ if (buf->data_p != NULL)
+ {
+ free(buf->data_p);
+ buf->data_p = NULL;
+ }
+ buf->buffer_size = 0;
+}
+
+/*******************************************************************
+ reallocate a memory buffer
+********************************************************************/
+BOOL prs_realloc_data(prs_struct *buf, size_t new_size)
+{
+ char *new_data;
+
+ /* prs_sma_init(); JERRY */
+
+ prs_debug(buf, 200, "prs_realloc_data - before", "prs_realloc_data");
+
+ SMB_ASSERT(((ssize_t) new_size) >= 0);
+
+ if (new_size == 0)
+ {
+ prs_free_data(buf);
+ return True;
+ }
+
+ /* new_data = sma_realloc(prs_sma_region, buf->data_p, new_size); */
+ new_data = realloc(buf->data_p, new_size);
+
+ if (new_data != NULL)
+ {
+ if (new_size > buf->buffer_size)
+ {
+ memset(&new_data[buf->buffer_size], 0,
+ new_size - buf->buffer_size);
+ }
+ buf->data_p = new_data;
+ buf->buffer_size = new_size;
+ }
+ else if (buf->buffer_size >= new_size)
+ {
+ DEBUG(3, ("prs_realloc_data: warning - "
+ "could not realloc to %d\n", new_size));
+ }
+ else
+ {
+ DEBUG(3, ("prs_realloc_data: error - "
+ "could not realloc to %d\n", new_size));
+
+ prs_free_data(buf);
+ return False;
+ }
+
+ prs_debug(buf, 200, "prs_realloc_data - after", "prs_realloc_data");
+ return True;
+}
+
+/*******************************************************************
+ return the memory location specified by may return NULL.
+ ********************************************************************/
+char *prs_data(const prs_struct *buf, uint32 offset)
+{
+ buf = prs_find(buf, offset);
+ if (buf != NULL)
+ {
+ /* return &(buf->data[offset - buf->start]); */
+ return &(buf->data_p[offset]);
+ }
+ return NULL;
+}
+
+
+
+
/* useful function to store a structure in rpc wire format */
int tdb_prs_store(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps)
{