Exemplo n.º 1
0
int vmbuf_inflate2(struct vmbuf *inbuf, struct vmbuf *outbuf) {
    z_stream strm;
    _init_alloc(&strm);
    if (Z_OK != inflateInit2(&strm, 15+16))
        return -1;
    for (;;)
    {
        strm.next_in = (uint8_t *)vmbuf_rloc(inbuf);
        strm.avail_in = vmbuf_ravail(inbuf);
        if (0 == strm.avail_in)
            break;
        vmbuf_resize_if_less(outbuf, strm.avail_in << 1);
        strm.next_out = (uint8_t *)vmbuf_wloc(outbuf);
        strm.avail_out = vmbuf_wavail(outbuf);
        int res = inflate(&strm, Z_NO_FLUSH);
        vmbuf_wseek(outbuf, vmbuf_wavail(outbuf) - strm.avail_out);
        if (res == Z_STREAM_END)
            break;
        if (Z_OK != res)
            return inflateEnd(&strm), -1;
        vmbuf_rseek(inbuf, vmbuf_ravail(inbuf) - strm.avail_in);
    }
    inflateEnd(&strm);
    return 0;
}
Exemplo n.º 2
0
/*
 * inline
 */
_RIBS_INLINE_ int http_uri_encode(const char *in, struct vmbuf *out) {

    static uint8_t bits[] = {
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x9B, 0x00, 0xFC,
        0x01, 0x00, 0x00, 0x78, 0x01, 0x00, 0x00, 0xF8,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
    };
    static char hex_chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                                'A', 'B', 'C', 'D', 'E', 'F'
                              };
    const uint8_t *inbuf = (const uint8_t *)in;

    vmbuf_resize_if_less(out, vmbuf_wlocpos(out)+(strlen(in)*3)+1);
    uint8_t *outbuf = (uint8_t *)vmbuf_wloc(out);

    if (outbuf == NULL) {
        return -1;
    }

    for ( ; *inbuf; ++inbuf)
    {
        register uint8_t c = *inbuf;
        if (c == ' ')
        {
            *outbuf++ = '+';
        } else if ((bits[c >> 3] & (1 << (c & 7))) > 0)
        {
            *outbuf++ = '%';
            *outbuf++ = hex_chars[c >> 4];
            *outbuf++ = hex_chars[c & 15];
        }
        else
            *outbuf++ = c;

    }
Exemplo n.º 3
0
int vmbuf_inflate_ptr(void *inbuf, size_t inbuf_size, struct vmbuf *outbuf) {
    z_stream strm;
    _init_alloc(&strm);
    if (Z_OK != inflateInit2(&strm, 15+16))
        return -1;
    strm.next_in = inbuf;
    strm.avail_in = inbuf_size;
    for (;0 < strm.avail_in;)
    {
        if (0 > vmbuf_resize_if_less(outbuf, strm.avail_in << 1))
            return inflateEnd(&strm), -1;
        strm.next_out = (uint8_t *)vmbuf_wloc(outbuf);
        strm.avail_out = vmbuf_wavail(outbuf);
        int res = inflate(&strm, Z_NO_FLUSH);
        vmbuf_wseek(outbuf, vmbuf_wavail(outbuf) - strm.avail_out);
        if (res == Z_STREAM_END)
            return inflateEnd(&strm), strm.avail_in == 0 ? 0 : -1; /* return error if inbuf has extra data */
        if (Z_OK != res)
            return inflateEnd(&strm), -1;
    }
    inflateEnd(&strm);
    return -1; /* if we reached here, we have partial outbuf */

}