mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
librpc: Always call ndr_push_compression_state_init() for compression
This allows the push routine to cache the chosen compression algorithm in the struct ndr_compression_state in ndr->cstate and so, in claims, avoid calling ndr_size_CLAIMS_SET_NDR() three times per compression (more in the overall push). As claims is now the primary use of the libndr compression code, this is a reasonable tradeoff compared to the other callers who have more static algorithm selections. By removing the struct ndr_compression_state **state argument from ndr_push_compression_state_init() we make clear that the ndr->cstate belongs to this NDR context, and this context alone. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
This commit is contained in:
parent
ff2de50aa4
commit
963688b3a5
@ -132,7 +132,7 @@ static enum ndr_err_code ndr_push_folder_cfdata(struct ndr_push *ndr,
|
||||
|
||||
if (cab_ctype == CF_COMPRESS_MSZIP) {
|
||||
ndr_ctype = NDR_COMPRESSION_MSZIP_CAB;
|
||||
NDR_CHECK(ndr_push_compression_state_init(ndr, ndr_ctype, &ndr->cstate));
|
||||
NDR_CHECK(ndr_push_compression_state_init(ndr, ndr_ctype));
|
||||
}
|
||||
|
||||
for (i = 0; i < num_cfdata; i++, r++) {
|
||||
@ -189,11 +189,18 @@ static enum ndr_err_code ndr_push_folder_cfdata(struct ndr_push *ndr,
|
||||
|
||||
/* compress via subcontext */
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &push_sub, 0, -1));
|
||||
|
||||
/*
|
||||
* This assignment replaces a call to
|
||||
* ndr_push_compression_state_init(push_sub, ndr_ctype))
|
||||
* here. This is instead done outside the loop.
|
||||
*/
|
||||
push_sub->cstate = ndr->cstate;
|
||||
NDR_CHECK(ndr_push_compression_start(push_sub, &push_compress, ndr_ctype));
|
||||
|
||||
NDR_CHECK(ndr_push_compression_start(push_sub, &push_compress));
|
||||
ndr_set_flags(&push_compress->flags, LIBNDR_FLAG_REMAINING);
|
||||
NDR_CHECK(ndr_push_DATA_BLOB(push_compress, NDR_SCALARS, r->ab));
|
||||
NDR_CHECK(ndr_push_compression_end(push_sub, push_compress, ndr_ctype));
|
||||
NDR_CHECK(ndr_push_compression_end(push_sub, push_compress));
|
||||
NDR_CHECK(ndr_push_subcontext_end(ndr, push_sub, 0, -1));
|
||||
compressed_length = push_sub->offset;
|
||||
|
||||
|
@ -898,10 +898,10 @@ 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 **_uncomndr,
|
||||
enum ndr_compression_alg compression_alg)
|
||||
struct ndr_push **_uncomndr)
|
||||
{
|
||||
struct ndr_push *uncomndr;
|
||||
enum ndr_compression_alg compression_alg = subndr->cstate->type;
|
||||
|
||||
switch (compression_alg) {
|
||||
case NDR_COMPRESSION_NONE:
|
||||
@ -928,13 +928,14 @@ 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 *uncomndr,
|
||||
enum ndr_compression_alg compression_alg)
|
||||
struct ndr_push *uncomndr)
|
||||
{
|
||||
struct ndr_pull *ndrpull;
|
||||
bool last = false;
|
||||
z_stream z;
|
||||
|
||||
enum ndr_compression_alg compression_alg = subndr->cstate->type;
|
||||
|
||||
ndrpull = talloc_zero(uncomndr, struct ndr_pull);
|
||||
NDR_ERR_HAVE_NO_MEMORY(ndrpull);
|
||||
ndrpull->flags = uncomndr->flags;
|
||||
@ -1034,12 +1035,17 @@ enum ndr_err_code ndr_pull_compression_state_init(struct ndr_pull *ndr,
|
||||
}
|
||||
|
||||
enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr,
|
||||
enum ndr_compression_alg compression_alg,
|
||||
struct ndr_compression_state **state)
|
||||
enum ndr_compression_alg compression_alg)
|
||||
{
|
||||
struct ndr_compression_state *s;
|
||||
int z_ret;
|
||||
|
||||
/*
|
||||
* Avoid confusion, NULL out ndr->cstate at the start of the
|
||||
* compression block
|
||||
*/
|
||||
ndr->cstate = NULL;
|
||||
|
||||
s = talloc_zero(ndr, struct ndr_compression_state);
|
||||
NDR_ERR_HAVE_NO_MEMORY(s);
|
||||
s->type = compression_alg;
|
||||
@ -1079,8 +1085,7 @@ enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr,
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
*state = s;
|
||||
ndr->cstate = s;
|
||||
|
||||
return NDR_ERR_SUCCESS;
|
||||
}
|
||||
|
@ -42,19 +42,16 @@ enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr,
|
||||
enum ndr_compression_alg compression_alg,
|
||||
ssize_t decompressed_len);
|
||||
enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr,
|
||||
struct ndr_push **_uncomndr,
|
||||
enum ndr_compression_alg compression_alg);
|
||||
struct ndr_push **_uncomndr);
|
||||
enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr,
|
||||
struct ndr_push *uncomndr,
|
||||
enum ndr_compression_alg compression_alg);
|
||||
struct ndr_push *uncomndr);
|
||||
|
||||
enum ndr_err_code ndr_pull_compression_state_init(struct ndr_pull *ndr,
|
||||
enum ndr_compression_alg compression_alg,
|
||||
struct ndr_compression_state **state);
|
||||
void ndr_pull_compression_state_free(struct ndr_compression_state *state);
|
||||
enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr,
|
||||
enum ndr_compression_alg compression_alg,
|
||||
struct ndr_compression_state **state);
|
||||
enum ndr_compression_alg compression_alg);
|
||||
|
||||
#undef _PRINTF_ATTRIBUTE
|
||||
#define _PRINTF_ATTRIBUTE(a1, a2)
|
||||
|
@ -216,10 +216,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr,
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
decompressed_length = _ndr_ts_compressed->offset;
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
compressed_length = _ndr_ts->offset;
|
||||
talloc_free(_ndr_ts);
|
||||
@ -237,9 +238,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr,
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
|
||||
}
|
||||
@ -259,10 +261,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr,
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
decompressed_length = _ndr_ts_compressed->offset;
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
compressed_length = _ndr_ts->offset;
|
||||
talloc_free(_ndr_ts);
|
||||
@ -280,9 +283,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr,
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
|
||||
}
|
||||
@ -302,10 +306,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr1(struct
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
decompressed_length = _ndr_ts_compressed->offset;
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
compressed_length = _ndr_ts->offset;
|
||||
talloc_free(_ndr_ts);
|
||||
@ -323,9 +328,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr1(struct
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
|
||||
}
|
||||
@ -345,10 +351,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr6(struct
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
decompressed_length = _ndr_ts_compressed->offset;
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
compressed_length = _ndr_ts->offset;
|
||||
talloc_free(_ndr_ts);
|
||||
@ -366,9 +373,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr6(struct
|
||||
NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
|
||||
{
|
||||
struct ndr_push *_ndr_ts_compressed;
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed));
|
||||
NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2));
|
||||
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
|
||||
}
|
||||
NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
|
||||
}
|
||||
|
@ -514,8 +514,8 @@ sub ParseCompressionPushStart($$$$$)
|
||||
$self->pidl("{");
|
||||
$self->indent;
|
||||
$self->pidl("struct ndr_push *$comndr;");
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_state_init($ndr, $alg, &$ndr->cstate));");
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_start($ndr, &$comndr, $alg));");
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_state_init($ndr, $alg));");
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_start($ndr, &$comndr));");
|
||||
|
||||
return $comndr;
|
||||
}
|
||||
@ -526,7 +526,7 @@ sub ParseCompressionPushEnd($$$$$)
|
||||
my $comndr = "$ndr\_compressed";
|
||||
my $alg = compression_alg($e, $l, $env);
|
||||
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_end($ndr, $comndr, $alg));");
|
||||
$self->pidl("NDR_CHECK(ndr_push_compression_end($ndr, $comndr));");
|
||||
$self->pidl("TALLOC_FREE($ndr->cstate);");
|
||||
$self->deindent;
|
||||
$self->pidl("}");
|
||||
|
Loading…
Reference in New Issue
Block a user