summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-08-07 16:26:45 +0000
committerStefan Metzmacher <metze@samba.org>2008-08-21 11:47:40 +0200
commit2d2e7f6c4881ecbf79dd9277e1d31a4ef91b751c (patch)
tree6d10865401b2975c4434dd1edd98a0943b617fea /source4/librpc
parent8acc7f7da7718c7750387c1043391618be46e15b (diff)
downloadsamba-2d2e7f6c4881ecbf79dd9277e1d31a4ef91b751c.tar.gz
samba-2d2e7f6c4881ecbf79dd9277e1d31a4ef91b751c.tar.bz2
samba-2d2e7f6c4881ecbf79dd9277e1d31a4ef91b751c.zip
ndr_compression: add common parts of ndr compression
metze (This used to be commit 9fe466f84afcbd64c9bbfe0f9ea6c1933acb07fe)
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/ndr/ndr_compression.c67
1 files changed, 52 insertions, 15 deletions
diff --git a/source4/librpc/ndr/ndr_compression.c b/source4/librpc/ndr/ndr_compression.c
index f6de0a1319..3b38c6b913 100644
--- a/source4/librpc/ndr/ndr_compression.c
+++ b/source4/librpc/ndr/ndr_compression.c
@@ -145,10 +145,12 @@ static enum ndr_err_code ndr_pull_compression_mszip_chunk(struct ndr_pull *ndrpu
return NDR_ERR_SUCCESS;
}
-static enum ndr_err_code ndr_push_compression_mszip(struct ndr_push *subndr,
- struct ndr_push *comndr)
+static enum ndr_err_code ndr_push_compression_mszip_chunk(struct ndr_push *ndrpush,
+ struct ndr_pull *ndrpull,
+ z_stream *z,
+ bool *last)
{
- return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "Sorry MSZIP compression is not supported yet (PUSH)");
+ return ndr_push_error(ndrpush, NDR_ERR_COMPRESSION, "MSZIP compression is not supported yet (PUSH)");
}
static enum ndr_err_code ndr_pull_compression_xpress_chunk(struct ndr_pull *ndrpull,
@@ -194,10 +196,11 @@ static enum ndr_err_code ndr_pull_compression_xpress_chunk(struct ndr_pull *ndrp
return NDR_ERR_SUCCESS;
}
-static enum ndr_err_code ndr_push_compression_xpress(struct ndr_push *subndr,
- struct ndr_push *comndr)
+static enum ndr_err_code ndr_push_compression_xpress_chunk(struct ndr_push *ndrpush,
+ struct ndr_pull *ndrpull,
+ bool *last)
{
- return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "XPRESS compression is not supported yet (PUSH)");
+ return ndr_push_error(ndrpush, NDR_ERR_COMPRESSION, "XPRESS compression is not supported yet (PUSH)");
}
/*
@@ -273,17 +276,27 @@ enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr,
push a compressed subcontext
*/
enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr,
- struct ndr_push **_comndr,
+ struct ndr_push **_uncomndr,
enum ndr_compression_alg compression_alg,
ssize_t decompressed_len)
{
- struct ndr_push *comndr;
+ struct ndr_push *uncomndr;
- comndr = ndr_push_init_ctx(subndr, subndr->iconv_convenience);
- NDR_ERR_HAVE_NO_MEMORY(comndr);
- comndr->flags = subndr->flags;
+ switch (compression_alg) {
+ case NDR_COMPRESSION_MSZIP:
+ case NDR_COMPRESSION_XPRESS:
+ break;
+ default:
+ return ndr_push_error(subndr, NDR_ERR_COMPRESSION,
+ "Bad compression algorithm %d (PUSH)",
+ compression_alg);
+ }
- *_comndr = comndr;
+ uncomndr = ndr_push_init_ctx(subndr, subndr->iconv_convenience);
+ NDR_ERR_HAVE_NO_MEMORY(uncomndr);
+ uncomndr->flags = subndr->flags;
+
+ *_uncomndr = uncomndr;
return NDR_ERR_SUCCESS;
}
@@ -291,18 +304,42 @@ enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr,
push a compressed subcontext
*/
enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr,
- struct ndr_push *comndr,
+ struct ndr_push *uncomndr,
enum ndr_compression_alg compression_alg,
ssize_t decompressed_len)
{
+ struct ndr_pull *ndrpull;
+ bool last = false;
+ z_stream z;
+
+ ndrpull = talloc_zero(uncomndr, struct ndr_pull);
+ NDR_ERR_HAVE_NO_MEMORY(ndrpull);
+ ndrpull->flags = uncomndr->flags;
+ ndrpull->data = uncomndr->data;
+ ndrpull->data_size = uncomndr->offset;
+ ndrpull->offset = 0;
+
+ ndrpull->iconv_convenience = talloc_reference(ndrpull, subndr->iconv_convenience);
+
switch (compression_alg) {
case NDR_COMPRESSION_MSZIP:
- return ndr_push_compression_mszip(subndr, comndr);
+ ZERO_STRUCT(z);
+ while (!last) {
+ NDR_CHECK(ndr_push_compression_mszip_chunk(subndr, ndrpull, &z, &last));
+ }
+ break;
+
case NDR_COMPRESSION_XPRESS:
- return ndr_push_compression_xpress(subndr, comndr);
+ while (!last) {
+ NDR_CHECK(ndr_push_compression_xpress_chunk(subndr, ndrpull, &last));
+ }
+ break;
+
default:
return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "Bad compression algorithm %d (PUSH)",
compression_alg);
}
+
+ talloc_free(uncomndr);
return NDR_ERR_SUCCESS;
}