Exemplo n.º 1
0
int LYUpload( char *line )
{
  int eax;
  char *method, *directory;
  int method_number;
  int count;
  char *the_upload = 0;
  char tmpbuf[256];
  char *filename = 0;
  lynx_list_item_type *upload_command = 0;
  char *the_command = 0;
  directory = strstr( line, "TO=" );
  if ( directory != 0 )
  {
    directory[ -1 ] = 0;
    directory += 3;
    method = strstr( line, "UPLOAD=" );
    if ( method != 0 )
    {
      method += 7;
      method_number = atoi( method );
      count = 0;
      upload_command = uploaders;
      for ( ; count < method_number; upload_command = &upload_command )
      {
        count++;
        //upload_command = &upload_command;
      }
      if ( upload_command->command == 0 )
      {
        HTAlert( gettext( "ERROR! - upload command is misconfigured" ) );
      }
      if ( HTCountCommandArgs( upload_command->command ) != 0 )
      {
        mustshow = 1;
        statusline( gettext( "Enter a filename: " ) );
        do
        {
          tmpbuf[0] = 0;
          if ( LYgetstr( tmpbuf, 0, 256, 0 ) >= 0 && ( tmpbuf[0] & 255 ) != 0 )
          {
            if ( strstr( tmpbuf, "../" ) != 0 )
            {
              HTAlert( gettext( "Illegal redirection \"../\" found! Request ignored." ) );
            }
            if ( strchr( tmpbuf, 47 ) != 0 )
            {
              HTAlert( gettext( "Illegal character \"/\" found! Request ignored." ) );
            }
            if ( tmpbuf[0] == '~' )
            {
              HTAlert( gettext( "Illegal redirection using \"~\" found! Request ignored." ) );
            }
            HTSprintf0( &filename, "%s/%s", directory, tmpbuf[0] );
            if ( filename[0] == '|' )
            {
              HTAlert( gettext( "Cannot write to file." ) );
              mustshow = 1;
              statusline( gettext( "Enter a new filename: " ) );
            }
            switch ( LYValidateOutput( filename ) )
            {
            case 89:
              if ( ( WWW_TraceFlag & 255 ) != 0 )
              {
                fprintf( TraceFP( ), "LYUpload: filename is %s", filename );
              }
              break;
            default:
              HTInfoMsg( gettext( "Cancelling!" ) );
              if ( ( 0 ^ 0 ) != 0 )
              {
                __stack_chk_fail( );
                break;
              }
              break;
            }
          }
        }
        while ( ( LYCanWriteFile( filename ) & 255 ) == 0 );
        HTAddParam( &the_upload, upload_command->command, 1, filename );
        HTEndParam( &the_upload, upload_command->command, 1 );
      }
      else
      {
        HTSACopy( &the_upload, upload_command->command );
        HTAddParam( &the_command, "cd %s ; ", 1, directory );
        HTEndParam( &the_command, "cd %s ; ", 1 );
        HTSACat( &the_command, the_upload );
        if ( ( WWW_TraceFlag & 255 ) != 0 )
        {
          fprintf( TraceFP( ), "command: %s\n", the_command );
        }
        stop_curses( );
        LYSystem( the_command );
        start_curses( );
        if ( the_command != 0 )
        {
          free( the_command );
          the_command = 0;
        }
        if ( the_upload != 0 )
        {
          free( the_upload );
          the_upload = 0;
        }
        if ( filename != 0 )
          chmod( filename, 384 );
        if ( filename != 0 )
        {
          free( filename );
          filename = 0;
        }
      }
    }
  }
  HTAlert( gettext( "Unable to upload file." ) );
}
Exemplo n.º 2
0
/*	Translate by rules					HTTranslate()
 *	------------------
 *
 *	The most recently defined rules are applied first.
 *
 * On entry,
 *	required	points to a string whose equivalent value is needed
 * On exit,
 *	returns		the address of the equivalent string allocated from
 *			the heap which the CALLER MUST FREE. If no translation
 *			occurred, then it is a copy of the original.
 * NEW FEATURES:
 *			When a "protect" or "defprot" rule is matched,
 *			a call to HTAA_setCurrentProtection() or
 *			HTAA_setDefaultProtection() is made to notify
 *			the Access Authorization module that the file is
 *			protected, and so it knows how to handle it.
 *								-- AL
 */
char *HTTranslate(const char *required)
{
    rule *r;
    char *current = NULL;
    char *msgtmp = NULL;
    const char *pMsg;
    int proxy_none_flag = 0;
    int permitredir_flag = 0;

    StrAllocCopy(current, required);

    HTAA_clearProtections();	/* Reset from previous call -- AL */

    for (r = rules; r; r = r->next) {
	char *p = r->pattern;
	int m = 0;		/* Number of characters matched against wildcard */
	const char *q = current;

	for (; *p && *q; p++, q++) {	/* Find first mismatch */
	    if (*p != *q)
		break;
	}

	if (*p == '*') {	/* Match up to wildcard */
	    m = strlen(q) - strlen(p + 1);	/* Amount to match to wildcard */
	    if (m < 0)
		continue;	/* tail is too short to match */
	    if (0 != strcmp(q + m, p + 1))
		continue;	/* Tail mismatch */
	} else
	    /* Not wildcard */ if (*p != *q)
	    continue;		/* plain mismatch: go to next rule */

	if (!rule_cond_ok(r))	/* check condition, next rule if false - kw */
	    continue;

	switch (r->op) {	/* Perform operation */

#ifdef ACCESS_AUTH
	case HT_DefProt:
	case HT_Protect:
	    {
		char *local_copy = NULL;
		char *p2;
		char *eff_ids = NULL;
		char *prot_file = NULL;

		CTRACE((tfp, "HTRule: `%s' matched %s %s: `%s'\n",
			current,
			(r->op == HT_Protect ? "Protect" : "DefProt"),
			"rule, setup",
			(r->equiv ? r->equiv :
			 (r->op == HT_Protect ? "DEFAULT" : "NULL!!"))));

		if (r->equiv) {
		    StrAllocCopy(local_copy, r->equiv);
		    p2 = local_copy;
		    prot_file = HTNextField(&p2);
		    eff_ids = HTNextField(&p2);
		}

		if (r->op == HT_Protect)
		    HTAA_setCurrentProtection(current, prot_file, eff_ids);
		else
		    HTAA_setDefaultProtection(current, prot_file, eff_ids);

		FREE(local_copy);

		/* continue translating rules */
	    }
	    break;
#endif /* ACCESS_AUTH */

	case HT_UserMsg:	/* Produce message immediately */
	    LYFixCursesOn("show rule message:");
	    HTUserMsg2((r->equiv ? r->equiv : "Rule: %s"), current);
	    break;
	case HT_InfoMsg:	/* Produce messages immediately */
	case HT_Progress:
	case HT_Alert:
	    LYFixCursesOn("show rule message:");	/* and fall through */
	case HT_AlwaysAlert:
	    pMsg = r->equiv ? r->equiv :
		(r->op == HT_AlwaysAlert) ? "%s" : "Rule: %s";
	    if (strchr(pMsg, '%')) {
		HTSprintf0(&msgtmp, pMsg, current);
		pMsg = msgtmp;
	    }
	    switch (r->op) {	/* Actually produce message */
	    case HT_InfoMsg:
		HTInfoMsg(pMsg);
		break;
	    case HT_Progress:
		HTProgress(pMsg);
		break;
	    case HT_Alert:
		HTAlert(pMsg);
		break;
	    case HT_AlwaysAlert:
		HTAlwaysAlert("Rule alert:", pMsg);
		break;
	    default:
		break;
	    }
	    FREE(msgtmp);
	    break;

	case HT_PermitRedir:	/* Set special flag */
	    permitredir_flag = 1;
	    CTRACE((tfp, "HTRule: Mark for redirection permitted\n"));
	    break;

	case HT_Pass:		/* Authorised */
	    if (!r->equiv) {
		if (proxy_none_flag) {
		    char *temp = NULL;

		    StrAllocCopy(temp, "NoProxy=");
		    StrAllocCat(temp, current);
		    FREE(current);
		    current = temp;
		}
		CTRACE((tfp, "HTRule: Pass `%s'\n", current));
		return current;
	    }
	    /* Else fall through ...to map and pass */

	case HT_Map:
	case HT_Redirect:
	case HT_RedirectPerm:
	    if (*p == *q) {	/* End of both strings, no wildcard */
		CTRACE((tfp, "For `%s' using `%s'\n", current, r->equiv));
		StrAllocCopy(current, r->equiv);	/* use entire translation */
	    } else {
		char *ins = strchr(r->equiv, '*');	/* Insertion point */

		if (ins) {	/* Consistent rule!!! */
		    char *temp = NULL;

		    HTSprintf0(&temp, "%.*s%.*s%s",
			       (int) (ins - r->equiv),
			       r->equiv,
			       m,
			       q,
			       ins + 1);
		    CTRACE((tfp, "For `%s' using `%s'\n",
			    current, temp));
		    FREE(current);
		    current = temp;	/* Use this */

		} else {	/* No insertion point */
		    char *temp = NULL;

		    StrAllocCopy(temp, r->equiv);
		    CTRACE((tfp, "For `%s' using `%s'\n",
			    current, temp));
		    FREE(current);
		    current = temp;	/* Use this */
		}		/* If no insertion point exists */
	    }
	    if (r->op == HT_Pass) {
		if (proxy_none_flag) {
		    char *temp = NULL;

		    StrAllocCopy(temp, "NoProxy=");
		    StrAllocCat(temp, current);
		    FREE(current);
		    current = temp;
		}
		CTRACE((tfp, "HTRule: ...and pass `%s'\n",
			current));
		return current;
	    } else if (r->op == HT_Redirect) {
		CTRACE((tfp, "HTRule: ...and redirect to `%s'\n",
			current));
		redirecting_url = current;
		HTPermitRedir = (BOOL) (permitredir_flag == 1);
		return (char *) 0;
	    } else if (r->op == HT_RedirectPerm) {
		CTRACE((tfp, "HTRule: ...and redirect like 301 to `%s'\n",
			current));
		redirecting_url = current;
		permanent_redirection = TRUE;
		HTPermitRedir = (BOOL) (permitredir_flag == 1);
		return (char *) 0;
	    }
	    break;

	case HT_UseProxy:
	    if (r->equiv && 0 == strcasecomp(r->equiv, "none")) {
		CTRACE((tfp, "For `%s' will not use proxy\n", current));
		proxy_none_flag = 1;
	    } else if (proxy_none_flag) {
		CTRACE((tfp, "For `%s' proxy server ignored: %s\n",
			current,
			NONNULL(r->equiv)));
	    } else {
		char *temp = NULL;

		StrAllocCopy(temp, "Proxied=");
		StrAllocCat(temp, r->equiv);
		StrAllocCat(temp, current);
		CTRACE((tfp, "HTRule: proxy server found: %s\n",
			NONNULL(r->equiv)));
		FREE(current);
		return temp;
	    }
	    break;

	case HT_Invalid:
	case HT_Fail:		/* Unauthorised */
	    CTRACE((tfp, "HTRule: *** FAIL `%s'\n", current));
	    FREE(current);
	    return (char *) 0;
	}			/* if tail matches ... switch operation */

    }				/* loop over rules */

    if (proxy_none_flag) {
	char *temp = NULL;

	StrAllocCopy(temp, "NoProxy=");
	StrAllocCat(temp, current);
	FREE(current);
	return temp;
    }

    return current;
}
Exemplo n.º 3
0
/*
 *  In edit mode invoke the given (or default) editor to display and edit the
 *  current file.  For editors listed in 'editor_can_position()', Lynx
 *  will open the file to the same line that the screen cursor is on (or
 *  close...) when editing is invoked.
 *
 *  Returns FALSE if file is uneditable.
 */
PUBLIC int edit_current_file ARGS3(
	char *,		newfile,
	int,		cur,
	int,		lineno)
{
    int result = FALSE;
    char *filename = NULL;
#if !(defined(VMS) || defined(USE_DOS_DRIVES))
    char *colon;
#endif
    char *number_sign;
    char position[80];
#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
    FILE *fp;
#endif

    CTRACE((tfp, "edit_current_file(newfile=%s, cur=%d, lineno=%d)\n",
		 newfile, cur, lineno));

    /*
     *  If it's a remote file then we can't edit it.
     */
    if (!LYisLocalFile(newfile)) {
	HTUserMsg(CANNOT_EDIT_REMOTE_FILES);
	return FALSE;
    }

    /*
     *  If there's a fragment, trim it. - FM
     */
    number_sign = trimPoundSelector(newfile);

    /*
     *  On Unix, first try to open it as a completely referenced file,
     *  then via the path alone.
     *
     * On VMS, only try the path.
     */
#if defined (VMS) || defined (USE_DOS_DRIVES)
    filename = HTParse(newfile, "", PARSE_PATH+PARSE_PUNCTUATION);
    HTUnEscape(filename);
    StrAllocCopy(filename, HTSYS_name(filename));
    if (!LYCanReadFile(filename)) {
#ifdef SH_EX
	HTUserMsg2(COULD_NOT_EDIT_FILE, filename);
#else
	HTAlert(COULD_NOT_ACCESS_FILE);
#endif
	CTRACE((tfp, "filename: '%s'\n", filename));
	goto done;
    }
#else	/* something like UNIX */
    if (strncmp(newfile, "file://localhost/", 16) == 0)
	colon = newfile + 16;
    else
	colon = strchr(newfile, ':');
    StrAllocCopy(filename, (colon + 1));
    HTUnEscape(filename);
    if (!LYCanReadFile(filename)) {
	FREE(filename);
	filename = HTParse(newfile, "", PARSE_PATH+PARSE_PUNCTUATION);
	HTUnEscape(filename);
	if (!LYCanReadFile(HTSYS_name(filename))) {
	    HTAlert(COULD_NOT_ACCESS_FILE);
	    goto done;
	}
    }
#endif

#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
    /*
     *  Don't allow editing if user lacks append access.
     */
    if ((fp = fopen(filename, TXT_A)) == NULL)
    {
	HTUserMsg(NOAUTH_TO_EDIT_FILE);
	goto done;
    }
    fclose(fp);
#endif /* VMS || CANT_EDIT_UNWRITABLE_FILES */

    /*
     *  Make sure cur is at least zero. - FM
     */
    if (cur < 0) {
	cur = 0;
    }

    /*
     *  Set up the command for the editor. - FM
     */
    *position = 0;
#ifdef VMS
    lineno--;
#endif
    lineno += (nlinks ? links[cur].ly : 0);
    if (lineno > 0)
	sprintf(position, "%d", lineno);

    edit_temporary_file(filename, position, NULL);
    result = TRUE;

done:
    /*
     *  Restore the fragment if there was one. - FM
     */
    restorePoundSelector(number_sign);

    FREE(filename);
    CTRACE((tfp, "edit_current_file returns %d\n", result));
    return (result);
}
Exemplo n.º 4
0
/*
 *  This function is called from HTLoadNews() to have the user
 *  create a file with news headers and a body for posting of
 *  a new message (based on a newspost://nntp_host/newsgroups
 *  or snewspost://secure_nntp_host/newsgroups URL), or to post
 *  a followup (based on a newsreply://nntp_host/newsgroups or
 *  snewsreply://secure_nntp_host/newsgroups URL). The group
 *  or comma-separated list of newsgroups is passed without
 *  a lead slash, and followup is TRUE for newsreply or
 *  snewsreply URLs.  - FM
 */
