Annotation of libwww/Library/src/HTSChunk.c, revision 2.2

2.1       frystyk     1: /*
                      2: **     STREAM TO CHUNK CONVERTER
                      3: **
                      4: **     (c) COPYRIGHT MIT 1995.
                      5: **     Please first read the full copyright statement in the file COPYRIGH.
2.2     ! frystyk     6: **     @(#) $Id: HTSChunk.c,v 2.1 1996/06/28 16:31:27 frystyk Exp $
2.1       frystyk     7: **
                      8: **     This stream converts a stream to a chunk object.
                      9: */
                     10: 
                     11: /* Library include files */
                     12: #include "sysdep.h"
                     13: #include "WWWUtil.h"
                     14: #include "WWWCore.h"
                     15: #include "HTSChunk.h"                                   /* Implemented here */
                     16: 
                     17: #define HT_MAXSIZE     0x10000               /* Max size of allocated chunk */
                     18: #define HT_GROWSIZE    0x2000                        /* Increment buffer by */
                     19: 
                     20: struct _HTStream {
                     21:     HTStreamClass *    isa;
                     22:     HTRequest *                request;
                     23:     HTChunk *          chunk;
                     24: 
                     25:     int                        cur_size;
                     26:     int                        max_size;
                     27:     BOOL               give_up;
                     28: };
                     29: 
                     30: /* ------------------------------------------------------------------------- */
                     31: 
                     32: PRIVATE int HTSC_flush (HTStream * me)
                     33: {
                     34:     return HT_OK;                      /* Nothing to flush */
                     35: }
                     36: 
                     37: /*
                     38: **     We don't free the chunk as this is for the caller to do
                     39: */
                     40: PRIVATE int HTSC_free (HTStream * me)
                     41: {
                     42:     if (STREAM_TRACE) HTTrace("Chunkstream. FREEING...\n");
                     43:     HT_FREE(me);
                     44:     return HT_OK;
                     45: }
                     46: 
                     47: /*
                     48: **     We don't free the chunk as this is for the caller to do
                     49: */
                     50: PRIVATE int HTSC_abort (HTStream * me, HTList * errorlist)
                     51: {
                     52:     if (STREAM_TRACE) HTTrace("Chunkstream. ABORTING...\n");
                     53:     HT_FREE(me);
                     54:     return HT_ERROR;
                     55: }
                     56: 
                     57: PRIVATE int HTSC_putBlock (HTStream * me, const char * b, int l)
                     58: {
                     59:     me->cur_size += l;
2.2     ! frystyk    60: 
        !            61:     /*
        !            62:     ** Currently we ask the user whether to proceed even though we have a full
        !            63:     ** buffer. In the case of puting a document we could also just start 
        !            64:     ** sending data.
        !            65:     */
        !            66:     if (me->cur_size > me->max_size) {
        !            67:        HTAlertCallback *cbf = HTAlert_find(HT_A_CONFIRM);
        !            68:        if ((cbf && (*cbf)(me->request, HT_A_CONFIRM, HT_MSG_BIG_PUT,
        !            69:                           NULL, NULL, NULL)))
        !            70:            me->max_size *= 4;
        !            71:        else
        !            72:            me->give_up = YES;
        !            73:     }
2.1       frystyk    74:     if (!me->give_up) {
                     75:        HTChunk_putb(me->chunk, b, l);
                     76:        return HT_OK;
2.2     ! frystyk    77:     }    
2.1       frystyk    78:     return HT_ERROR;
                     79: }
                     80: 
                     81: PRIVATE int HTSC_putCharacter (HTStream * me, char c)
                     82: {
                     83:     return HTSC_putBlock(me, &c, 1);
                     84: }
                     85: 
                     86: PRIVATE int HTSC_putString (HTStream * me, const char * s)
                     87: {
                     88:     return HTSC_putBlock(me, s, (int) strlen(s));
                     89: }
                     90: 
                     91: HTStreamClass HTStreamToChunkClass = {
                     92:     "StreamToChunk",
                     93:     HTSC_flush,
                     94:     HTSC_free,
                     95:     HTSC_abort,
                     96:     HTSC_putCharacter,
                     97:     HTSC_putString,
                     98:     HTSC_putBlock
                     99: };
                    100: 
                    101: PUBLIC HTStream * HTStreamToChunk (HTRequest *         request,
                    102:                                   HTChunk **   chunk,
                    103:                                   int          max_size)
                    104: {
                    105:     if (request) {
                    106:        HTStream * me;
                    107:        *chunk = NULL;
                    108:        if ((me = (HTStream  *) HT_CALLOC(1, sizeof(HTStream))) == NULL)
                    109:            HT_OUTOFMEM("HTStreamToChunk");
                    110:        me->isa = &HTStreamToChunkClass;
                    111:        me->request = request;
                    112:        me->max_size = (max_size > 0) ? max_size : HT_MAXSIZE;
                    113:        me->chunk = *chunk = HTChunk_new(HTMIN(me->max_size, HT_GROWSIZE));
                    114:        if (STREAM_TRACE)
                    115:            HTTrace("ChunkStream. Chunk %p created\n", me->chunk);
                    116:        return me;
                    117:     }
                    118:     return HTErrorStream();
                    119: }
                    120: 

Webmaster