2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file saml/saml2/binding/SAML2Redirect.h
20 * SAML 2.0 HTTP Redirect compression functionality
24 #include "saml2/binding/SAML2Redirect.h"
25 #include "zlib/zlib.h"
27 #include <log4cpp/Category.hh>
28 #include <xmltooling/util/NDC.h>
30 using namespace log4cpp;
35 voidpf saml_zalloc(void* opaque, uInt items, uInt size)
37 return malloc(items*size);
40 void saml_zfree(void* opaque, voidpf addr)
47 unsigned int opensaml::saml2p::inflate(char* in, unsigned int in_len, ostream& out)
50 xmltooling::NDC ndc("inflate");
52 Category& log = Category::getInstance(SAML_LOGCAT".MessageDecoder.SAML2Redirect.zlib");
55 memset(&z, 0, sizeof(z_stream));
57 z.zalloc = saml_zalloc;
60 z.next_in = (Bytef*)in;
63 int dlen = in_len << 3; /* guess inflated size: orig_size * 8 */
64 Byte* buf = new Byte[dlen];
69 int ret = inflateInit2(&z, -15);
71 log.error("zlib inflateInit failed with error code (%d)", ret);
77 while (--iter) { /* Make sure we can never be caught in infinite loop */
78 ret = inflate(&z, Z_SYNC_FLUSH);
81 ret = z.next_out - buf;
84 out << *(z.next_out++);
87 case Z_OK: /* avail_out should be 0 now. Time to dump the buffer. */
88 ret = z.next_out - buf;
91 out << *(z.next_out++);
100 log.error("zlib inflate failed with error code (%d)", ret);
106 int out_len = z.total_out;