char *LYNewsPost(char *newsgroups,
		 BOOLEAN followup)
{
    char user_input[MAX_LINE];
    char CJKinput[MAX_LINE];
    char *cp = NULL;
    const char *kp = NULL;
    int c = 0;			/* user input */
    int len;
    FILE *fd = NULL;
    char my_tempfile[LY_MAXPATH];
    FILE *fc = NULL;
    char CJKfile[LY_MAXPATH];
    char *postfile = NULL;
    char *NewsGroups = NULL;
    char *References = NULL;
    char *org = NULL;
    FILE *fp = NULL;
    BOOLEAN nonempty = FALSE;
    BOOLEAN nonspaces = FALSE;

    /*
     * Make sure a non-zero length newspost, newsreply, snewspost or snewsreply
     * path was sent to us.  - FM
     */
    if (isEmpty(newsgroups))
	return (postfile);

    /*
     * Return immediately if we do get called, maybe by some quirk of HTNews.c,
     * when we shouldn't.  - kw
     */
    if (no_newspost)
	return (postfile);

    /*
     * Open a temporary file for the headers and message body.  - FM
     */
#ifdef __DJGPP__
    if ((fd = LYOpenTemp(my_tempfile, HTML_SUFFIX, BIN_W)) == NULL)
#else
    if ((fd = LYOpenTemp(my_tempfile, HTML_SUFFIX, "w")) == NULL)
#endif /* __DJGPP__ */
    {
	HTAlert(CANNOT_OPEN_TEMP);
	return (postfile);
    }

    /*
     * If we're using a Japanese display character set, open a temporary file
     * for a conversion to JIS.  - FM
     */
    CJKfile[0] = '\0';
    if (current_char_set == UCGetLYhndl_byMIME("euc-jp") ||
	current_char_set == UCGetLYhndl_byMIME("shift_jis")) {
	if ((fc = LYOpenTemp(CJKfile, HTML_SUFFIX, "w")) == NULL) {
	    HTAlert(CANNOT_OPEN_TEMP);
	    LYRemoveTemp(my_tempfile);
	    return (postfile);
	}
    }

    /*
     * The newsgroups could be a comma-seperated list.  It need not have
     * spaces, but deal with any that may also have been hex escaped.  - FM
     */
    StrAllocCopy(NewsGroups, newsgroups);
    if ((cp = strstr(NewsGroups, ";ref="))) {
	*cp = '\0';
	cp += 5;
	if (*cp == '<') {
	    StrAllocCopy(References, cp);
	} else {
	    StrAllocCopy(References, "<");
	    StrAllocCat(References, cp);
	    StrAllocCat(References, ">");
	}
	HTUnEscape(References);
	if (!((cp = strchr(References, '@')) && cp > References + 1 &&
	      isalnum(UCH(cp[1])))) {
	    FREE(References);
	}
    }
    HTUnEscape(NewsGroups);
    if (!*NewsGroups) {
	LYCloseTempFP(fd);	/* Close the temp file. */
	goto cleanup;
    }

    /*
     * Allow ^C to cancel the posting, i.e., don't let SIGINTs exit Lynx.
     */
    signal(SIGINT, terminate_message);
    term_message = FALSE;

    /*
     * Show the list of newsgroups.  - FM
     */
    LYclear();
    LYmove(2, 0);
    scrollok(LYwin, TRUE);	/* Enable scrolling. */
    LYaddstr(gettext("You will be posting to:"));
    LYaddstr("\n\t");
    LYaddstr(NewsGroups);
    LYaddch('\n');

    /*
     * Get the mail address for the From header, offering personal_mail_address
     * as default.
     */
    LYaddstr(gettext("\n\n Please provide your mail address for the From: header\n"));
    sprintf(user_input, "From: %.*s", (int) sizeof(user_input) - 8,
	    NonNull(personal_mail_address));
    if (LYgetstr(user_input, VISIBLE,
		 sizeof(user_input), NORECALL) < 0 ||
	term_message) {
	HTInfoMsg(NEWS_POST_CANCELLED);
	LYCloseTempFP(fd);	/* Close the temp file. */
	scrollok(LYwin, FALSE);	/* Stop scrolling.      */
	goto cleanup;
    }
    fprintf(fd, "%s\n", user_input);

    /*
     * Get the Subject header, offering the current document's title as the
     * default if this is a followup rather than a new post.  - FM
     */
    LYaddstr(gettext("\n\n Please provide or edit the Subject: header\n"));
    strcpy(user_input, "Subject: ");
    if ((followup == TRUE && nhist > 0) &&
	(kp = HText_getTitle()) != NULL) {
	/*
	 * Add the default subject.
	 */
	kp = LYSkipCBlanks(kp);
#ifdef CJK_EX			/* 1998/05/15 (Fri) 09:10:38 */
	if (HTCJK == JAPANESE) {
	    CJKinput[0] = '\0';
	    switch (kanji_code) {
	    case EUC:
		TO_EUC((const unsigned char *) kp, (unsigned char *) CJKinput);
		kp = CJKinput;
		break;
	    case SJIS:
		TO_SJIS((const unsigned char *) kp, (unsigned char *) CJKinput);
		kp = CJKinput;
		break;
	    default:
		break;
	    }
	}
#endif
	if (strncasecomp(kp, "Re:", 3)) {
	    strcat(user_input, "Re: ");
	}
	len = (int) strlen(user_input);
	LYstrncpy(user_input + len, kp, (int) sizeof(user_input) - len - 1);
    }
    cp = NULL;
    if (LYgetstr(user_input, VISIBLE,
		 sizeof(user_input), NORECALL) < 0 ||
	term_message) {
	HTInfoMsg(NEWS_POST_CANCELLED);
	LYCloseTempFP(fd);	/* Close the temp file. */
	scrollok(LYwin, FALSE);	/* Stop scrolling.      */
	goto cleanup;
    }
    fprintf(fd, "%s\n", user_input);

    /*
     * Add Organization:  header.
     */
    StrAllocCopy(cp, "Organization: ");
    if ((org = LYGetEnv("ORGANIZATION")) != NULL) {
	StrAllocCat(cp, org);
    } else if ((org = LYGetEnv("NEWS_ORGANIZATION")) != NULL) {
	StrAllocCat(cp, org);
    }
#ifdef UNIX
    else if ((fp = fopen("/etc/organization", TXT_R)) != NULL) {
	char *buffer = 0;

	if (LYSafeGets(&buffer, fp) != NULL) {
	    if (user_input[0] != '\0') {
		LYTrimNewline(buffer);
		StrAllocCat(cp, buffer);
	    }
	}
	FREE(buffer);
	LYCloseInput(fp);
    }
#else
#ifdef _WINDOWS			/* 1998/05/14 (Thu) 17:47:01 */
    else {
	char *p, fname[LY_MAXPATH];

	strcpy(fname, LynxSigFile);
	p = strrchr(fname, '/');
	if (p != 0 && (p - fname) < sizeof(fname) - 15) {
	    strcpy(p + 1, "LYNX_ETC.TXT");
	    if ((fp = fopen(fname, TXT_R)) != NULL) {
		if (fgets(user_input, sizeof(user_input), fp) != NULL) {
		    if ((org = strchr(user_input, '\n')) != NULL) {
			*org = '\0';
		    }
		    if (user_input[0] != '\0') {
			StrAllocCat(cp, user_input);
		    }
		}
		LYCloseInput(fp);
	    }
	}
    }
#endif /* _WINDOWS */
#endif /* !UNIX */
    LYstrncpy(user_input, cp, (sizeof(user_input) - 16));
    FREE(cp);
    LYaddstr(gettext("\n\n Please provide or edit the Organization: header\n"));
    if (LYgetstr(user_input, VISIBLE,
		 sizeof(user_input), NORECALL) < 0 ||
	term_message) {
	HTInfoMsg(NEWS_POST_CANCELLED);
	LYCloseTempFP(fd);	/* Close the temp file. */
	scrollok(LYwin, FALSE);	/* Stop scrolling.      */
	goto cleanup;
    }
    fprintf(fd, "%s\n", user_input);

    if (References) {
	fprintf(fd, "References: %s\n", References);
    }
    /*
     * Add Newsgroups Summary and Keywords headers.
     */
    fprintf(fd, "Newsgroups: %s\nSummary: \nKeywords: \n\n", NewsGroups);

    /*
     * Have the user create the message body.
     */
    if (!no_editor && non_empty(editor)) {

	if (followup && nhist > 0) {
	    /*
	     * Ask if the user wants to include the original message.
	     */
	    if (term_message) {
		_statusline(INC_ORIG_MSG_PROMPT);
	    } else if (HTConfirm(INC_ORIG_MSG_PROMPT) == YES) {
		/*
		 * The 'TRUE' will add the reply ">" in front of every line. 
		 * We're assuming that if the display character set is Japanese
		 * and the document did not have a CJK charset, any non-EUC or
		 * non-SJIS 8-bit characters in it where converted to 7-bit
		 * equivalents.  - FM
		 */
		print_wwwfile_to_fd(fd, FALSE, TRUE);
	    }
	}
	LYCloseTempFP(fd);	/* Close the temp file. */
	scrollok(LYwin, FALSE);	/* Stop scrolling.      */
	if (term_message || LYCharIsINTERRUPT(c))
	    goto cleanup;

	/*
	 * Spawn the user's editor on the news file.
	 */
	edit_temporary_file(my_tempfile, "", SPAWNING_EDITOR_FOR_NEWS);

	nonempty = message_has_content(my_tempfile, &nonspaces);

    } else {
	/*
	 * Use the built in line editior.
	 */
	LYaddstr(gettext("\n\n Please enter your message below."));
	LYaddstr(gettext("\n When you are done, press enter and put a single period (.)"));
	LYaddstr(gettext("\n on a line and press enter again."));
	LYaddstr("\n\n");
	LYrefresh();
	*user_input = '\0';
	if (LYgetstr(user_input, VISIBLE,
		     sizeof(user_input), NORECALL) < 0 ||
	    term_message) {
	    HTInfoMsg(NEWS_POST_CANCELLED);
	    LYCloseTempFP(fd);	/* Close the temp file. */
	    scrollok(LYwin, FALSE);	/* Stop scrolling.      */
	    goto cleanup;
	}
	while (!STREQ(user_input, ".") && !term_message) {
	    LYaddch('\n');
	    fprintf(fd, "%s\n", user_input);
	    if (!nonempty && strlen(user_input))
		nonempty = TRUE;
	    *user_input = '\0';
	    if (LYgetstr(user_input, VISIBLE,
			 sizeof(user_input), NORECALL) < 0) {
		HTInfoMsg(NEWS_POST_CANCELLED);
		LYCloseTempFP(fd);	/* Close the temp file. */
		scrollok(LYwin, FALSE);		/* Stop scrolling.      */
		goto cleanup;
	    }
	}
	fprintf(fd, "\n");
	LYCloseTempFP(fd);	/* Close the temp file. */
	scrollok(LYwin, FALSE);	/* Stop scrolling.      */
    }

    if (nonempty) {
	/*
	 * Confirm whether to post, and if so, whether to append the sig file. 
	 * - FM
	 */
	LYStatusLine = (LYlines - 1);
	c = HTConfirm(POST_MSG_PROMPT);
	LYStatusLine = -1;
	if (c != YES) {
	    LYclear();		/* clear the screen */
	    goto cleanup;
	}
    } else {
	HTAlert(gettext("Message has no original text!"));
	if (!nonspaces
	    || HTConfirmDefault(POST_MSG_PROMPT, NO) != YES)
	    goto cleanup;
    }
    if ((LynxSigFile != NULL) && (fp = fopen(LynxSigFile, TXT_R)) != NULL) {
	char *msg = NULL;

	HTSprintf0(&msg, APPEND_SIG_FILE, LynxSigFile);

	LYStatusLine = (LYlines - 1);
	if (term_message) {
	    _user_message(APPEND_SIG_FILE, LynxSigFile);
	} else if (HTConfirm(msg) == YES) {
	    if ((fd = LYAppendToTxtFile(my_tempfile)) != NULL) {
		char *buffer = NULL;

		fputs("-- \n", fd);
		while (LYSafeGets(&buffer, fp) != NULL) {
		    fputs(buffer, fd);
		}
		LYCloseOutput(fd);
	    }
	}
	LYCloseInput(fp);
	FREE(msg);
	LYStatusLine = -1;
    }
    LYclear();			/* clear the screen */

    /*
     * If we are using a Japanese display character set, convert the contents
     * of the temp file to JIS (nothing should change if it does not, in fact,
     * contain EUC or SJIS di-bytes).  Otherwise, use the temp file as is.  -
     * FM
     */
    if (CJKfile[0] != '\0') {
	if ((fd = fopen(my_tempfile, TXT_R)) != NULL) {
	    char *buffer = NULL;

	    while (LYSafeGets(&buffer, fd) != NULL) {
		TO_JIS((unsigned char *) buffer,
		       (unsigned char *) CJKinput);
		fputs(CJKinput, fc);
	    }
	    LYCloseTempFP(fc);
	    StrAllocCopy(postfile, CJKfile);
	    LYCloseInput(fd);
	    LYRemoveTemp(my_tempfile);
	    strcpy(my_tempfile, CJKfile);
	    CJKfile[0] = '\0';
	} else {
	    StrAllocCopy(postfile, my_tempfile);
	}
    } else {
	StrAllocCopy(postfile, my_tempfile);
    }
    if (!followup) {
	/*
	 * If it's not a followup, the current document most likely is the
	 * group listing, so force a to have the article show up in the list
	 * after the posting.  Note, that if it's a followup via a link in a
	 * news article, the user must do a reload manually on returning to the
	 * group listing.  - FM
	 */
	LYforce_no_cache = TRUE;
    }
    LYStatusLine = (LYlines - 1);
    HTUserMsg(POSTING_TO_NEWS);
    LYStatusLine = -1;

    /*
     * Come here to cleanup and exit.
     */
  cleanup:
#ifndef VMS
    signal(SIGINT, cleanup_sig);
#endif /* !VMS */
    term_message = FALSE;
    if (!postfile)
	LYRemoveTemp(my_tempfile);
    LYRemoveTemp(CJKfile);
    FREE(NewsGroups);
    FREE(References);

    return (postfile);
}
Exemplo n.º 5
0
PUBLIC int change_form_link ARGS6(
	struct link *,	form_link,
	int,		mode,
	document *,	newdoc,
	BOOLEAN *,	refresh_screen,
	char *,		link_name,
	char *,		link_value)
{
    FormInfo *form = form_link->form;
    int c = DO_NOTHING;
    int OrigNumValue;

	/*
	 *  If there is no form to perform action on, don't do anything.
	 */
	if (form == NULL) {
	    return(c);
	}

    /*
     *  Move to the link position.
     */
    move(form_link->ly, form_link->lx);

    switch(form->type) {
	case F_CHECKBOX_TYPE:
	    if (form->disabled == YES)
		break;
	    if (form->num_value) {
		form_link->hightext = unchecked_box;
		form->num_value = 0;
	    } else {
		form_link->hightext = checked_box;
		form->num_value = 1;
	    }
	    break;

	case F_OPTION_LIST_TYPE:
	    if (!form->select_list) {
		HTAlert(BAD_HTML_NO_POPUP);
		c = DO_NOTHING;
		break;
	    }

	    if (form->disabled == YES) {
		int dummy;
		dummy = popup_options(form->num_value, form->select_list,
				form_link->ly, form_link->lx, form->size,
				form->size_l, form->disabled);
#if defined(FANCY_CURSES) || defined(USE_SLANG)
		if (!enable_scrollback)
#if defined(VMS) && !defined(USE_SLANG)
		    c = DO_NOTHING;
#else
		    c = 23;  /* CTRL-W refresh without clearok */
#endif /* VMS && !USE_SLANG */
		else
#endif /* FANCY_CURSES || USE_SLANG */
		    c = 12;  /* CTRL-L for repaint */
		break;
	    }
Exemplo n.º 6
0
HTStream *HTCompressed( HTPresentation *pres, HTParentAnchor *anchor, HTStream *sink )
{
  int eax;
  HTStream *me;
  HTFormat format;
  char *type = 0;
  HTPresentation *Pres = 0;
  HTPresentation *Pnow = 0;
  int n, i;
  BOOLEAN can_present = 0;
  char fnam[256];
  char temp[256];
  char *suffix;
  char *uncompress_mask = 0;
  char *compress_suffix = "";
  char *middle;
  if ( anchor == 0 || anchor->content_encoding == 0 || anchor->content_type == 0 )
  {
    format = HTAtom_for( "application/octet-stream" );
    me = HTStreamStack( format, &pres->rep_out, &sink->isa->name[0], anchor );
    return me;
  }
  else
  {
    n = HTList_count( HTPresentations );
    i = 0;
    for ( ; i < n; i++ )
    {
      Pnow = (HTPresentation*)HTList_objectAt( HTPresentations, i );
      if ( strcasecomp( (char*)Pnow->rep_out, &anchor->content_type ) == 0 && Pnow->rep_out == HTAtom_for( "www/present" ) )
      {
        char *program = "";
        if ( Pres == 0 )
          Pres = Pnow;
        else
        if ( Pres->quality <= Pnow->quality )
          Pres = Pnow;
        can_present = 1;
        switch ( HTEncodingToCompressType( &anchor->content_encoding ) )
        {
        case 2:
          program = HTGetProgramPath( 6 );
          if ( program )
          {
            HTSACopy( &uncompress_mask, program );
            HTSACat( &uncompress_mask, " -d --no-name %s" );
            compress_suffix = "gz";
          }
          break;
        case 4:
          program = HTGetProgramPath( 7 );
          if ( program )
          {
            HTSACopy( &uncompress_mask, program );
            HTSACat( &uncompress_mask, " %s" );
            compress_suffix = "zz";
          }
          break;
        case 3:
          program = HTGetProgramPath( 1 );
          if ( program )
          {
            HTSACopy( &uncompress_mask, program );
            HTSACat( &uncompress_mask, " -d %s" );
            compress_suffix = "bz2";
          }
          break;
        case 1:
          program = HTGetProgramPath( 19 );
          if ( program )
          {
            HTSACopy( &uncompress_mask, program );
            HTSACat( &uncompress_mask, " %s" );
            compress_suffix = "Z";
          }
          break;
        }
      }
      // i++;
    }
    if ( can_present == 0 || uncompress_mask == 0 || strchr( &anchor->content_type, ';' ) || HTOutputFormat == HTAtom_for( "www/download" ) || !strcasecomp( &pres->rep_out->name, "www/download" ) || ( traversal && strcasecomp( &anchor->content_type, "text/html" ) && strcasecomp( &anchor->content_type, "text/plain" ) ) )
    {
      if ( strchr( &anchor->content_encoding, '/' ) == 0 )
      {
        if ( strncasecomp( &anchor->content_encoding, "x-", 2 ) == 0 )
          HTSACopy( &type, "application/" );
        else
          HTSACopy( &type, "application/x-" );
        HTSACat( &type, &anchor->content_encoding );
      }
      else
        HTSACopy( &type, &anchor->content_encoding );
      format = HTAtom_for( type );
      if ( type )
      {
        free( type );
        type = 0;
      }
      if ( uncompress_mask )
      {
        free( uncompress_mask );
        uncompress_mask = 0;
      }
      me = HTStreamStack( format, &pres->rep_out, &sink->isa->name[0], anchor );
      return me;
    }
    else
    {
      me = calloc( 1, sizeof( HTStream ) );
      if ( me == 0 )
        outofmem( "./HTFWriter.c", "HTCompressed" );
      me->isa->name[0] = HTFWriter.name;
      me->input_format = pres->rep->next;
      me->output_format = pres->rep_out;
      me->anchor = anchor;
      me->sink = sink;
      if ( anchor->FileCache )
      {
        LYRemoveTemp( &anchor->FileCache );
        if ( anchor->FileCache )
        {
          free( &anchor->FileCache );
          anchor->FileCache = 0;
        }
      }
      middle = 0;
      if ( strcasecomp( &anchor->content_type, "text/html" ) == 0 )
      {
        middle = ".html";
        middle++;
      }
      else
      {
        if ( strncasecomp( &anchor->content_type, "text/", 5 ) == 0 )
          middle = "txt";
        else
        {
          if ( strncasecomp( &anchor->content_type, "application/", 12 ) == 0 )
            middle = "bin";
          else
          {
            suffix = HTFileSuffix( HTAtom_for( &anchor->content_type ), 0 );
            if ( suffix && suffix[0] == '.' )
              middle = &suffix[1];
          }
        }
      }
      temp[0] = 0;
      if ( middle )
      {
        memcpy( temp[0] + strlen( temp ) );
        strcat( temp, middle );
        strcat( temp, "." );
      }
      strcat( temp, compress_suffix );
      me->fp = LYOpenTemp( fnam, temp, "wb" );
      if ( me->fp == 0 )
      {
        HTAlert( gettext( "Can't open temporary file!" ) );
        if ( uncompress_mask )
        {
          free( uncompress_mask );
          uncompress_mask = 0;
        }
        if ( me )
        {
          free( me );
          me = 0;
        }
        return 0;
      }
      else
      {
        if ( dump_output_immediately == 0 && traversal == 0 && ( Pres->quality < 999.000000000000 || ( no_exec == 0 && ( local_exec || ( local_exec_on_local_files && ( LYJumpFileURL || strncmp( &anchor->address, "file://localhost", 16 ) == 0 ) ) ) ) ) )
          HTSACopy( &me->viewer_command, &Pres->command );
        if ( compress_suffix[0] == 'g' && me->viewer_command == 0 )
          HTSACopy( &me->end_command, "" );
        else
        {
          *(int*)&me->end_command = 0;
          HTAddParam( &me->end_command, uncompress_mask, 1, fnam );
          HTEndParam( &me->end_command, uncompress_mask, 1 );
        }
        if ( uncompress_mask )
        {
          free( uncompress_mask );
          uncompress_mask = 0;
        }
        *(int*)&me->remove_command = 0;
        HTAddParam( &me->remove_command, "%s", 1, fnam );
        HTEndParam( &me->remove_command, "%s", 1 );
        HTSACopy( &anchor->FileCache, fnam );
        return me;
      }
    }
  }
}
Exemplo n.º 7
0
/*	Push data from a socket down a stream
**	-------------------------------------
**
**   This routine is responsible for creating and PRESENTING any
**   graphic (or other) objects described by the file.
**
**   The file number given is assumed to be a TELNET stream, i.e., containing
**   CRLF at the end of lines which need to be stripped to LF for unix
**   when the format is textual.
**
**  State of socket and target stream on entry:
**			socket (file_number) assumed open,
**			target (sink) assumed valid.
**
**  Return values:
**	HT_INTERRUPTED  Interruption or error after some data received.
**	-2		Unexpected disconnect before any data received.
**	-1		Interruption or error before any data received, or
**			(UNIX) other read error before any data received, or
**			download cancelled.
**	HT_LOADED	Normal close of socket (end of file indication
**			received), or
**			unexpected disconnect after some data received, or
**			other read error after some data received, or
**			(not UNIX) other read error before any data received.
**
**  State of socket and target stream on return depends on return value:
**	HT_INTERRUPTED	socket still open, target aborted.
**	-2		socket still open, target stream still valid.
**	-1		socket still open, target aborted.
**	otherwise	socket closed,	target stream still valid.
*/
PUBLIC int HTCopy ARGS4(
	HTParentAnchor *,	anchor,
	int,			file_number,
	void*,			handle GCC_UNUSED,
	HTStream*,		sink)
{
    HTStreamClass targetClass;
    BOOL suppress_readprogress = NO;
    int bytes;
    int rv = 0;

    /*	Push the data down the stream
    */
    targetClass = *(sink->isa); /* Copy pointers to procedures */

    /*	Push binary from socket down sink
    **
    **	This operation could be put into a main event loop
    */
    HTReadProgress(bytes = 0, 0);
    for (;;) {
	int status;

	if (LYCancelDownload) {
	    LYCancelDownload = FALSE;
	    (*targetClass._abort)(sink, NULL);
	    rv = -1;
	    goto finished;
	}

	if (HTCheckForInterrupt()) {
	    _HTProgress (TRANSFER_INTERRUPTED);
	    (*targetClass._abort)(sink, NULL);
	    if (bytes)
		rv = HT_INTERRUPTED;
	    else
		rv = -1;
	    goto finished;
	}

#ifdef USE_SSL
	if (handle)
	    status = SSL_read((SSL *)handle, input_buffer, INPUT_BUFFER_SIZE);
	else
	    status = NETREAD(file_number, input_buffer, INPUT_BUFFER_SIZE);
#else
	status = NETREAD(file_number, input_buffer, INPUT_BUFFER_SIZE);
#endif /* USE_SSL */

	if (status <= 0) {
	    if (status == 0) {
		break;
	    } else if (status == HT_INTERRUPTED) {
		_HTProgress (TRANSFER_INTERRUPTED);
		(*targetClass._abort)(sink, NULL);
		if (bytes)
		    rv = HT_INTERRUPTED;
		else
		    rv = -1;
		goto finished;
	    } else if (SOCKET_ERRNO == ENOTCONN ||
#ifdef _WINDOWS	/* 1997/11/10 (Mon) 16:57:18 */
		       SOCKET_ERRNO == ETIMEDOUT ||
#endif
		       SOCKET_ERRNO == ECONNRESET ||
		       SOCKET_ERRNO == EPIPE) {
		/*
		 *  Arrrrgh, HTTP 0/1 compatibility problem, maybe.
		 */
		if (bytes <= 0) {
		    /*
		     *	Don't have any data, so let the calling
		     *	function decide what to do about it. - FM
		     */
		    rv = -2;
		    goto finished;
		} else {
#ifdef UNIX
		   /*
		    *  Treat what we've received already as the complete
		    *  transmission, but not without giving the user
		    *  an alert.  I don't know about all the different
		    *  TCP stacks for VMS etc., so this is currently
		    *  only for UNIX. - kw
		    */
		   HTInetStatus("NETREAD");
		   HTAlert("Unexpected server disconnect.");
		   CTRACE((tfp,
	    "HTCopy: Unexpected server disconnect. Treating as completed.\n"));
		   status = 0;
		   break;
#else  /* !UNIX */
		   /*
		    *  Treat what we've gotten already
		    *  as the complete transmission. - FM
		    */
		   CTRACE((tfp,
	    "HTCopy: Unexpected server disconnect.  Treating as completed.\n"));
		   status = 0;
		   break;
#endif /* UNIX */
		}
#ifdef UNIX
	    } else {		/* status < 0 and other errno */
		/*
		 *  Treat what we've received already as the complete
		 *  transmission, but not without giving the user
		 *  an alert.  I don't know about all the different
		 *  TCP stacks for VMS etc., so this is currently
		 *  only for UNIX. - kw
		 */
		HTInetStatus("NETREAD");
		HTAlert("Unexpected read error.");
		if (bytes) {
		    (void)NETCLOSE(file_number);
		    rv = HT_LOADED;
		} else {
		    (*targetClass._abort)(sink, NULL);
		    rv = -1;
		}
		goto finished;
#endif
	    }
	    break;
	}

	/*
	 *  Suppress ReadProgress messages when collecting a redirection
	 *  message, at least initially (unless/until anchor->content_type
	 *  gets changed, probably by the MIME message parser).  That way
	 *  messages put up by the HTTP module or elsewhere can linger in
	 *  the statusline for a while. - kw
	 */
	suppress_readprogress = (anchor && anchor->content_type &&
				 !strcmp(anchor->content_type,
					 "message/x-http-redirection"));
#ifdef NOT_ASCII
	{
	    char * p;
	    for (p = input_buffer; p < input_buffer+status; p++) {
		*p = FROMASCII(*p);
	    }
	}
#endif /* NOT_ASCII */

	(*targetClass.put_block)(sink, input_buffer, status);
	bytes += status;
	if (!suppress_readprogress)
	    HTReadProgress(bytes, anchor ? anchor->content_length : 0);
	HTDisplayPartial();

    } /* next bufferload */

    _HTProgress(TRANSFER_COMPLETE);
    (void)NETCLOSE(file_number);
    rv = HT_LOADED;

finished:
    HTFinishDisplayPartial();
    return(rv);
}
Exemplo n.º 8
0
void HTFWriter_free( HTStream *me )
{
  int len;
  char *path = 0;
  char *addr = 0;
  int status;
  BOOLEAN use_zread = 0;
  BOOLEAN found = 0;
  if ( me->fp )
    fflush( &me->fp );
  if ( me->end_command )
  {
    LYCloseTempFP( &me->fp );
    if ( me->input_format == HTAtom_for( "www/compressed" ) )
    {
      if ( me->anchor->FileCache )
      {
        BOOLEAN skip_loadfile = me->viewer_command != 0;
        HTSACopy( &path, &me->anchor->FileCache );
        len = strlen( path );
        if ( len > 3 && ( strcasecomp( &path[ len + -2 ], "gz" ) == 0 || strcasecomp( &path[ len + -2 ], "zz" ) == 0 ) )
        {
          if ( skip_loadfile == 0 )
            use_zread = 1;
          else
          {
            path[ len + -3 ] = 0;
            remove( path );
          }
        }
        else
        if ( len > 4 && strcasecomp( &path[ len + -3 ], "bz2" ) == 0 )
        {
          path[ len + -4 ] = 0;
          remove( path );
        }
        else
        if ( len > 2 && strcasecomp( &path[ len + -1 ], "Z" ) == 0 )
        {
          path[ len + -2 ] = 0;
          remove( path );
        }
        if ( use_zread == 0 )
        {
          if ( dump_output_immediately == 0 )
          {
            mustshow = 1;
            HTProgress( &me->end_command );
          }
          if ( me->end_command && me->end_command[0] )
            LYSystem( &me->end_command );
          found = LYCanReadFile( &me->anchor->FileCache );
        }
        if ( found )
        {
          if ( dump_output_immediately == 0 )
          {
            lynx_force_repaint( );
            LYrefresh( );
          }
          HTAlert( gettext( "Error uncompressing temporary file!" ) );
          LYRemoveTemp( &me->anchor->FileCache );
          if ( me->anchor->FileCache )
          {
            free( &me->anchor->FileCache );
            me->anchor->FileCache = 0;
          }
        }
        else
        {
          LYLocalFileToURL( &addr, path );
          if ( use_zread == 0 )
          {
            LYRenamedTemp( &me->anchor->FileCache, path );
            HTSACopy( &me->anchor->FileCache, path );
            HTSACopy( &me->anchor->content_encoding, "binary" );
          }
          if ( path )
          {
            free( path );
            path = 0;
          }
          if ( skip_loadfile == 0 )
          {
            if ( HTAnchor_getUCLYhndl( &me->anchor, 1 ) < 0 )
              HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, 2 );
            HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, -1 );
          }
          if ( dump_output_immediately == 0 )
          {
            LYstore_message2( gettext( "Using %s" ), addr );
          }
          if ( skip_loadfile )
          {
            if ( me->end_command )
            {
              free( &me->end_command );
              *(int*)&me->end_command = 0;
            }
            HTAddParam( &me->end_command, &me->viewer_command, 1, &me->anchor->FileCache );
            HTEndParam( &me->end_command, &me->viewer_command, 1 );
            if ( dump_output_immediately == 0 )
            {
              HTProgress( &me->end_command );
              stop_curses( );
            }
            LYSystem( &me->end_command );
            if ( me->remove_command && me->remove_command )
            {
              free( &me->remove_command );
              *(int*)&me->remove_command = 0;
            }
            if ( dump_output_immediately == 0 )
              start_curses( );
          }
          else
          {
            status = HTLoadFile( addr, &me->anchor, &me->output_format, &me->sink );
          }
          if ( dump_output_immediately && me->output_format == HTAtom_for( "www/present" ) )
          {
            if ( addr )
            {
              free( addr );
              addr = 0;
            }
            remove( &me->anchor->FileCache );
            if ( me->anchor->FileCache )
            {
              free( &me->anchor->FileCache );
              me->anchor->FileCache = 0;
            }
            if ( me->remove_command )
            {
              free( &me->remove_command );
              *(int*)&me->remove_command = 0;
            }
            if ( me->end_command )
            {
              free( &me->end_command );
              *(int*)&me->end_command = 0;
            }
            if ( me->viewer_command )
            {
              free( &me->viewer_command );
              *(int*)&me->viewer_command = 0;
            }
            if ( me == 0 )
            {
              return;
            }
            free( me );
            me = 0;
            return;
          }
        }
        if ( addr )
        {
          free( addr );
          addr = 0;
        }
      }
      if ( me->remove_command && me->remove_command )
      {
        free( &me->remove_command );
        *(int*)&me->remove_command = 0;
      }
    }
    else
    {
      if ( strcmp( &me->end_command, "SaveToFile" ) )
      {
        if ( dump_output_immediately == 0 )
        {
          mustshow = 1;
          HTProgress( &me->end_command );
          stop_curses( );
        }
        LYSystem( &me->end_command );
        if ( me->remove_command && me->remove_command )
        {
          free( &me->remove_command );
          *(int*)&me->remove_command = 0;
        }
        if ( dump_output_immediately == 0 )
          start_curses( );
      }
      else
      {
        if ( me->remove_command && me->remove_command )
        {
          free( &me->remove_command );
          *(int*)&me->remove_command = 0;
        }
        if ( dump_output_immediately == 0 )
          start_curses( );
      }
    }
    if ( me->end_command )
    {
      free( &me->end_command );
      *(int*)&me->end_command = 0;
    }
  }
  if ( me->viewer_command )
  {
    free( &me->viewer_command );
    *(int*)&me->viewer_command = 0;
  }
  if ( dump_output_immediately )
  {
    if ( me->anchor->FileCache )
      remove( &me->anchor->FileCache );
    if ( me )
    {
      free( me );
      me = 0;
    }
    if ( persistent_cookies )
      LYStoreCookies( LYCookieSaveFile );
    exit_immediately( 0 );
  }
  if ( me == 0 )
  {
    return;
  }
  free( me );
  me = 0;
  return;
}
Exemplo n.º 9
0
HTStream *HTSaveToFile( HTPresentation *pres, HTParentAnchor *anchor, HTStream *sink )
{
  int eax;
  HTStream *ret_obj;
  char fnam[256];
  char *suffix;
  char *cp;
  int c = 0;
  BOOLEAN IsBinary = 1;
  ret_obj = calloc( 1, sizeof( HTStream ) );
  if ( ret_obj == 0 )
    outofmem( "./HTFWriter.c", "HTSaveToFile" );
  ret_obj->isa->name[0] = HTFWriter.name;
  *(int*)&ret_obj->remove_command = 0;
  *(int*)&ret_obj->end_command = 0;
  ret_obj->input_format = pres->rep->next;
  ret_obj->output_format = pres->rep_out;
  ret_obj->anchor = anchor;
  ret_obj->sink = sink;
  if ( dump_output_immediately )
  {
    ret_obj->fp = stdout;
    if ( HTOutputFormat != HTAtom_for( "www/download" ) )
      return ret_obj;
  }
  else
  {
    LYCancelDownload = 0;
    if ( HTOutputFormat != HTAtom_for( "www/download" ) )
    {
      if ( traversal || ( no_download && !override_no_download && no_disk_save ) )
      {
        if ( traversal == 0 )
        {
          HTAlert( gettext( "This file cannot be displayed on this terminal." ) );
        }
        LYCancelDownload = 1;
        if ( traversal )
          LYCancelledFetch = 1;
        if ( ret_obj )
        {
          free( ret_obj );
          ret_obj = 0;
        }
        return 0;
      }
      else
      {
        cp = strchr( (char*)pres->rep_out, ';' );
        if ( cp && strstr( &cp[1], "charset" ) )
        {
          mustshow = 1;
          user_message( gettext( "%s  D)ownload, or C)ancel" ), (char*)pres->rep_out );
          while ( 1 )
          {
            switch ( c )
            {
            case -1:
              if ( keymap[0] != 47 )
              {
                c = LYgetch_single( );
              }
              break;
            default:
              if ( c & 34816 )
              {
                if ( ( c & 255 ) != 47 )
                  continue;
              }
              else
              if ( keymap[ ( c & 2047 ) + 1 ] != 47 )
                continue;
              break;
            }
            switch ( c )
            {
            case -1:
              if ( keymap[0] == 47 )
              {
                mustshow = 1;
                statusline( gettext( "Cancelling file." ) );
                LYCancelDownload = 1;
                if ( ret_obj )
                {
                  free( ret_obj );
                  ret_obj = 0;
                }
                return 0;
              }
              break;
            default:
              if ( c & 34816 )
              {
                if ( ( c & 255 ) == 47 )
                  continue;
              }
              else
              if ( keymap[ ( c & 2047 ) + 1 ] == 47 )
                continue;
              break;
            }
          }
        }
        else
        if ( pres->rep_out->next )
        {
          mustshow = 1;
          user_message( gettext( "%s  D)ownload, or C)ancel" ), (char*)pres->rep_out );
        }
        else
        {
          mustshow = 1;
          statusline( gettext( "This file cannot be displayed on this terminal:  D)ownload, or C)ancel" ) );
        }
      }
    }
    if ( LYCachedTemp( fnam, &anchor->FileCache ) & 255 )
    {
      ret_obj->fp = LYOpenTempRewrite( fnam, ".bin", "wb" );
    }
    else
    {
      if ( strcasecomp( (char*)pres->rep_out, "text/html" ) == 0 )
        suffix = ".html";
      else
      {
        if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 )
          suffix = ".txt";
        else
        {
          if ( strncasecomp( (char*)pres->rep_out, "application/", 12 ) == 0 )
            suffix = ".bin";
          else
          {
            suffix = HTFileSuffix( &pres->rep->next, &anchor->content_encoding );
            if ( suffix == 0 || suffix[0] != '.' )
              suffix = ".html";
          }
        }
      }
      ret_obj->fp = LYOpenTemp( fnam, suffix, "wb" );
    }
    if ( ret_obj->fp == 0 )
    {
      HTAlert( gettext( "Can't open output file!  Cancelling!" ) );
      if ( ret_obj )
      {
        free( ret_obj );
        ret_obj = 0;
      }
      return 0;
    }
    else
    {
      if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 || strcasecomp( (char*)pres->rep_out, "application/postscript" ) == 0 || strcasecomp( (char*)pres->rep_out, "application/x-RUNOFF-MANUAL" ) == 0 )
        IsBinary = 0;
      HTInfoMsg2( gettext( "Content-type: %s" ), (char*)pres->rep_out );
      HTSACopy( &WWW_Download_File, fnam );
      *(int*)&ret_obj->remove_command = 0;
      HTAddParam( &ret_obj->remove_command, "%s", 1, fnam );
      HTEndParam( &ret_obj->remove_command, "%s", 1 );
      HTSACopy( &ret_obj->end_command, "SaveToFile" );
      mustshow = 1;
      statusline( gettext( "Retrieving file.  - PLEASE WAIT -" ) );
      HTSACopy( &anchor->FileCache, fnam );
    }
  }
  if ( LYPrependBaseToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 )
  {
    char *temp = 0;
    if ( anchor->content_base && anchor->content_base[0] )
      HTSACopy( &temp, &anchor->content_base );
    else
    if ( anchor->content_location && anchor->content_location[0] )
      HTSACopy( &temp, &anchor->content_location );
    if ( temp )
    {
      LYRemoveBlanks( temp );
      if ( !is_url( temp ) && temp )
      {
        free( temp );
        temp = 0;
      }
    }
    fprintf( &ret_obj->fp, "&lt;!-- X-URL: %s --&gt;\n", &anchor->address );
    if ( anchor->date && anchor->date[0] )
    {
      fprintf( &ret_obj->fp, "&lt;!-- Date: %s --&gt;\n", &anchor->date );
      if ( anchor->last_modified && anchor->last_modified[0] && strcmp( &anchor->last_modified, &anchor->date ) && strcmp( &anchor->last_modified, "Thu, 01 Jan 1970 00:00:01 GMT" ) )
        fprintf( &ret_obj->fp, "&lt;!-- Last-Modified: %s --&gt;\n", &anchor->last_modified );
    }
    fprintf( &ret_obj->fp, "&lt;BASE HREF=\"%s\"&gt;\n\n", temp ? temp : &anchor->address );
    if ( temp )
    {
      free( temp );
    }
  }
  if ( LYPrependCharsetToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 )
  {
    char *temp = 0;
    if ( anchor->charset && anchor->charset[0] )
    {
      HTSACopy( &temp, &anchor->charset );
      LYRemoveBlanks( temp );
      fprintf( &ret_obj->fp, "&lt;META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\"&gt;\n\n", temp );
    }
    if ( temp )
    {
      free( temp );
    }
  }
  return ret_obj;
}
Exemplo n.º 10
0
/*	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");
    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");
    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;
}
Exemplo n.º 11
0
HTStream *HTSaveAndExecute( HTPresentation *pres, HTParentAnchor *anchor, HTStream *sink )
{
  int eax;
  char fnam[256];
  char *suffix;
  HTStream *me;
  if ( traversal )
  {
    LYCancelledFetch = 1;
    return 0;
  }
  else
  {
    if ( 999.000000000000 <= pres->quality )
    {
      if ( dump_output_immediately )
      {
        LYCancelledFetch = 1;
        return 0;
      }
      else
      if ( no_exec )
      {
        HTAlert( gettext( "Execution is disabled." ) );
      }
      else
      if ( !local_exec && ( !local_exec_on_local_files || ( !LYJumpFileURL && strncmp( &anchor->address, "file://localhost", 16 ) ) ) )
      {
        char *buf = 0;
        HTSprintf0( &buf, gettext( "Execution is not enabled for this file.  See the Options menu (use %s)." ), key_for_func( 49 ) );
        HTAlert( buf );
        if ( buf )
        {
          free( buf );
          buf = 0;
        }
      }
    }
    if ( dump_output_immediately )
    {
    }
    else
    {
      me = calloc( 1, sizeof( HTStream ) );
      if ( me == 0 )
        outofmem( "./HTFWriter.c", "HTSaveAndExecute" );
      me->isa->name[0] = HTFWriter.name;
      me->input_format = pres->rep->next;
      me->output_format = pres->rep_out;
      me->anchor = anchor;
      me->sink = sink;
      if ( LYCachedTemp( fnam, &anchor->FileCache ) & 255 )
      {
        me->fp = LYOpenTempRewrite( fnam, ".bin", "wb" );
      }
      else
      {
        if ( strcasecomp( (char*)pres->rep_out, "text/html" ) == 0 )
          suffix = ".html";
        else
        {
          if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 )
            suffix = ".txt";
          else
          {
            suffix = HTFileSuffix( &pres->rep->next, &anchor->content_encoding );
            if ( suffix == 0 || suffix[0] != '.' )
            {
              if ( strncasecomp( (char*)pres->rep_out, "application/", 12 ) == 0 )
                suffix = ".bin";
              else
                suffix = ".html";
            }
          }
        }
        me->fp = LYOpenTemp( fnam, suffix, "wb" );
      }
      if ( me->fp == 0 )
      {
        HTAlert( gettext( "Can't open temporary file!" ) );
        if ( me )
        {
          free( me );
          me = 0;
        }
        return 0;
      }
      else
      {
        HTSACopy( &me->viewer_command, &pres->command );
        me->end_command = mailcap_substitute( anchor, pres, fnam );
        *(int*)&me->remove_command = 0;
        HTAddParam( &me->remove_command, "%s", 1, fnam );
        HTEndParam( &me->remove_command, "%s", 1 );
        HTSACopy( &anchor->FileCache, fnam );
        return me;
      }
    }
  }
}
Exemplo n.º 12
0
int LYShowInfo( DocInfo *doc, DocInfo *newdoc, char *owner_address )
{
  int eax;
  int edx;
  static char tempfile[256];
  int url_type;
  FILE *fp0;
  char *Title = 0;
  char *cp;
  char *temp = 0;
  BOOLEAN LYInfoAdvanced = user_mode == 2;
  struct stat dir_info;
  static char *name;
  if ( LYReuseTempfiles )
  {
    fp0 = LYOpenTempRewrite( tempfile, ".html", "w" );
  }
  else
  {
    LYRemoveTemp( tempfile );
    fp0 = LYOpenTemp( tempfile, ".html", "w" );
  }
  if ( fp0 == 0 )
  {
    HTAlert( gettext( "Can't open temporary file!" ) );
    return -1;
  }
  else
  {
    LYLocalFileToURL( &newdoc->address, tempfile );
    if ( nlinks > 0 && links[ doc->link ] )
    {
      url_type = is_url( links[ doc->link ].lname );
      switch ( url_type )
      {
      case 26:
      case 27:
      {
        char *last_slash = strrchr( links[ doc->link ].lname, '/' );
        int next_to_last = strlen( links[ doc->link ].lname ) + -1;
        if ( next_to_last == last_slash - links[ doc->link ].lname )
          links[ doc->link ].lname[ ebp_1152 ] = 0;
      }
        break;
      }
    }
    label_columns = 9;
    WriteInternalTitle( fp0, gettext( "Information about the current document" ) );
    fprintf( fp0, "&lt;h1&gt;%s %s (%s) (&lt;a href=\"%s\"&gt;%s&lt;/a&gt;)", "Lynx", "2.8.7dev.11", LYVersionDate( ), "http://lynx.isc.org/current/", LYVersionStatus( ) );
    fwrite( "&lt;/h1&gt;\n", 1, 6, fp0 );
    if ( lynx_edit_mode && nlinks > 0 )
    {
      fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Directory that you are currently viewing" ) );
      temp = HTnameOfFile_WWW( &doc->address, 0, 1 );
      dt_String( fp0, gettext( "Name:" ), temp );
      if ( temp )
      {
        free( temp );
        temp = 0;
      }
      dt_String( fp0, gettext( "URL:" ), &doc->address );
      fwrite( "\n&lt;/dl&gt;\n", 1, 7, fp0 );
      temp = HTnameOfFile_WWW( links[ doc->link ].lname, 0, 1 );
      if ( lstat64( temp, &dir_info.st_dev ) == -1 )
      {
        if ( WWW_TraceFlag )
        {
          fprintf( TraceFP( ), "lstat(%s) failed, errno=%d\n", temp, *(int*)(__errno_location( )) );
        }
        HTAlert( gettext( "Failed to obtain status of current link!" ) );
      }
      else
      {
        char modes[80];
        label_columns = 16;
        if ( ( dir_info.st_mode & 61440 ) == 16384 )
        {
          fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Directory that you have currently selected" ) );
        }
        else
        if ( ( dir_info.st_mode & 61440 ) == 32768 )
        {
          fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "File that you have currently selected" ) );
        }
        else
        if ( ( dir_info.st_mode & 61440 ) == 40960 )
        {
          fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Symbolic link that you have currently selected" ) );
        }
        else
        {
          fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Item that you have currently selected" ) );
        }
        dt_String( fp0, gettext( "Full name:" ), temp );
        if ( ( dir_info.st_mode & 61440 ) == 40960 )
        {
          char buf[1024];
          int buf_size = readlink( temp, buf, 1023 );
          if ( buf_size != -1 )
            buf[ buf_size ] = 0;
          else
          {
            sprintf( buf, "%.*s", 1023, gettext( "Unable to follow link" ) );
          }
          dt_String( fp0, gettext( "Points to file:" ), buf );
        }
        name = HTAA_UidToName( (int)dir_info.st_uid );
        if ( name[0] )
        {
          dt_String( fp0, gettext( "Name of owner:" ), name );
        }
        name = HTAA_GidToName( (int)dir_info.st_gid );
        if ( name[0] )
        {
          dt_String( fp0, gettext( "Group name:" ), name );
        }
        if ( ( dir_info.st_mode & 61440 ) == 32768 )
        {
          dt_Number( fp0, gettext( "File size:" ), (int)( (long)(dir_info.st_size & 0xFFFFFFFF) ), gettext( "(bytes)" ) );
        }
        dt_String( fp0, gettext( "Creation date:" ), ctime( &dir_info.st_ctim.tv_sec ) );
        dt_String( fp0, gettext( "Last modified:" ), ctime( &dir_info.st_mtim.tv_sec ) );
        dt_String( fp0, gettext( "Last accessed:" ), ctime( &dir_info.st_atim.tv_sec ) );
        fwrite( "\n&lt;/dl&gt;\n", 1, 7, fp0 );
        label_columns = 9;
        fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Access Permissions" ) );
        modes[0] = 0;
        modes[1] = 0;
        modes[2] = 0;
        if ( dir_info.st_mode & 256 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 128 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 64 )
        {
          if ( ( dir_info.st_mode & 61440 ) == 16384 )
          {
            memcpy( modes[0] + strlen( modes ) );
          }
          else
          {
            memcpy( modes[0] + strlen( modes ) );
            if ( dir_info.st_mode & 2048 )
            {
              memcpy( modes[0] + strlen( modes ) );
            }
          }
        }
        dt_String( fp0, gettext( "Owner:" ), &modes[2] );
        modes[0] = 0;
        modes[1] = 0;
        modes[2] = 0;
        if ( dir_info.st_mode & 32 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 16 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 8 )
        {
          if ( ( dir_info.st_mode & 61440 ) == 16384 )
          {
            memcpy( modes[0] + strlen( modes ) );
          }
          else
          {
            memcpy( modes[0] + strlen( modes ) );
            if ( dir_info.st_mode & 1024 )
            {
              memcpy( modes[0] + strlen( modes ) );
            }
          }
        }
        dt_String( fp0, gettext( "Group:" ), &modes[2] );
        modes[0] = 0;
        modes[1] = 0;
        modes[2] = 0;
        if ( dir_info.st_mode & 4 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 2 )
        {
          memcpy( modes[0] + strlen( modes ) );
        }
        if ( dir_info.st_mode & 1 )
        {
          if ( ( dir_info.st_mode & 61440 ) == 16384 )
          {
            memcpy( modes[0] + strlen( modes ) );
          }
          else
          {
            memcpy( modes[0] + strlen( modes ) );
            if ( dir_info.st_mode & 512 )
            {
              memcpy( modes[0] + strlen( modes ) );
            }
          }
        }
        dt_String( fp0, gettext( "World:" ), &modes[2] );
        fwrite( "\n&lt;/dl&gt;\n", 1, 7, fp0 );
      }
      if ( temp )
      {
        free( temp );
        temp = 0;
      }
    }
    else
    {
      fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "File that you are currently viewing" ) );
      LYformTitle( &Title, &doc->title[0] );
      HTSprintf( &temp, "%s%s", Title, "" );
      dt_String( fp0, gettext( "Linkname:" ), temp );
      if ( temp )
      {
        free( temp );
        temp = 0;
      }
      dt_String( fp0, "URL:", &doc->address );
      if ( HTLoadedDocumentCharset( ) )
      {
        dt_String( fp0, gettext( "Charset:" ), HTLoadedDocumentCharset( ) );
      }
      else
      {
        LYUCcharset *p_in = HTAnchor_getUCInfoStage( HTMainAnchor, 1 );
        if ( p_in == 0 || p_in->MIMEname == 0 || p_in->MIMEname[0] == 0 || HTAnchor_getUCLYhndl( HTMainAnchor, 1 ) < 0 )
        {
          p_in = HTAnchor_getUCInfoStage( HTMainAnchor, 0 );
        }
        if ( p_in && p_in->MIMEname && p_in->MIMEname[0] && HTAnchor_getUCLYhndl( HTMainAnchor, 0 ) >= 0 )
        {
          HTSprintf( &temp, "%s %s", p_in->MIMEname, gettext( "(assumed)" ) );
          dt_String( fp0, gettext( "Charset:" ), &p_in->MIMEname );
          if ( temp )
          {
            free( temp );
            temp = 0;
          }
        }
      }
      cp = HText_getServer( );
      if ( cp && cp[0] )
      {
        dt_String( fp0, gettext( "Server:" ), cp );
      }
      cp = HText_getDate( );
      if ( cp && cp[0] )
      {
        dt_String( fp0, gettext( "Date:" ), cp );
      }
      cp = HText_getLastModified( );
      if ( cp && cp[0] )
      {
        dt_String( fp0, gettext( "Last Mod:" ), cp );
      }
      if ( LYInfoAdvanced )
      {
        if ( HTMainAnchor && HTMainAnchor->expires )
        {
          dt_String( fp0, gettext( "Expires:" ), &HTMainAnchor->expires );
        }
        if ( HTMainAnchor && HTMainAnchor->cache_control )
        {
          dt_String( fp0, gettext( "Cache-Control:" ), &HTMainAnchor->cache_control );
        }
        if ( HTMainAnchor && HTMainAnchor->content_length > 0 )
        {
          dt_Number( fp0, gettext( "Content-Length:" ), HTMainAnchor->content_length, gettext( "bytes" ) );
        }
        else
        {
          dt_Number( fp0, gettext( "Length:" ), HText_getNumOfBytes( ), gettext( "bytes" ) );
        }
        if ( HTMainAnchor && HTMainAnchor->content_language )
        {
          dt_String( fp0, gettext( "Language:" ), &HTMainAnchor->content_language );
        }
      }
      if ( doc->post_data )
      {
        fprintf( fp0, "&lt;dt&gt;&lt;em&gt;%s&lt;/em&gt; &lt;xmp&gt;%.*s&lt;/xmp&gt;\n", gettext( "Post Data:" ), 0, 0 );
        dt_String( fp0, gettext( "Post Content Type:" ), &doc->post_content_type );
      }
      dt_String( fp0, gettext( "Owner(s):" ), owner_address ? owner_address : gettext( "Owner(s):" ) );
      dt_Number( fp0, gettext( "size:" ), HText_getNumOfLines( ), gettext( "lines" ) );
      if ( lynx_mode != 2 )
      {
        if ( HTisDocumentSource( ) )
        {
        }
        else
        {
        }
      }
      else
      {
      }
      HTSACopy( &temp, gettext( "source" ) );
      if ( doc->safe )
      {
        HTSACat( &temp, gettext( ", safe" ) );
      }
      if ( doc->internal_link )
      {
        HTSACat( &temp, gettext( ", via internal link" ) );
      }
      if ( LYInfoAdvanced )
      {
        if ( HText_hasNoCacheSet( HTMainText ) & 255 )
        {
          HTSACat( &temp, gettext( ", no-cache" ) );
        }
        if ( HTAnchor_isISMAPScript( (int)( &HTMainAnchor->parent->parent ) ) & 255 )
        {
          HTSACat( &temp, gettext( ", ISMAP script" ) );
        }
        if ( doc->bookmark )
        {
          HTSACat( &temp, gettext( ", bookmark file" ) );
        }
      }
      dt_String( fp0, gettext( "mode:" ), temp );
      if ( temp )
      {
        free( temp );
        temp = 0;
      }
      fwrite( "\n&lt;/dl&gt;\n", 1, 7, fp0 );
      if ( nlinks > 0 )
      {
        fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;\n&lt;dl compact&gt;", gettext( "Link that you currently have selected" ) );
        dt_String( fp0, gettext( "Linkname:" ), LYGetHiliteStr( doc->link, 0 ) );
        if ( lynx_mode == 2 && links[ doc->link ].type == 1 )
        {
          if ( links[ doc->link ].l_form->submit_method )
          {
            int method = links[ doc->link ].l_form->submit_method;
            char *enctype = &links[ doc->link ].l_form->submit_enctype;
            dt_String( fp0, gettext( "Method:" ), "POST" );
            dt_String( fp0, gettext( "Enctype:" ), "application/x-www-form-urlencoded" );
          }
          if ( links[ doc->link ].l_form->submit_action )
          {
            dt_String( fp0, gettext( "Action:" ), &links[ doc->link ].l_form->submit_action );
          }
          if ( links[ doc->link ].l_form->submit_method == 0 || links[ doc->link ].l_form->submit_action == 0 )
          {
            fprintf( fp0, "&lt;dt&gt;&nbsp;%s\n", gettext( "(Form field)" ) );
          }
        }
        else
        {
          dt_String( fp0, "URL:", "" );
        }
        fwrite( "\n&lt;/dl&gt;\n", 1, 7, fp0 );
      }
      else
      {
        fprintf( fp0, "&lt;h2&gt;%s&lt;/h2&gt;", gettext( "No Links on the current page" ) );
      }
    }
    EndInternalPage( fp0 );
    LYrefresh( );
    LYCloseTemp( tempfile );
    if ( Title )
    {
      free( Title );
      Title = 0;
    }
    return 0;
  }
}
Exemplo n.º 13
0
static void send_file_to_printer(DocInfo *newdoc,
				 char *content_base,
				 char *sug_filename,
				 int printer_number)
{
    BOOLEAN FirstRecall = TRUE;
    FILE *outfile_fp;
    char *the_command = 0;
    bstring *my_file = NULL;
    char my_temp[LY_MAXPATH];
    int FnameTotal, FnameNum = -1;
    lynx_list_item_type *cur_printer;

    outfile_fp = LYOpenTemp(my_temp,
			    (HTisDocumentSource())
			    ? HTML_SUFFIX
			    : TEXT_SUFFIX,
			    "w");
    if (outfile_fp == NULL) {
	CannotPrint(FILE_ALLOC_FAILED);
    }

    if (LYPrependBaseToSource && HTisDocumentSource()) {
	/*
	 * Added the document's base as a BASE tag to the top of the file.  May
	 * create technically invalid HTML, but will help get any partial or
	 * relative URLs resolved properly if no BASE tag is present to replace
	 * it.  - FM
	 */
	fprintf(outfile_fp,
		"<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",
		newdoc->address, content_base);
    }
    print_wwwfile_to_fd(outfile_fp, FALSE, FALSE);	/* PRINTER */
    if (keypad_mode)
	printlist(outfile_fp, FALSE);

    LYCloseTempFP(outfile_fp);

    /* find the right printer number */
    {
	int count = 0;

	for (cur_printer = printers;
	     count < printer_number;
	     count++, cur_printer = cur_printer->next) ;	/* null body */
    }

    /*
     * Commands have the form "command %s [%s] [etc]" where %s is the filename
     * and the second optional %s is the suggested filename.
     */
    if (cur_printer->command == NULL) {
	CannotPrint(PRINTER_MISCONF_ERROR);
    }

    /*
     * Check for two '%s' and ask for the second filename argument if there
     * is.
     */
    BStrCopy0(my_file, "");
    if (HTCountCommandArgs(cur_printer->command) >= 2) {
	_statusline(FILENAME_PROMPT);
      again:
	SetupFilename(&my_file, sug_filename);
      check_again:
	switch (RecallFilename(&my_file, &FirstRecall, &FnameNum,
			       &FnameTotal, PRINT_FLAG)) {
	case FN_INIT:
	    goto again;
	case FN_READ:
	    goto check_again;
	case FN_QUIT:
	    goto done;
	default:
	    break;
	}

	if (no_dotfiles || !show_dotfiles) {
	    if (*LYPathLeaf(my_file->str) == '.') {
		HTAlert(FILENAME_CANNOT_BE_DOT);
		_statusline(NEW_FILENAME_PROMPT);
		FirstRecall = TRUE;
		FnameNum = FnameTotal;
		goto again;
	    }
	}
	/*
	 * Cancel if the user entered "/dev/null" on Unix, or an "nl:" path
	 * on VMS.  - FM
	 */
	if (LYIsNullDevice(my_file->str)) {
	    CancelPrint(PRINT_REQUEST_CANCELLED);
	}
	HTAddSugFilename(my_file->str);
    }
