about summary refs log tree commit diff stats
path: root/WWW
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2012-08-10 15:39:12 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2012-08-10 15:39:12 -0400
commite95e8bb0ca158527eebbde0ca503552bfeda77c8 (patch)
tree6e8bc02687ffdf9c111c26b4fa4f3d2d3b98cd31 /WWW
parent49a26ec8e574bda2f6b8c809a30a471c7f274ff6 (diff)
downloadlynx-snapshots-e95e8bb0ca158527eebbde0ca503552bfeda77c8.tar.gz
snapshot of project "lynx", label v2-8-8dev_12k
Diffstat (limited to 'WWW')
-rw-r--r--WWW/Library/Implementation/HTAnchor.h3
-rw-r--r--WWW/Library/Implementation/HTFWriter.c361
-rw-r--r--WWW/Library/Implementation/HTFormat.c25
-rw-r--r--WWW/Library/Implementation/HTMIME.c8
4 files changed, 27 insertions, 370 deletions
diff --git a/WWW/Library/Implementation/HTAnchor.h b/WWW/Library/Implementation/HTAnchor.h
index 43b64b90..679a477d 100644
--- a/WWW/Library/Implementation/HTAnchor.h
+++ b/WWW/Library/Implementation/HTAnchor.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTAnchor.h,v 1.34 2010/06/17 00:13:37 tom Exp $
+ * $LynxId: HTAnchor.h,v 1.35 2012/08/09 23:50:33 tom Exp $
  *
  *	Hypertext "Anchor" Object				     HTAnchor.h
  *	==========================
