pike.git / src / modules / Gz / zlibmod.c

version» Context lines:

pike.git/src/modules/Gz/zlibmod.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: zlibmod.c,v 1.63 2003/04/14 17:10:57 marcus Exp $ + || $Id: zlibmod.c,v 1.64 2003/04/15 15:00:58 marcus Exp $   */      #include "global.h" - RCSID("$Id: zlibmod.c,v 1.63 2003/04/14 17:10:57 marcus Exp $"); + RCSID("$Id: zlibmod.c,v 1.64 2003/04/15 15:00:58 marcus Exp $");      #include "zlib_machine.h"   #include "module.h"      #if !defined(HAVE_LIBZ) && !defined(HAVE_LIBGZ)   #undef HAVE_ZLIB_H   #endif      #ifdef HAVE_ZLIB_H   
pike.git/src/modules/Gz/zlibmod.c:32:   #include <zlib.h>         #define sp Pike_sp      struct zipper   {    int level;    int state;    struct z_stream_s gz; +  struct pike_string *epilogue;   #ifdef _REENTRANT    DEFINE_MUTEX(lock);   #endif /* _REENTRANT */   };      #define BUF 32768   #define MAX_BUF (64*BUF)      #undef THIS   #define THIS ((struct zipper *)(Pike_fp->current_storage))
pike.git/src/modules/Gz/zlibmod.c:301:      static void init_gz_deflate(struct object *o)   {    mt_init(& THIS->lock);    MEMSET(& THIS->gz, 0, sizeof(THIS->gz));    THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL;    THIS->gz.opaque=(void *)THIS;    THIS->state=0;    deflateInit(& THIS->gz, THIS->level = Z_DEFAULT_COMPRESSION); +  THIS->epilogue = NULL;   }      static void exit_gz_deflate(struct object *o)   {   /* mt_lock(& THIS->lock); */    deflateEnd(&THIS->gz); -  +  do_free_string(THIS->epilogue);   /* mt_unlock(& THIS->lock); */    mt_destroy( & THIS->lock );   }      /*! @endclass    */      /*******************************************************************/      /*! @class inflate
pike.git/src/modules/Gz/zlibmod.c:512:    toss_buffer(&buf);    if(THIS->gz.msg)    Pike_error("Error in gz_inflate->inflate(): %s\n",THIS->gz.msg);    else    Pike_error("Error in gz_inflate->inflate(): %d\n",fail);    }       pop_n_elems(args);       push_string(low_free_buf(&buf)); +  +  if(fail == Z_STREAM_END) +  { +  struct pike_string *old_epilogue = this->epilogue; +  if(old_epilogue) { +  push_string(old_epilogue); +  this->epilogue = NULL; +  } +  push_string(make_shared_binary_string(this->gz.next_in, +  this->gz.avail_in)); +  if(old_epilogue) +  f_add(2); +  if(sp[-1].type == PIKE_T_STRING) +  this->epilogue = (--sp)->u.string; +  else +  pop_stack(); +  } +     if(fail != Z_STREAM_END && fail!=Z_OK && !sp[-1].u.string->len)    {    pop_stack();    push_int(0);    }   }    -  + /*! @decl string end_of_stream() +  *! +  *! This function returns 0 if the end of stream marker has not yet +  *! been encountered, or a string (possibly empty) containg any extra data +  *! received following the end of stream marker if the marker has been +  *! encountered. If the extra data is not needed, the result of this +  *! function can be treated as a logical value. +  */ + static void gz_end_of_stream(INT32 args) + { +  struct zipper *this=THIS; +  pop_n_elems(args); +  if(this->epilogue) +  ref_push_string(this->epilogue); +  else +  push_int(0); + } +    static void init_gz_inflate(struct object *o)   {    mt_init(& THIS->lock);    MEMSET(& THIS->gz, 0, sizeof(THIS->gz));    THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL;    THIS->gz.opaque=(void *)THIS;    inflateInit(&THIS->gz);    inflateEnd(&THIS->gz); -  +  THIS->epilogue = NULL;   }      static void exit_gz_inflate(struct object *o)   {   /* mt_lock(& THIS->lock); */    inflateEnd(& THIS->gz); -  +  do_free_string(THIS->epilogue);   /* mt_unlock(& THIS->lock); */    mt_destroy( & THIS->lock );   }      /*! @endclass    */      /*! @decl int crc32(string data, void|int start_value)    *!    *! This function calculates the standard ISO3309 Cyclic Redundancy Check.
pike.git/src/modules/Gz/zlibmod.c:605: Inside #if defined(HAVE_ZLIB_H)
      end_class("deflate",0);       start_new_program();    ADD_STORAGE(struct zipper);       /* function(int|void:void) */    ADD_FUNCTION("create",gz_inflate_create,tFunc(tOr(tInt,tVoid),tVoid),0);    /* function(string:string) */    ADD_FUNCTION("inflate",gz_inflate,tFunc(tStr,tStr),0); +  /* function(:string) */ +  ADD_FUNCTION("end_of_stream",gz_end_of_stream,tFunc(tNone,tStr),0);       add_integer_constant("NO_FLUSH",Z_NO_FLUSH,0);    add_integer_constant("PARTIAL_FLUSH",Z_PARTIAL_FLUSH,0);    add_integer_constant("SYNC_FLUSH",Z_SYNC_FLUSH,0);    add_integer_constant("FINISH",Z_FINISH,0);       set_init_callback(init_gz_inflate);    set_exit_callback(exit_gz_inflate);       end_class("inflate",0);