#ifdef SH_EX			/* 1999/01/04 (Mon) 09:37:03 */
    HTAddParam(&the_command, cur_printer->command, 1, my_temp);
    if (!isBEmpty(my_file)) {
	HTAddParam(&the_command, cur_printer->command, 2, my_file->str);
	HTEndParam(&the_command, cur_printer->command, 3);
    } else {
	HTEndParam(&the_command, cur_printer->command, 2);
    }
#else
    HTAddParam(&the_command, cur_printer->command, 1, my_temp);
    HTAddParam(&the_command, cur_printer->command, 2, my_file->str);
    HTEndParam(&the_command, cur_printer->command, 2);
#endif

    /*
     * Move the cursor to the top of the screen so that output from system'd
     * commands don't scroll up the screen.
     */
    LYmove(1, 1);

    stop_curses();
    CTRACE((tfp, "command: %s\n", the_command));
    SetOutputMode(O_TEXT);
    printf(PRINTING_FILE);
    /*
     * Set various bits of document information as environment variables, for
     * use by external print scripts/etc.  On UNIX, We assume there are values,
     * and leave NULL value checking up to the external PRINTER:  cmd/script -
     * KED
     */
    SET_ENVIRON(LYNX_PRINT_TITLE, HText_getTitle(), "No Title");
    SET_ENVIRON(LYNX_PRINT_URL, newdoc->address, "No URL");
    SET_ENVIRON(LYNX_PRINT_DATE, HText_getDate(), "No Date");
    SET_ENVIRON(LYNX_PRINT_LASTMOD, HText_getLastModified(), "No LastMod");

    LYSystem(the_command);
    FREE(the_command);
    (void) LYRemoveTemp(my_temp);

    /*
     * Remove the various LYNX_PRINT_xxxx logicals.  - KED
     * [could use unsetenv(), but it's not portable]
     */
    SET_ENVIRON(LYNX_PRINT_TITLE, "", "");
    SET_ENVIRON(LYNX_PRINT_URL, "", "");
    SET_ENVIRON(LYNX_PRINT_DATE, "", "");
    SET_ENVIRON(LYNX_PRINT_LASTMOD, "", "");

    fflush(stdout);