@@ -115,6 +115,7 @@ extern "C" {
 	char *message_id;	/* Message-ID */
 	char *subject;		/* Subject */
 	long content_length;	/* Content-Length */
+	long actual_length;	/* actual length may differ */
 	char *date;		/* Date */
 	char *expires;		/* Expires */
 	char *last_modified;	/* Last-Modified */
diff --git a/WWW/Library/Implementation/HTFWriter.c b/WWW/Library/Implementation/HTFWriter.c
deleted file mode 100644
index 90ab003e..00000000
--- a/WWW/Library/Implementation/HTFWriter.c
+++ /dev/null
@@ -1,361 +0,0 @@
-/*		FILE WRITER				HTFWrite.h
- *		===========
- *
- *	This version of the stream object just writes to a C file.
- *	The file is assumed open and left open.
- *
- *	Bugs:
- *		strings written must be less than buffer size.
- */
-
-#define HTSTREAM_INTERNAL 1
-
-#include <HTUtils.h>
-
-#include <HTFWriter.h>
-
-#include <HTFormat.h>
-#include <HTAlert.h>
-#include <HTFile.h>
-
-#include <LYUtils.h>
-#include <LYLeaks.h>
-
-/*		Stream Object
- *		------------
- */
-
-struct _HTStream {
-    const HTStreamClass *isa;
-
-    FILE *fp;
-    char *end_command;
-    char *remove_command;
-    BOOL announce;
-};
-
-/*_________________________________________________________________________
- *
- *		B L A C K    H O L E    C L A S S
- *
- *	There is only one black hole instance shared by anyone
- *	who wanst a black hole.  These black holes don't radiate,
- *	they just absorb data.
- */
-static void HTBlackHole_put_character(HTStream *me, char c)
-{
-}
-static void HTBlackHole_put_string(HTStream *me, const char *s)
-{
-}
-static void HTBlackHole_write(HTStream *me, const char *s, int l)
-{
-}
-static void HTBlackHole_free(HTStream *me)
-{
-}
-static void HTBlackHole_abort(HTStream *me, HTError e)
-{
-}
-
-/*	Black Hole stream
- *	-----------------
- */
-static const HTStreamClass HTBlackHoleClass =
-{
-    "BlackHole",
-    HTBlackHole_free,
-    HTBlackHole_abort,
-    HTBlackHole_put_character, HTBlackHole_put_string,
-    HTBlackHole_write
-};
-
-static HTStream HTBlackHoleInstance =
-{
-    &HTBlackHoleClass,
-    NULL,
-    NULL,
-    NULL,
-    NO
-};
-
-/*	Black hole craetion
-*/
-HTStream *HTBlackHole(void)
-{
-    return &HTBlackHoleInstance;
-}
-
-/*_________________________________________________________________________
- *
- *		F I L E     A C T I O N 	R O U T I N E S
- *  Bug:
- *	All errors are ignored.
- */
-
-/*	Character handling
- *	------------------
- */
-
-static void HTFWriter_put_character(HTStream *me, char c)
-{
-    putc(c, me->fp);
-}
-
-/*	String handling
- *	---------------
- *
- *	Strings must be smaller than this buffer size.
- */
-static void HTFWriter_put_string(HTStream *me, const char *s)
-{
-    fputs(s, me->fp);
-}
-
-/*	Buffer write.  Buffers can (and should!) be big.
- *	------------
- */
-static void HTFWriter_write(HTStream *me, const char *s, int l)
-{
-    fwrite(s, 1, l, me->fp);
-}
-
-/*	Free an HTML object
- *	-------------------
- *
- *	Note that the SGML parsing context is freed, but the created
- *	object is not,
- *	as it takes on an existence of its own unless explicitly freed.
- */
-static void HTFWriter_free(HTStream *me)
-{
-    fclose(me->fp);
-    if (me->end_command) {	/* Temp file */
-	_HTProgress(me->end_command);	/* Tell user what's happening */
-	system(me->end_command);
-	FREE(me->end_command);
-	if (me->remove_command) {
-	    system(me->remove_command);
-	    FREE(me->remove_command);
-	}
-    }
-
-    FREE(me);
-}
-
-/*	End writing
-*/
-
-static void HTFWriter_abort(HTStream *me, HTError e)
-{
-    fclose(me->fp);
-    if (me->end_command) {	/* Temp file */
-	CTRACE((tfp, "HTFWriter: Aborting: file not executed.\n"));
-	FREE(me->end_command);
-	if (me->remove_command) {
-	    system(me->remove_command);
-	    FREE(me->remove_command);
-	}
-    }
-
-    FREE(me);
-}
-
-/*	Structured Object Class
- *	-----------------------
- */
-static const HTStreamClass HTFWriter =	/* As opposed to print etc */
-{
-    "FileWriter",
-    HTFWriter_free,
-    HTFWriter_abort,
-    HTFWriter_put_character, HTFWriter_put_string,
-    HTFWriter_write
-};
-
-/*	Subclass-specific Methods
- *	-------------------------
- */
-
-HTStream *HTFWriter_new(FILE *fp)
-{
-    HTStream *me;
-
-    if (!fp)
-	return NULL;
-
-    me = (HTStream *) malloc(sizeof(*me));
-    if (me == NULL)
-	outofmem(__FILE__, "HTML_new");
-
-    assert(me != NULL);
-
-    me->isa = &HTFWriter;
-
-    me->fp = fp;
-    me->end_command = NULL;
-    me->remove_command = NULL;
-    me->announce = NO;
-
-    return me;
-}
-
-/*	Make system command from template
- *	---------------------------------
- *
- *	See mailcap spec for description of template.
- */
-/* @@ to be written.  sprintfs will do for now.  */
-
-/*	Take action using a system command
- *	----------------------------------
- *
- *	originally from Ghostview handling by Marc Andreseen.
- *	Creates temporary file, writes to it, executes system command
- *	on end-document.  The suffix of the temp file can be given
- *	in case the application is fussy, or so that a generic opener can
- *	be used.
- */
-HTStream *HTSaveAndExecute(HTPresentation *pres,
-			   HTParentAnchor *anchor,	/* Not used */
-			   HTStream *sink)	/* Not used */
-
-#ifdef UNIX
-#define REMOVE_COMMAND "/bin/rm -f %s\n"
-#endif
-#ifdef VMS
-#define REMOVE_COMMAND "delete/noconfirm/nolog %s.."
-#endif
-
-#ifdef REMOVE_COMMAND
-{
-    char *fnam;
-    const char *suffix;
-
-    HTStream *me;
-
-    if (HTClientHost) {
-	HTAlert(CANNOT_SAVE_REMOTE);
-	return HTBlackHole();
-    }
-
-    me = (HTStream *) malloc(sizeof(*me));
-    if (me == NULL)
-	outofmem(__FILE__, "Save and execute");
-
-    assert(me != NULL);
-
-    me->isa = &HTFWriter;
-
-    /* Save the file under a suitably suffixed name */
-
-    suffix = HTFileSuffix(pres->rep, anchor->content_encoding);
-
-    fnam = (char *) malloc(L_tmpnam + 16 + strlen(suffix));
-    if (fnam == NULL)
-	outofmem(__FILE__, "HTSaveAndExecute");
-
-    assert(fnam != NULL);
-
-    tmpnam(fnam);
-    strcat(fnam, suffix);
-
-    me->fp = fopen(fnam, BIN_W);
-    if (!me->fp) {
-	HTAlert(CANNOT_OPEN_TEMP);
-	FREE(fnam);
-	FREE(me);
-	return NULL;
-    }
-
-/*	Make command to process file
-*/
-    me->end_command = 0;
-    HTSprintf0(&(me->end_command), pres->command, fnam, fnam, fnam);
-
-    me->remove_command = NULL;	/* If needed, put into end_command */
-#ifdef NOPE
-/*	Make command to delete file
-*/
-    me->remove_command = 0;
-    HTSprintf0(&(me->remove_command), REMOVE_COMMAND, fnam);
-#endif
-
-    me->announce = NO;
-    FREE(fnam);
-    return me;
-}
-
-#else				/* can do remove */
-{
-    return NULL;
-}
-#endif
-
-/*	Save Locally
- *	------------
- *
- *  Bugs:
- *	GUI Apps should open local Save panel here really.
- *
- */
-HTStream *HTSaveLocally(HTPresentation *pres,
-			HTParentAnchor *anchor,		/* Not used */
-			HTStream *sink)		/* Not used */
-
-{
-    char *fnam;
-    char *answer;
-    const char *suffix;
-
-    HTStream *me;
-
-    if (HTClientHost) {
-	HTAlert(CANNOT_SAVE_REMOTE);
-	return HTBlackHole();
-    }
-
-    me = (HTStream *) malloc(sizeof(*me));
-    if (me == NULL)
-	outofmem(__FILE__, "SaveLocally");
-
-    assert(me != NULL);
-
-    me->isa = &HTFWriter;
-    me->end_command = NULL;
-    me->remove_command = NULL;	/* If needed, put into end_command */
-    me->announce = YES;
-
-    /* Save the file under a suitably suffixed name */
-
-    suffix = HTFileSuffix(pres->rep, anchor->content_encoding);
-
-    fnam = (char *) malloc(L_tmpnam + 16 + strlen(suffix));
-    if (fnam == NULL)
-	outofmem(__FILE__, "HTSaveLocally");
-
-    assert(fnam != NULL);
-
-    tmpnam(fnam);
-    strcat(fnam, suffix);
-
-    /*  Save Panel */
-    answer = HTPrompt(GIVE_FILENAME, fnam);
-
-    FREE(fnam);
-
-    me->fp = fopen(answer, BIN_W);
-    if (!me->fp) {
-	HTAlert(CANNOT_OPEN_OUTPUT);
-	FREE(answer);
-	FREE(me);
-	return NULL;
-    }
-
-    FREE(answer);
-    return me;
-}
-
-/*	Format Converter using system command
- *	-------------------------------------
- */
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index ef574499..98daa0b4 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTFormat.c,v 1.74 2011/06/11 12:13:09 tom Exp $
+ * $LynxId: HTFormat.c,v 1.75 2012/08/10 11:48:05 tom Exp $
  *
  *		Manage different file formats			HTFormat.c
  *		=============================
@@ -742,7 +742,9 @@ int HTCopy(HTParentAnchor *anchor,
 {
     HTStreamClass targetClass;
     BOOL suppress_readprogress = NO;
-    off_t bytes;
+    off_t limit = anchor ? anchor->content_length : 0;
+    off_t bytes = anchor ? anchor->actual_length : 0;
+    off_t total;
     int rv = 0;
 
     /*  Push the data down the stream
@@ -754,7 +756,7 @@ int HTCopy(HTParentAnchor *anchor,
      *
      * This operation could be put into a main event loop
      */
-    HTReadProgress(bytes = 0, (off_t) 0);
+    HTReadProgress(bytes, (off_t) 0);
     for (;;) {
 	int status;
 
@@ -875,13 +877,24 @@ int HTCopy(HTParentAnchor *anchor,
 	}
 #endif /* NOT_ASCII */
 
-	(*targetClass.put_block) (sink, input_buffer, status);
-	bytes += status;
+	total = bytes + status;
+	if (limit == 0 || (total < limit)) {
+	    (*targetClass.put_block) (sink, input_buffer, status);
+	} else if (bytes < limit) {
+	    (*targetClass.put_block) (sink, input_buffer, (int) (limit - bytes));
+	}
+	bytes = total;
 	if (!suppress_readprogress)
-	    HTReadProgress(bytes, (off_t) (anchor ? anchor->content_length : 0));
+	    HTReadProgress(bytes, limit);
 	HTDisplayPartial();
 
     }				/* next bufferload */
+    if (anchor != 0) {
+	CTRACE((tfp, "HTCopy copied %"
+		PRI_off_t " actual, %"
+		PRI_off_t " limit\n", bytes, limit));
+	anchor->actual_length = bytes;
+    }
 
     _HTProgress(TRANSFER_COMPLETE);
     (void) NETCLOSE(file_number);
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index bdb86ec9..688fb58a 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTMIME.c,v 1.76 2011/06/11 12:10:40 tom Exp $
+ * $LynxId: HTMIME.c,v 1.77 2012/08/10 11:49:03 tom Exp $
  *
  *			MIME Message Parse			HTMIME.c
  *			==================
@@ -1075,7 +1075,11 @@ static void HTMIME_put_character(HTStream *me, int c)
     switch (me->state) {
       begin_transparent:
     case MIME_TRANSPARENT:
-	(*me->targetClass.put_character) (me->target, c);
+	me->anchor->actual_length += 1;
+	if (me->anchor->content_length == 0 ||
+	    (me->anchor->content_length >= me->anchor->actual_length)) {
+	    (me->targetClass.put_character) (me->target, c);
+	}
 	return;
 
 	/* RFC-2616 describes chunked transfer coding */