#ifndef VMS
    signal(SIGINT, cleanup_sig);
#endif /* !VMS */
#ifdef SH_EX
    fprintf(stdout, gettext(" Print job complete.\n"));
    fflush(stdout);
#endif
    SetOutputMode(O_BINARY);
    LYSleepMsg();
    start_curses();

  done:			/* send_file_to_printer() */
    BStrFree(my_file);
    return;
}
Exemplo n.º 14
0
static void send_file_to_file(DocInfo *newdoc,
			      char *content_base,
			      char *sug_filename)
{
    BOOLEAN FirstRecall = TRUE;
    BOOLEAN use_cte;
    const char *disp_charset;
    FILE *outfile_fp;
    bstring *buffer = NULL;
    bstring *filename = NULL;
    int FnameNum = -1;
    int FnameTotal;
    int c = 0;

    _statusline(FILENAME_PROMPT);

  retry:
    SetupFilename(&filename, sug_filename);
    if (lynx_save_space) {
	BStrCopy0(buffer, lynx_save_space);
	BStrCat(buffer, filename);
	BStrCopy(filename, buffer);
    } else {
	BStrCopy0(buffer, "");
    }

  check_recall:
    switch (RecallFilename(&filename, &FirstRecall, &FnameNum,
			   &FnameTotal, PRINT_FLAG)) {
    case FN_INIT:
	goto retry;
    case FN_READ:
	goto check_recall;
    case FN_QUIT:
	goto done;
    default:
	break;
    }

    if (!LYValidateFilename(&buffer, &filename)) {
	CancelPrint(SAVE_REQUEST_CANCELLED);
    }

    /*
     * See if it already exists.
     */
    switch (c = LYValidateOutput(buffer->str)) {
    case 'Y':
	break;
    case 'N':
	_statusline(NEW_FILENAME_PROMPT);
	FirstRecall = TRUE;
	FnameNum = FnameTotal;
	goto retry;
    default:
	goto done;
    }

    /*
     * See if we can write to it.
     */
    CTRACE((tfp, "LYPrint: filename is %s, action is `%c'\n", buffer->str, c));

#ifdef HAVE_POPEN
    if (buffer->str[0] == '|') {
	if (no_shell) {
	    HTUserMsg(SPAWNING_DISABLED);
	    FirstRecall = TRUE;
	    FnameNum = FnameTotal;
	    goto retry;
	} else if ((outfile_fp = popen(buffer->str + 1, "w")) == NULL) {
	    CTRACE((tfp, "LYPrint: errno is %d\n", errno));
	    HTAlert(CANNOT_WRITE_TO_FILE);
	    _statusline(NEW_FILENAME_PROMPT);
	    FirstRecall = TRUE;
	    FnameNum = FnameTotal;
	    goto retry;
	}
    } else
#endif
	if ((outfile_fp = (TOUPPER(c) == 'A'
			   ? LYAppendToTxtFile(buffer->str)
			   : LYNewTxtFile(buffer->str))) == NULL) {
	CTRACE((tfp, "LYPrint: errno is %d\n", errno));
	HTAlert(CANNOT_WRITE_TO_FILE);
	_statusline(NEW_FILENAME_PROMPT);
	FirstRecall = TRUE;
	FnameNum = FnameTotal;
	goto retry;
    }

    if (LYPrependBaseToSource && HTisDocumentSource()) {
	/*
	 * Added the document's base as a BASE tag to the top of the file.  May
	 * create technically invalid HTML, but will help get any partial or
	 * relative URLs resolved properly if no BASE tag is present to replace
	 * it.  - FM
	 *
	 * Add timestamp (last reload).
	 */

	fprintf(outfile_fp,
		"<!-- X-URL: %s -->\n", newdoc->address);
	if (HText_getDate() != NULL) {
	    fprintf(outfile_fp,
		    "<!-- Date: %s -->\n", HText_getDate());
	    if (HText_getLastModified() != NULL
		&& strcmp(HText_getLastModified(), HText_getDate())
		&& strcmp(HText_getLastModified(),
			  "Thu, 01 Jan 1970 00:00:01 GMT")) {
		fprintf(outfile_fp,
			"<!-- Last-Modified: %s -->\n", HText_getLastModified());
	    }
	}

	fprintf(outfile_fp,
		"<BASE HREF=\"%s\">\n", content_base);
    }

    if (LYPrependCharsetToSource && HTisDocumentSource()) {
	/*
	 * Added the document's charset as a META CHARSET tag to the top of the
	 * file.  May create technically invalid HTML, but will help to resolve
	 * properly the document converted via chartrans:  printed document
	 * correspond to a display charset and we *should* override both
	 * assume_local_charset and original document's META CHARSET (if any).
	 *
	 * Currently, if several META CHARSETs are found Lynx uses the first
	 * only, and it is opposite to BASE where the original BASE in the
	 * <HEAD> overrides ones from the top.
	 *
	 * As in print-to-email we write charset only if the document has 8-bit
	 * characters, and we have no CJK or an unofficial "x-" charset.
	 */
	use_cte = HTLoadedDocumentEightbit();
	disp_charset = LYCharSet_UC[current_char_set].MIMEname;
	if (!use_cte || LYHaveCJKCharacterSet ||
	    strncasecomp(disp_charset, "x-", 2) == 0) {
	} else {
	    fprintf(outfile_fp,
		    "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\">\n\n",
		    disp_charset);
	}
    }

    print_wwwfile_to_fd(outfile_fp, FALSE, FALSE);	/* FILE */
    if (keypad_mode)
	printlist(outfile_fp, FALSE);

#ifdef HAVE_POPEN
    if (LYIsPipeCommand(buffer->str))
	pclose(outfile_fp);
    else
#endif
	LYCloseOutput(outfile_fp);

#ifdef VMS
    if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) {
	if (0 == StrNCmp((buffer->str + 9), "[]", 2)) {
	    HTAddSugFilename(buffer->str + 11);
	} else {
	    HTAddSugFilename(buffer->str + 9);
	}
    } else {
	HTAddSugFilename(buffer->str);
    }
#else
    HTAddSugFilename(buffer->str);
#endif /* VMS */

  done:
    BStrFree(buffer);
    BStrFree(filename);
    return;
}
Exemplo n.º 15
0
PUBLIC int HTLoadHTTP ARGS4 (
	char *, 		arg,
	HTParentAnchor *,	anAnchor,
	HTFormat,		format_out,
	HTStream*,		sink)
{
  int s;				/* Socket number for returned data */
  char *command;			/* The whole command */
  char *eol;			/* End of line if found */
  char *start_of_data;		/* Start of body of reply */
  int status;				/* tcp return */
  int bytes_already_read;
  char crlf[3];			/* A CR LF equivalent string */
  HTStream *target;		/* Unconverted data */
  HTFormat format_in;			/* Format arriving in the message */

  char *line_buffer;
  char *line_kept_clean;
  BOOL extensions;		/* Assume good HTTP server */
  int compressed;
  char line[2048];	/* bumped up to cover Kerb huge headers */

  int length, doing_redirect, rv;
  int already_retrying = 0;
  int return_nothing;

  int i;
  int keepingalive = 0;
  char *p;

/*SWP*/
  int statusError=0;

  if (!arg)
    {
      status = -3;
      HTProgress ("Bad request.");
      goto done;
    }
  if (!*arg)
    {
      status = -2;
      HTProgress ("Bad request.");
      goto done;
    }

  sprintf(crlf, "%c%c", CR, LF);

  /* At this point, we're talking HTTP/1.0. */
  extensions = YES;

 try_again:
  /* All initializations are moved down here from up above,
     so we can start over here... */
  eol = 0;
  bytes_already_read = 0;
  length = 0;
  doing_redirect = 0;
  compressed = 0;
  target = NULL;
  line_buffer = NULL;
  line_kept_clean = NULL;
  return_nothing = 0;

	/* okay... addr looks like http://hagbard.ncsa.uiuc.edu/blah/etc.html
	lets crop it at the 3rd '/' */
	for(p = arg,i=0;*p && i!=3;p++)
		if(*p=='/') i++;

	if(i==3)
		i = p-arg; /* i = length not counting last '/' */
	else
		i = 0;

	if((lsocket != -1) && i && addr && !strncmp(addr,arg,i)){
		/* keepalive is active and addresses match -- try the old socket */
		s = lsocket;
		keepingalive = 1; /* flag in case of network error due to server timeout*/
		lsocket = -1; /* prevent looping on failure */
#ifndef DISABLE_TRACE
		if (www2Trace)
			fprintf (stderr,
				 "HTTP: Keep-Alive reusing '%s'\n",addr);
#endif
/*
		if (addr && *addr) {
			sprintf(tmpbuf,"Reusing socket from %s.",addr);
			HTProgress(tmpbuf);
		}
*/
	} else {
		if(addr) free(addr);
		/* save the address for next time around */
		addr = malloc(i+1);
		strncpy(addr,arg,i);
		*(addr+i)=0;

		keepingalive = 0; /* just normal opening of the socket */
		if(lsocket != -1) NETCLOSE(lsocket); /* no socket leaks here */
		lsocket = -1; /*dont assign until we know the server says okay */

#ifndef DISABLE_TRACE
		if (www2Trace)
			fprintf (stderr,
				 "HTTP: Keep-Alive saving '%s'\n",addr);
#endif
/*
		if (addr && *addr) {
			sprintf(tmpbuf,"Saving %s for possible socket reuse.",addr);
			HTProgress(tmpbuf);
		}
*/
	}

  if (!keepingalive) {
      status = HTDoConnect (arg, "HTTP", TCP_PORT, &s);
      if (status == HT_INTERRUPTED){
	  /* Interrupt cleanly. */
#ifndef DISABLE_TRACE
	  if (www2Trace)
	      fprintf (stderr,
		       "HTTP: Interrupted on connect; recovering cleanly.\n");
#endif
	  HTProgress ("Connection interrupted.");
	  /* status already == HT_INTERRUPTED */
	  goto done;
      }
      if (status < 0) {
#ifndef DISABLE_TRACE
	  if (www2Trace)
	      fprintf(stderr,
		      "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n", arg, errno);
#endif
	  HTProgress ("Unable to connect to remote host.");
	  status = HT_NO_DATA;
	  goto done;
      }
  }
  /*	Ask that node for the document,
   **	omitting the host name & anchor
   */
  {
    char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
    command = malloc(5 + strlen(p1)+ 2 + 31);

    if (do_post && !do_put)
      strcpy(command, "POST ");
    else if (do_post && do_put)
      strcpy(command, "PUT ");
    else if (do_head)
      strcpy(command, "HEAD ");
    else if (do_meta)
      strcpy(command, "META ");
    else
      strcpy(command, "GET ");

    /*
     * For a gateway, the beginning '/' on the request must
     * be stripped before appending to the gateway address.
     */
    if ((using_gateway)||(using_proxy)) {
        strcat(command, p1+1);
    }
    else
        strcat(command, p1);
    free(p1);
  }
  if (extensions)
    {
      strcat(command, " ");
      strcat(command, HTTP_VERSION);
    }

  strcat(command, crlf);	/* CR LF, as in rfc 977 */

  if (extensions)
    {
#ifdef SAM_NOT_YET
		/* SAM This produces an absolutely huge Accept: line.  While
		   there is probably a better way to turn this off, just
		   compiling it out works for now.
		*/
      int n, i;

      if (!HTPresentations) HTFormatInit();
      n = HTList_count(HTPresentations);

      begin_ptr=command+strlen(command);
      env_length=0;

      sprintf(line, "Accept:");
      env_length+=strlen(line);
      StrAllocCat(command, line);

	/* KCMS Accept Header - swp */
	if (KCMS_Return_Format==JPEG) {
		sprintf(line," image/x-pcd-jpeg,");
		StrAllocCat(command, line);
		env_length+=strlen(line);
	}
	else if (KCMS_Return_Format==JYCC) {
		sprintf(line," image/x-pcd-jycc,");
		StrAllocCat(command, line);
		env_length+=strlen(line);
	}
	else if (KCMS_Return_Format==GIF) {
		sprintf(line," image/x-pcd-gif,");
		StrAllocCat(command, line);
		env_length+=strlen(line);
	}

      for(i=0; i<n; i++)
        {
          HTPresentation * pres = HTList_objectAt(HTPresentations, i);
          if (pres->rep_out == WWW_PRESENT)
            {
		sprintf(line, " %s,",HTAtom_name(pres->rep));
		env_length+=strlen(line);
		StrAllocCat(command, line);
		if (env_length>200) {
			if ((tmp_ptr=strrchr(command,','))!=NULL) {
				*tmp_ptr='\0';
			}
			sprintf(line, "%c%c",CR,LF);
			StrAllocCat(command, line);

			begin_ptr=command+strlen(command);
			sprintf(line, "Accept:");
			env_length=strlen(line);
			StrAllocCat(command, line);
		}
            }
        }

      /* This gets rid of the last comma. */
      if ((tmp_ptr=strrchr(command,','))!=NULL) {
	*tmp_ptr='\0';
	sprintf(line, "%c%c",CR,LF);
	StrAllocCat(command, line);
      }
      else { /* No accept stuff...get rid of "Accept:" */
	begin_ptr='\0';
      }
#endif

      /* if reloading, send no-cache pragma to proxy servers. --swp */
      /* original patch from Ari L. <*****@*****.**> */
      if (reloading) {
	sprintf(line, "Pragma: no-cache%c%c", CR, LF);
	StrAllocCat(command, line);
      }

      /*This is just used for "not" sending this header on a proxy request*/
      if (useKeepAlive) {
	sprintf(line, "Connection: keep-alive%c%c", CR, LF);
	StrAllocCat(command, line);
      }

      if (sendAgent) {
	sprintf(line, "User-Agent: %s%c%c",agent[selectedAgent],CR,LF);
/*
	sprintf(line, "User-Agent:  %s/%s  libwww/%s%c%c",
		HTAppName ? HTAppName : "unknown",
		HTAppVersion ? HTAppVersion : "0.0",
		HTLibraryVersion, CR, LF);
*/
	StrAllocCat(command, line);
      }

      if (sendReferer) {
	/* HTTP Referer field, specifies back-link URL   - amb */
	if (HTReferer) {
		sprintf(line, "Referer: %s%c%c", HTReferer, CR, LF);
		StrAllocCat(command, line);
		HTReferer = NULL;
	}
      }

      {
	char *tmp,*startPtr,*endPtr;

	/* addr is always in URL form */

	if (addr && !using_proxy && !using_gateway) {
		tmp=strdup(addr);
		startPtr=strchr(tmp,'/');
		if (startPtr) {
			startPtr+=2; /*now at begining of hostname*/
			if (*startPtr) {
				endPtr=strchr(startPtr,':');
				if (!endPtr) {
					endPtr=strchr(startPtr,'/');
					if (endPtr && *endPtr) {
						*endPtr='\0';
					}
				}
				else {
					*endPtr='\0';
				}

				sprintf(line, "Host: %s%c%c", startPtr, CR, LF);
				StrAllocCat(command, line);

				free(tmp);
				tmp=startPtr=endPtr=NULL;
			}
		}
	}
	else if (using_proxy || using_gateway) {
		sprintf(line, "Host: %s%c%c", proxy_host_fix, CR, LF);
		StrAllocCat(command, line);
	}
      }

      /* SWP -- 7/10/95 */
      /* HTTP Extension headers */
      /* Domain Restriction */
      sprintf(line,"Extension: Notify-Domain-Restriction%c%c",CR,LF);
      StrAllocCat(command,line);

      /* BJS -- 12/05/95 -- allow arbitrary headers sent from browser */
      if(extra_headers){
		int h;
		for(h=0;extra_headers[h];h++){
			sprintf(line,"%s%c%c",extra_headers[h],CR,LF);
			StrAllocCat(command,line);
		}
      }

      {
        char *docname;
        char *hostname;
        char *colon;
        int portnumber;
        char *auth;

        docname = HTParse(arg, "", PARSE_PATH);
        hostname = HTParse(arg, "", PARSE_HOST);
        if (hostname &&
            NULL != (colon = strchr(hostname, ':')))
          {
            *(colon++) = '\0';	/* Chop off port number */
            portnumber = atoi(colon);
          }
        else portnumber = 80;

        if (NULL!=(auth=HTAA_composeAuth(hostname, portnumber, docname)))
          {
            sprintf(line, "%s%c%c", auth, CR, LF);
            StrAllocCat(command, line);
          }
#ifndef DISABLE_TRACE
        if (www2Trace)
          {
            if (auth)
              fprintf(stderr, "HTTP: Sending authorization: %s\n", auth);
            else
              fprintf(stderr, "HTTP: Not sending authorization (yet)\n");
          }
#endif
        FREE(hostname);
        FREE(docname);
      }
    }

  if (do_post && !do_put)
    {
#ifndef DISABLE_TRACE
      if (www2Trace)
        fprintf (stderr, "HTTP: Doing post, content-type '%s'\n",
                 post_content_type);
#endif
      sprintf (line, "Content-type: %s%c%c",
               post_content_type ? post_content_type : "lose", CR, LF);
      StrAllocCat(command, line);
      {
        int content_length;
        if (!post_data)
          content_length = 4; /* 4 == "lose" :-) */
        else
          content_length = strlen (post_data);
        sprintf (line, "Content-length: %d%c%c",
                 content_length, CR, LF);
        StrAllocCat(command, line);
      }

      StrAllocCat(command, crlf);	/* Blank line means "end" */

      if (post_data)
        StrAllocCat(command, post_data);
      else
        StrAllocCat(command, "lose");
    }
  else if (do_post && do_put)
    {
      sprintf (line, "Content-length: %d%c%c",
	       put_file_size, CR, LF);
      StrAllocCat(command, line);
      StrAllocCat(command, crlf);	/* Blank line means "end" */
    }
  else {
      StrAllocCat(command, crlf);	/* Blank line means "end" */
  }

#ifndef DISABLE_TRACE
  if (www2Trace)
    fprintf (stderr, "Writing:\n%s----------------------------------\n",
             command);
#endif

/*
  HTProgress ("Sending HTTP request.");
*/

  status = NETWRITE(s, command, (int)strlen(command));
  if (do_post && do_put) {
      char buf[BUFSIZ];
      int upcnt=0,n;

      while (status>0) {
	n=fread(buf,1,BUFSIZ-1,put_fp);

	upcnt+= status = NETWRITE(s, buf, n);
#ifndef DISABLE_TRACE
	if (www2Trace) {
		fprintf(stderr,"[%d](%d) %s",status,n,buf);
	}
#endif
	if (feof(put_fp)) {
		break;
	}
      }

      if (status<0 || !feof(put_fp) || upcnt!=put_file_size) {
	char tmpbuf[BUFSIZ];

	sprintf(tmpbuf,"Status: %d  --  EOF: %d  --  UpCnt/FileSize: %d/%d\n\nThe server you connected to either does not support\nthe PUT method, or an error occurred.\n\nYour upload was corrupted! Please try again!",status,(feof(put_fp)?1:0),upcnt,put_file_size);
	application_error(tmpbuf,"Upload Error!");
      }
  }

  /* Twirl on each request to make things look nicer -- SWP */
  HTCheckActiveIcon(1);

#ifndef DISABLE_TRACE
  if (httpTrace) {
	fprintf(stderr,"%s",command);
  }
#endif

  free (command);
  if (status <= 0)
    {
      if (status == 0)
        {
#ifndef DISABLE_TRACE
          if (www2Trace)
            fprintf (stderr, "HTTP: Got status 0 in initial write\n");
#endif
          /* Do nothing. */
        }
      else if
        ((errno == ENOTCONN || errno == ECONNRESET || errno == EPIPE) &&
         !already_retrying &&
         /* Don't retry if we're posting. */ !do_post)
          {
            /* Arrrrgh, HTTP 0/1 compability problem, maybe. */
#ifndef DISABLE_TRACE
            if (www2Trace)
              fprintf
                (stderr,
                 "HTTP: BONZO ON WRITE Trying again with HTTP0 request.\n");
#endif
/*
            HTProgress ("Retrying as HTTP0 request.");
*/
            NETCLOSE(s);
// SAM            extensions = NO;
            already_retrying = 1;
            goto try_again;
          }
      else
        {
		if(keepingalive){
#ifndef DISABLE_TRACE
			if (www2Trace)
				fprintf (stderr, "HTTP: Timeout on Keep-Alive. Retrying.\n");
#endif
			HTProgress("Server Timeout: Reconnecting");
			goto try_again;
		}
#ifndef DISABLE_TRACE
          if (www2Trace)
            fprintf (stderr, "HTTP: Hit unexpected network WRITE error; aborting connection.\n");
#endif
          NETCLOSE (s);
          status = -1;
          HTProgress ("Unexpected network write error; connection aborted.");
          goto done;
        }
    }

#ifndef DISABLE_TRACE
  if (www2Trace)
    fprintf (stderr, "HTTP: WRITE delivered OK\n");
#endif
  HTProgress ("Done sending HTTP request; waiting for response.");

  /*	Read the first line of the response
   **	-----------------------------------
   */

  {
      /* Get numeric status etc */
      BOOL end_of_file = NO;
      int buffer_length = INIT_LINE_SIZE;

      line_buffer = (char *) malloc(buffer_length * sizeof(char));

      do {
	  /* Loop to read in the first line */
	  /* Extend line buffer if necessary for those crazy WAIS URLs ;-) */
	  if (buffer_length - length < LINE_EXTEND_THRESH) {
	      buffer_length = buffer_length + buffer_length;
	      line_buffer =
		  (char *) realloc(line_buffer, buffer_length * sizeof(char));
          }
#ifndef DISABLE_TRACE
	  if (www2Trace)
	      fprintf (stderr, "HTTP: Trying to read %d\n",
		       buffer_length - length - 1);
#endif
	  status = NETREAD(s, line_buffer + length,
			   buffer_length - length - 1);
#ifndef DISABLE_TRACE
	  if (www2Trace)
	      fprintf (stderr, "HTTP: Read %d\n", status);
#endif
	  if (status <= 0) {
	      /* Retry if we get nothing back too;
		 bomb out if we get nothing twice. */
	      if (status == HT_INTERRUPTED) {
#ifndef DISABLE_TRACE
		  if (www2Trace)
		      fprintf (stderr, "HTTP: Interrupted initial read.\n");
#endif
		  HTProgress ("Connection interrupted.");
		  status = HT_INTERRUPTED;
		  NETCLOSE (s);
		  goto clean_up;
              } else
		  if
		  (status < 0 &&
		   (errno == ENOTCONN || errno == ECONNRESET || errno == EPIPE)
		   && !already_retrying && !do_post)
		      {
			  /* Arrrrgh, HTTP 0/1 compability problem, maybe. */
#ifndef DISABLE_TRACE
			  if (www2Trace)
			      fprintf (stderr, "HTTP: BONZO Trying again with HTTP0 request.\n");
#endif
			  NETCLOSE(s);
			  if (line_buffer)
			      free(line_buffer);
			  if (line_kept_clean)
			      free(line_kept_clean);

			  extensions = NO;
			  already_retrying = 1;
			  HTProgress ("Retrying as HTTP0 request.");
			  goto try_again;
		      } else {
			      if(keepingalive){
#ifndef DISABLE_TRACE
					if (www2Trace)
						fprintf (stderr, "HTTP: Timeout on Keep-Alive. Retrying.\n");
#endif
					HTProgress("Server Timeout: Reconnecting");
					goto try_again;
			      }
#ifndef DISABLE_TRACE
			  if (www2Trace)
			      fprintf (stderr, "HTTP: Hit unexpected network read error; aborting connection; status %d.\n", status);
#endif
			  HTProgress
			      ("Unexpected network read error; connection aborted.");

			  NETCLOSE (s);
			  status = -1;
			  goto clean_up;
		      }
          }

	  bytes_already_read += status;
	  {
	      char line[256];
	      sprintf (line, "Read %d bytes of data.", bytes_already_read);
	      HTProgress (line);
	  }

	  if (status == 0) {
	      end_of_file = YES;
	      break;
          }
	  line_buffer[length+status] = 0;

	  if (line_buffer) {
	      if (line_kept_clean)
		  free (line_kept_clean);
	      line_kept_clean = (char *)malloc (buffer_length * sizeof (char));
/*
	      bcopy (line_buffer, line_kept_clean, buffer_length);
*/
	      memcpy (line_kept_clean, line_buffer, buffer_length);
          }

	  eol = strchr(line_buffer + length, LF);
	  /* Do we *really* want to do this? */
	  if (eol && eol != line_buffer && *(eol-1) == CR)
	      *(eol-1) = ' ';

	  length = length + status;

	  /* Do we really want to do *this*? */
	  if (eol)
	      *eol = 0;		/* Terminate the line */
      /* All we need is the first line of the response.  If it's a HTTP/1.0
	 response, then the first line will be absurdly short and therefore
	 we can safely gate the number of bytes read through this code
	 (as opposed to below) to ~1000. */
      /* Well, let's try 100. */
      } while (!eol && !end_of_file && bytes_already_read < 100);
  } /* Scope of loop variables */


  /*	We now have a terminated unfolded line. Parse it.
   **	-------------------------------------------------
   */
#ifndef DISABLE_TRACE
  if (www2Trace)
    fprintf(stderr, "HTTP: Rx: %s\n", line_buffer);
#endif

  {
    int fields;
    char server_version[VERSION_LENGTH+1];
    int server_status;

	/*SWP*/
	statusError=0;

    server_version[0] = 0;

    fields = sscanf(line_buffer, "%20s %d",
                    server_version,
                    &server_status);

#ifndef DISABLE_TRACE
    if (www2Trace)
      fprintf (stderr, "HTTP: Scanned %d fields from line_buffer\n", fields);
#endif
#ifndef DISABLE_TRACE
    if (www2Trace)
      fprintf (stderr, "HTTP: line_buffer '%s'\n", line_buffer);
#endif

    /* Rule out HTTP/1.0 reply as best we can. */
    if (fields < 2 || !server_version[0] || server_version[0] != 'H' ||
        server_version[1] != 'T' || server_version[2] != 'T' ||
        server_version[3] != 'P' || server_version[4] != '/' ||
        server_version[6] != '.')
      {
        /* HTTP0 reply */
        HTAtom * encoding;

#ifndef DISABLE_TRACE
        if (www2Trace)
          fprintf (stderr, "--- Talking HTTP0.\n");
#endif

        format_in = HTFileFormat(arg, &encoding, WWW_HTML, &compressed);
        start_of_data = line_kept_clean;
      }
    else
      {
        /* Decode full HTTP response */
        format_in = HTAtom_for("www/mime");
        /* We set start_of_data to "" when !eol here because there
           will be a put_block done below; we do *not* use the value
           of start_of_data (as a pointer) in the computation of
           length or anything else in this situation. */
        start_of_data = eol ? eol + 1 : "";
        length = eol ? length - (start_of_data - line_buffer) : 0;

#ifndef DISABLE_TRACE
        if (www2Trace)
          fprintf (stderr, "--- Talking HTTP1.\n");
#endif

        switch (server_status / 100)
          {
          case 3:		/* Various forms of redirection */
            /* We now support this in the parser, at least. */
            doing_redirect = 1;
            break;

          case 4:		/* "I think I goofed" */
            switch (server_status)
              {
              case 403:
		statusError=1;
                /* 403 is "forbidden"; display returned text. */
                break;

              case 401:
                /* length -= start_of_data - text_buffer; */
                if (HTAA_shouldRetryWithAuth(start_of_data, length, s))
                  {
                    (void)NETCLOSE(s);
			lsocket = -1;
                    if (line_buffer)
                      free(line_buffer);
                    if (line_kept_clean)
                      free(line_kept_clean);

#ifndef DISABLE_TRACE
                    if (www2Trace)
                      fprintf(stderr, "%s %d %s\n",
                              "HTTP: close socket", s,
                              "to retry with Access Authorization");
#endif

                    HTProgress ("Retrying with access authorization information.");
                    goto try_again;
                    break;
                  }
                else
                  {
		    statusError=1;
                    /* Fall through. */
                  }

              default:
		statusError=1;
                break;
              } /* case 4 switch */
            break;

          case 5:		/* I think you goofed */
	    statusError=1;
            break;

          case 2:		/* Good: Got MIME object */
            switch (server_status)
              {
              case 204:
                return_nothing = 1;
                format_in = HTAtom_for("text/html");
                break;
	      case 200:
		if (do_head) {
			if (!start_of_data || !*start_of_data) {
				headData=NULL;
			}
			else {
				char *ptr;

				headData=strdup(start_of_data);
				ptr=strchr(headData,'\n');
				*ptr='\0';
			}
		}
		break;
              default:
                break;
              }
            break;

          default:		/* bad number */
	    statusError=1;
            HTAlert("Unknown status reply from server!");
            break;
          } /* Switch on server_status/100 */

      }	/* Full HTTP reply */
  } /* scope of fields */

  /* Set up the stream stack to handle the body of the message */
  target = HTStreamStack(format_in,
                         format_out,
                         compressed,
                         sink, anAnchor);

  if (!target)
    {
      char buffer[1024];	/* @@@@@@@@ */
      sprintf(buffer, "Sorry, no known way of converting %s to %s.",
              HTAtom_name(format_in), HTAtom_name(format_out));
      HTProgress (buffer);
      status = -1;
      NETCLOSE (s);
	lsocket = -1;
      goto clean_up;
    }

  if (!return_nothing)
    {
#ifndef DISABLE_TRACE
      if (www2Trace)
        fprintf (stderr, "HTTP: Doing put_block, '%s'\n", start_of_data);
#endif
/* BJS: parse start_of_data...*/
	for(p=start_of_data;*p;p++){
/*		if(*p=='C' && !strncmp("Content-length: ",p,16)){
		i = 0;
		p+=16;
		while(*p && isdigit(*p)){
			i = i*10 + *p-'0';
			p++;
		}
		p--;
#ifndef DISABLE_TRACE
		if(www2Trace)
			fprintf(stderr, "HTTP: Content Length is %d\n",i);
#endif
	}
*/
		if(*p=='K' && !strncmp("Keep-Alive:",p,11)){
#ifndef DISABLE_TRACE
			if (www2Trace)
				fprintf (stderr, "HTTP: Server Agrees to Keep-Alive\n");
#endif
			lsocket = s;
			p+=10;
		}
	}

#ifndef DISABLE_TRACE
        if (www2Trace && lsocket == -1)
		fprintf (stderr, "HTTP: Server does not agree to Keep-Alive\n");
#endif
      /* Recycle the first chunk of data, in all cases. */
      (*target->isa->put_block)(target, start_of_data, length);

      /* Go pull the bulk of the data down. */
	/* if we dont use length, header length is wrong due to the
	    discarded first line - bjs*/
      rv = HTCopy(s, target, length /*bytes_already_read*/);
      if (rv == -1)
        {
          (*target->isa->handle_interrupt) (target);
          status = HT_INTERRUPTED;
	  NETCLOSE (s);
		lsocket = -1;
          goto clean_up;
        }
      if (rv == -2 && !already_retrying && !do_post)
        {
          /* Aw hell. */
#ifndef DISABLE_TRACE
          if (www2Trace)
            fprintf (stderr, "HTTP: Trying again with HTTP0 request.\n");
#endif
          /* May as well consider it an interrupt -- right? */
          (*target->isa->handle_interrupt) (target);
          NETCLOSE(s);
          if (line_buffer)
            free(line_buffer);
          if (line_kept_clean)
            free(line_kept_clean);

          extensions = NO;
          already_retrying = 1;
          HTProgress ("Retrying as HTTP0 request.");
          goto try_again;
        }
    }
  else
    {
      /* return_nothing is high. */
      (*target->isa->put_string) (target, "<mosaic-access-override>\n");
      HTProgress ("And silence filled the night.");
    }

  (*target->isa->end_document)(target);

  /* Close socket before doing free. */
	if(lsocket == -1){
		NETCLOSE(s);
#ifndef DISABLE_TRACE
		if(www2Trace)
			fprintf(stderr,"HTTP: Closing connection\n");
#endif
	} else {
		HTProgress("Leaving Server Connection Open");
#ifndef DISABLE_TRACE
		if(www2Trace)
			fprintf(stderr,"HTTP: Keeping connection alive\n");
#endif
	}
/*
  else {
      NETCLOSE(s);
#ifndef DISABLE_TRACE
      if(www2Trace)
	fprintf(stderr,"HTTP: Closing connection\n");
#endif
  }
*/

  (*target->isa->free)(target);

  if (doing_redirect)
    {
      /* OK, now we've got the redirection URL temporarily stored
         in external variable redirecting_url, exported from HTMIME.c,
         since there's no straightforward way to do this in the library
         currently.  Do the right thing. */
      status = HT_REDIRECTING;
    }
  else
    {
      status = HT_LOADED;
    }

  /*	Clean up
   */

 clean_up:
  if (line_buffer)
    free(line_buffer);
  if (line_kept_clean)
    free(line_kept_clean);

 done:
  /* Clear out on exit, just in case. */
  do_post = 0;

  if (statusError) {
	securityType=HTAA_NONE;
#ifndef DISABLE_TRACE
	if (www2Trace)
		fprintf(stderr,"Resetting security type to NONE.\n");
#endif
  }

  return status;
}
Exemplo n.º 16
0
static int LYLoadCGI(const char *arg,
		     HTParentAnchor *anAnchor,
		     HTFormat format_out,
		     HTStream *sink)
{
    int status = 0;

#ifdef LYNXCGI_LINKS
#ifndef VMS
    char *cp;
    struct stat stat_buf;
    char *pgm = NULL;		/* executable */
    char *pgm_args = NULL;	/* and its argument(s) */
    int statrv;
    char *orig_pgm = NULL;	/* Path up to ? as given, URL-escaped */
    char *document_root = NULL;	/* Corrected value of DOCUMENT_ROOT  */
    char *path_info = NULL;	/* PATH_INFO extracted from pgm      */
    char *pgm_buff = NULL;	/* PATH_INFO extraction buffer       */
    char *path_translated;	/* From document_root/path_info      */

    if (isEmpty(arg) || strlen(arg) <= 8) {
	HTAlert(BAD_REQUEST);
	status = -2;
	return (status);

    } else {
	if (StrNCmp(arg, "lynxcgi://localhost", 19) == 0) {
	    StrAllocCopy(pgm, arg + 19);
	} else {
	    StrAllocCopy(pgm, arg + 8);
	}
	if ((cp = StrChr(pgm, '?')) != NULL) {	/* Need to terminate executable */
	    *cp++ = '\0';
	    pgm_args = cp;
	}
    }

    StrAllocCopy(orig_pgm, pgm);
    if (trimPoundSelector(pgm) != NULL) {
	/*
	 * Strip a #fragment from path.  In this case any pgm_args found above
	 * will also be bogus, since the '?' came after the '#' and is part of
	 * the fragment.  Note that we don't handle the case where a '#'
	 * appears after a '?' properly according to URL rules.  - kw
	 */
	pgm_args = NULL;
    }
    HTUnEscape(pgm);

    /* BEGIN WebSter Mods */
    /* If pgm is not stat-able, see if PATH_INFO data is at the end of pgm */
    if ((statrv = stat(pgm, &stat_buf)) < 0) {
	StrAllocCopy(pgm_buff, pgm);
	while (statrv < 0 || (statrv = stat(pgm_buff, &stat_buf)) < 0) {
	    if ((cp = strrchr(pgm_buff, '/')) != NULL) {
		*cp = '\0';
		statrv = 1;	/* force new stat()  - kw */
	    } else {
		PERROR("strrchr(pgm_buff, '/') returned NULL");
		break;
	    }
	}

	if (statrv < 0) {
	    /* Did not find PATH_INFO data */
	    PERROR("stat() of pgm_buff failed");
	} else {
	    /* Found PATH_INFO data.  Strip it off of pgm and into path_info. */
	    StrAllocCopy(path_info, pgm + strlen(pgm_buff));
	    /* The following is safe since pgm_buff was derived from pgm
	       by stripping stuff off its end and by HTUnEscaping, so we
	       know we have enough memory allocated for pgm.  Note that
	       pgm_args may still point into that memory, so we cannot
	       reallocate pgm here. - kw */
	    strcpy(pgm, pgm_buff);
	    CTRACE((tfp,
		    "LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n",
		    pgm_buff, path_info));
	}
	FREE(pgm_buff);
    }
    /* END WebSter Mods */

    if (statrv != 0) {
	/*
	 * Neither the path as given nor any components examined by backing up
	 * were stat()able.  - kw
	 */
	HTAlert(gettext("Unable to access cgi script"));
	PERROR("stat() failed");
	status = -4;

    } else
#ifdef _WINDOWS			/* 1998/01/14 (Wed) 09:16:04 */
#define isExecutable(mode) (mode & (S_IXUSR))
#else
#define isExecutable(mode) (mode & (S_IXUSR|S_IXGRP|S_IXOTH))
#endif
    if (!(S_ISREG(stat_buf.st_mode) && isExecutable(stat_buf.st_mode))) {
	/*
	 * Not a runnable file, See if we can load it using "file:" code.
	 */
	char *new_arg = NULL;

	/*
	 * But try "file:" only if the file we are looking at is the path as
	 * given (no path_info was extracted), otherwise it will be to
	 * confusing to know just what file is loaded.  - kw
	 */
	if (path_info) {
	    CTRACE((tfp,
		    "%s is not a file and %s not an executable, giving up.\n",
		    orig_pgm, pgm));
	    FREE(path_info);
	    FREE(pgm);
	    FREE(orig_pgm);
	    status = -4;
	    return (status);
	}

	LYLocalFileToURL(&new_arg, orig_pgm);

	CTRACE((tfp, "%s is not an executable file, passing the buck.\n", arg));
	status = HTLoadFile(new_arg, anAnchor, format_out, sink);
	FREE(new_arg);

    } else if (path_info &&
	       anAnchor != HTMainAnchor &&
	       !(reloading && anAnchor->document) &&
	       strcmp(arg, HTLoadedDocumentURL()) &&
	       HText_AreDifferent(anAnchor, arg) &&
	       HTUnEscape(orig_pgm) &&
	       !can_exec_cgi(orig_pgm, "")) {
	/*
	 * If we have extra path info and are not just reloading the current,
	 * check the full file path (after unescaping) now to catch forbidden
	 * segments.  - kw
	 */
	status = HT_NOT_LOADED;

    } else if (no_lynxcgi) {
	HTUserMsg(CGI_DISABLED);
	status = HT_NOT_LOADED;

    } else if (no_bookmark_exec &&
	       anAnchor != HTMainAnchor &&
	       !(reloading && anAnchor->document) &&
	       strcmp(arg, HTLoadedDocumentURL()) &&
	       HText_AreDifferent(anAnchor, arg) &&
	       HTLoadedDocumentBookmark()) {
	/*
	 * If we are reloading a lynxcgi document that had already been loaded,
	 * the various checks above should allow it even if no_bookmark_exec is
	 * TRUE an we are not now coming from a bookmark page.  - kw
	 */
	HTUserMsg(BOOKMARK_EXEC_DISABLED);
	status = HT_NOT_LOADED;

    } else if (anAnchor != HTMainAnchor &&
	       !(reloading && anAnchor->document) &&
	       strcmp(arg, HTLoadedDocumentURL()) &&
	       HText_AreDifferent(anAnchor, arg) &&
	       !can_exec_cgi(pgm, pgm_args)) {
	/*
	 * If we are reloading a lynxcgi document that had already been loaded,
	 * the various checks above should allow it even if exec_ok() would
	 * reject it because we are not now coming from a document with a URL
	 * allowed by TRUSTED_LYNXCGI rules.  - kw
	 */
	status = HT_NOT_LOADED;

    } else {
	HTFormat format_in;
	HTStream *target = NULL;	/* Unconverted data */
	int fd1[2], fd2[2];
	char buf[MAX_LINE];
	int pid;

#ifdef HAVE_TYPE_UNIONWAIT
	union wait wstatus;

#else
	int wstatus;
#endif

	fd1[0] = -1;
	fd1[1] = -1;
	fd2[0] = -1;
	fd2[1] = -1;

	if (anAnchor->isHEAD || keep_mime_headers) {

	    /* Show output as plain text */
	    format_in = WWW_PLAINTEXT;
	} else {

	    /* Decode full HTTP response */
	    format_in = HTAtom_for("www/mime");
	}

	target = HTStreamStack(format_in,
			       format_out,
			       sink, anAnchor);

	if (!target || target == NULL) {
	    char *tmp = 0;

	    HTSprintf0(&tmp, CANNOT_CONVERT_I_TO_O,
		       HTAtom_name(format_in),
		       HTAtom_name(format_out));
	    HTAlert(tmp);
	    FREE(tmp);
	    status = HT_NOT_LOADED;

	} else if (anAnchor->post_data && pipe(fd1) < 0) {
	    HTAlert(CONNECT_SET_FAILED);
	    PERROR("pipe() failed");
	    status = -3;

	} else if (pipe(fd2) < 0) {
	    HTAlert(CONNECT_SET_FAILED);
	    PERROR("pipe() failed");
	    close(fd1[0]);
	    close(fd1[1]);
	    status = -3;

	} else {
	    static BOOL first_time = TRUE;	/* One time setup flag */

	    if (first_time) {	/* Set up static environment variables */
		first_time = FALSE;	/* Only once */

		add_environment_value("REMOTE_HOST=localhost");
		add_environment_value("REMOTE_ADDR=127.0.0.1");

		HTSprintf0(&user_agent, "HTTP_USER_AGENT=%s/%s libwww/%s",
			   LYNX_NAME, LYNX_VERSION, HTLibraryVersion);
		add_environment_value(user_agent);

		HTSprintf0(&server_software, "SERVER_SOFTWARE=%s/%s",
			   LYNX_NAME, LYNX_VERSION);
		add_environment_value(server_software);
	    }
	    fflush(stdout);
	    fflush(stderr);
	    CTRACE_FLUSH(tfp);

	    if ((pid = fork()) > 0) {	/* The good, */
		ssize_t chars;
		off_t total_chars;

		close(fd2[1]);

		if (anAnchor->post_data) {
		    ssize_t written;
		    int remaining, total_written = 0;

		    close(fd1[0]);

		    /* We have form data to push across the pipe */
		    if (TRACE) {
			CTRACE((tfp,
				"LYNXCGI: Doing post, content-type '%s'\n",
				anAnchor->post_content_type));
			CTRACE((tfp, "LYNXCGI: Writing:\n"));
			trace_bstring(anAnchor->post_data);
			CTRACE((tfp, "----------------------------------\n"));
		    }
		    remaining = BStrLen(anAnchor->post_data);
		    while ((written = write(fd1[1],
					    BStrData(anAnchor->post_data) + total_written,
					    (size_t) remaining)) != 0) {
			if (written < 0) {
#ifdef EINTR
			    if (errno == EINTR)
				continue;
#endif /* EINTR */
#ifdef ERESTARTSYS
			    if (errno == ERESTARTSYS)
				continue;
#endif /* ERESTARTSYS */
			    PERROR("write() of POST data failed");
			    break;
			}
			CTRACE((tfp, "LYNXCGI: Wrote %d bytes of POST data.\n",
				(int) written));
			total_written += (int) written;
			remaining -= (int) written;
			if (remaining == 0)
			    break;
		    }
		    if (remaining != 0) {
			CTRACE((tfp, "LYNXCGI: %d bytes remain unwritten!\n",
				remaining));
		    }
		    close(fd1[1]);
		}

		HTReadProgress(total_chars = 0, (off_t) 0);
		while ((chars = read(fd2[0], buf, sizeof(buf))) != 0) {
		    if (chars < 0) {
#ifdef EINTR
			if (errno == EINTR)
			    continue;
#endif /* EINTR */
#ifdef ERESTARTSYS
			if (errno == ERESTARTSYS)
			    continue;
#endif /* ERESTARTSYS */
			PERROR("read() of CGI output failed");
			break;
		    }
		    total_chars += (int) chars;
		    HTReadProgress(total_chars, (off_t) 0);
		    CTRACE((tfp, "LYNXCGI: Rx: %.*s\n", (int) chars, buf));
		    (*target->isa->put_block) (target, buf, (int) chars);
		}

		if (chars < 0 && total_chars == 0) {
		    status = HT_NOT_LOADED;
		    (*target->isa->_abort) (target, NULL);
		    target = NULL;
		} else if (chars != 0) {
		    status = HT_PARTIAL_CONTENT;
		} else {
		    status = HT_LOADED;
		}

#ifndef HAVE_WAITPID
		while (wait(&wstatus) != pid) ;		/* do nothing */
#else
		while (-1 == waitpid(pid, &wstatus, 0)) {	/* wait for child */
#ifdef EINTR
		    if (errno == EINTR)
			continue;
#endif /* EINTR */
#ifdef ERESTARTSYS
		    if (errno == ERESTARTSYS)
			continue;
#endif /* ERESTARTSYS */
		    break;
		}
#endif /* !HAVE_WAITPID */
		close(fd2[0]);

	    } else if (pid == 0) {	/* The Bad, */
		char **argv = NULL;
		int argv_cnt = 3;	/* name, one arg and terminator */
		char **cur_argv = NULL;
		int exec_errno;

		/* Set up output pipe */
		close(fd2[0]);
		dup2(fd2[1], fileno(stdout));	/* Should check success code */
		dup2(fd2[1], fileno(stderr));
		close(fd2[1]);

		if (non_empty(language)) {
		    HTSprintf0(&accept_language, "HTTP_ACCEPT_LANGUAGE=%s", language);
		    add_environment_value(accept_language);
		}

		if (non_empty(pref_charset)) {
		    cp = NULL;
		    StrAllocCopy(cp, "HTTP_ACCEPT_CHARSET=");
		    StrAllocCat(cp, pref_charset);
		    add_environment_value(cp);
		}

		if (anAnchor->post_data &&
		    anAnchor->post_content_type) {
		    cp = NULL;
		    StrAllocCopy(cp, "CONTENT_TYPE=");
		    StrAllocCat(cp, anAnchor->post_content_type);
		    add_environment_value(cp);
		}

		if (anAnchor->post_data) {	/* post script, read stdin */
		    close(fd1[1]);
		    dup2(fd1[0], fileno(stdin));
		    close(fd1[0]);

		    /* Build environment variables */

		    add_environment_value("REQUEST_METHOD=POST");

		    HTSprintf0(&post_len, "CONTENT_LENGTH=%d",
			       BStrLen(anAnchor->post_data));
		    add_environment_value(post_len);
		} else {
		    close(fileno(stdin));

		    if (anAnchor->isHEAD) {
			add_environment_value("REQUEST_METHOD=HEAD");
		    }
		}

		/*
		 * Set up argument line, mainly for <index> scripts
		 */
		if (pgm_args != NULL) {
		    for (cp = pgm_args; *cp != '\0'; cp++) {
			if (*cp == '+') {
			    argv_cnt++;
			}
		    }
		}

		argv = (char **) malloc((unsigned) argv_cnt * sizeof(char *));

		if (argv == NULL) {
		    outofmem(__FILE__, "LYCgi");
		}
		assert(argv != NULL);

		cur_argv = argv + 1;	/* For argv[0] */
		if (pgm_args != NULL) {
		    char *cr;

		    /* Data for a get/search form */
		    if (is_www_index) {
			add_environment_value("REQUEST_METHOD=SEARCH");
		    } else if (!anAnchor->isHEAD && !anAnchor->post_data) {
			add_environment_value("REQUEST_METHOD=GET");
		    }

		    cp = NULL;
		    StrAllocCopy(cp, "QUERY_STRING=");
		    StrAllocCat(cp, pgm_args);
		    add_environment_value(cp);

		    /*
		     * Split up arguments into argv array
		     */
		    cp = pgm_args;
		    cr = cp;
		    while (1) {
			if (*cp == '\0') {
			    *(cur_argv++) = HTUnEscape(cr);
			    break;

			} else if (*cp == '+') {
			    *cp++ = '\0';
			    *(cur_argv++) = HTUnEscape(cr);
			    cr = cp;
			}
			cp++;
		    }
		} else if (!anAnchor->isHEAD && !anAnchor->post_data) {
		    add_environment_value("REQUEST_METHOD=GET");
		}
		*cur_argv = NULL;	/* Terminate argv */
		argv[0] = pgm;

		/* Begin WebSter Mods  -jkt */
		if (LYCgiDocumentRoot != NULL) {
		    /* Add DOCUMENT_ROOT to env */
		    cp = NULL;
		    StrAllocCopy(cp, "DOCUMENT_ROOT=");
		    StrAllocCat(cp, LYCgiDocumentRoot);
		    add_environment_value(cp);
		}
		if (path_info != NULL) {
		    /* Add PATH_INFO to env */
		    cp = NULL;
		    StrAllocCopy(cp, "PATH_INFO=");
		    StrAllocCat(cp, path_info);
		    add_environment_value(cp);
		}
		if (LYCgiDocumentRoot != NULL && path_info != NULL) {
		    /* Construct and add PATH_TRANSLATED to env */
		    StrAllocCopy(document_root, LYCgiDocumentRoot);
		    LYTrimHtmlSep(document_root);
		    path_translated = document_root;
		    StrAllocCat(path_translated, path_info);
		    cp = NULL;
		    StrAllocCopy(cp, "PATH_TRANSLATED=");
		    StrAllocCat(cp, path_translated);
		    add_environment_value(cp);
		    FREE(path_translated);
		}
		/* End WebSter Mods  -jkt */

		execve(argv[0], argv, env);
		exec_errno = errno;
		PERROR("execve failed");
		printf("Content-Type: text/plain\r\n\r\n");
		if (!anAnchor->isHEAD) {
		    printf("exec of %s failed", pgm);
		    printf(": %s.\r\n", LYStrerror(exec_errno));
		}
		fflush(stdout);
		fflush(stderr);
		_exit(1);

	    } else {		/* and the Ugly */
		HTAlert(CONNECT_FAILED);
		PERROR("fork() failed");
		close(fd1[0]);
		close(fd1[1]);
		close(fd2[0]);
		close(fd2[1]);
		status = -1;
	    }

	}
	if (target != NULL) {
	    (*target->isa->_free) (target);
	}
    }
    FREE(path_info);
    FREE(pgm);
    FREE(orig_pgm);
#else /* VMS */
    HTStream *target;
    char *buf = 0;

    target = HTStreamStack(WWW_HTML,
			   format_out,
			   sink, anAnchor);

    HTSprintf0(&buf, "<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n",
	       gettext("Good Advice"));
    PUTS(buf);

    HTSprintf0(&buf, "<h1>%s</h1>\n", gettext("Good Advice"));
    PUTS(buf);

    HTSprintf0(&buf, "%s <a\n",
	       gettext("An excellent http server for VMS is available via"));
    PUTS(buf);

    HTSprintf0(&buf,
	       "href=\"http://www.ecr6.ohio-state.edu/www/doc/serverinfo.html\"\n");
    PUTS(buf);

    HTSprintf0(&buf, ">%s</a>.\n", gettext("this link"));
    PUTS(buf);

    HTSprintf0(&buf, "<p>%s\n",
	       gettext("It provides state of the art CGI script support.\n"));
    PUTS(buf);

    HTSprintf0(&buf, "</body>\n</html>\n");
    PUTS(buf);

    (*target->isa->_free) (target);
    FREE(buf);
    status = HT_LOADED;
#endif /* VMS */
#else /* LYNXCGI_LINKS */
    HTUserMsg(CGI_NOT_COMPILED);
    status = HT_NOT_LOADED;
#endif /* LYNXCGI_LINKS */

    (void) arg;
    (void) anAnchor;
    (void) format_out;
    (void) sink;

    return (status);
}