static void format(char **result, char *fmt, char *parm) { *result = NULL; HTAddParam(result, fmt, 1, parm); HTEndParam(result, fmt, 1); }
PRIVATE void format ARGS3( char **, result, char *, fmt, char *, parm) { *result = NULL; HTAddParam(result, fmt, 1, parm); HTEndParam(result, fmt, 1); }
void LYDownload(char *line) { char *Line = NULL, *method, *file, *sug_file = NULL; int method_number; int count; char *the_command = 0; bstring *buffer = NULL; bstring *command = NULL; char *cp; lynx_list_item_type *download_command = 0; int ch; RecallType recall; int FnameTotal; int FnameNum; BOOLEAN FirstRecall = TRUE; BOOLEAN SecondS = FALSE; #ifdef VMS LYDidRename = FALSE; #endif /* VMS */ /* * Make sure we have a valid download file comparison string loaded via the * download options menu. - FM */ if (LYValidDownloadFile[0] == '\0') { goto failed; } /* * Make a copy of the LYNXDOWNLOAD internal URL for parsing. - FM */ StrAllocCopy(Line, line); /* * Parse out the File, sug_file, and the Method. */ if ((file = strstr(Line, "/File=")) == NULL) goto failed; *file = '\0'; /* * Go past "File=". */ file += 6; if ((sug_file = strstr(file + 1, "/SugFile=")) != NULL) { *sug_file = '\0'; /* * Go past "SugFile=". */ sug_file += 9; HTUnEscape(sug_file); } /* * Make sure that the file string is the one from the last displayed * download options menu. - FM */ if (strcmp(file, LYValidDownloadFile)) { goto failed; } #if defined(DIRED_SUPPORT) /* FIXME: use HTLocalName */ if (!StrNCmp(file, "file://localhost", 16)) { #ifdef __DJGPP__ if (!StrNCmp(file + 16, "/dev/", 5)) file += 16; else { file += 17; file = HTDOS_name(file); } #else file += 16; #endif /* __DJGPP__ */ } else if (isFILE_URL(file)) file += LEN_FILE_URL; HTUnEscape(file); #else #if defined(_WINDOWS) /* 1997/10/15 (Wed) 16:27:38 */ if (!StrNCmp(file, "file://localhost/", 17)) file += 17; else if (!StrNCmp(file, "file:/", 6)) file += 6; HTUnEscape(file); #endif /* _WINDOWS */ #endif /* DIRED_SUPPORT */ if ((method = strstr(Line, "Method=")) == NULL) goto failed; /* * Go past "Method=". */ method += 7; method_number = atoi(method); /* * Set up the sug_filenames recall buffer. */ FnameTotal = (sug_filenames ? HTList_count(sug_filenames) : 0); recall = ((FnameTotal >= 1) ? RECALL_URL : NORECALL); FnameNum = FnameTotal; if (method_number < 0) { /* * Write to local file. */ _statusline(FILENAME_PROMPT); retry: if (sug_file) { BStrCopy0(buffer, sug_file); } else { BStrCopy0(buffer, ""); } check_recall: if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 || isBEmpty(buffer) || ch == UPARROW_KEY || ch == DNARROW_KEY) { if (recall && ch == UPARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the last Fname in the list. - FM */ FnameNum = 0; } else { /* * Go back to the previous Fname in the list. - FM */ FnameNum++; } if (FnameNum >= FnameTotal) { /* * Reset the FirstRecall flag, and use sug_file or a blank. * - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto retry; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_recall; } } else if (recall && ch == DNARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the first Fname in the list. - FM */ FnameNum = FnameTotal - 1; } else { /* * Advance to the next Fname in the list. - FM */ FnameNum--; } if (FnameNum < 0) { /* * Set the FirstRecall flag, and use sug_file or a blank. * - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto retry; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_recall; } } /* * Save cancelled. */ goto cancelled; } BStrCopy(command, buffer); if (!LYValidateFilename(&buffer, &command)) goto cancelled; #ifdef HAVE_POPEN else if (LYIsPipeCommand(buffer->str)) { /* I don't know how to download to a pipe */ HTAlert(CANNOT_WRITE_TO_FILE); _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; } #endif /* * See if it already exists. */ switch (LYValidateOutput(buffer->str)) { case 'Y': break; case 'N': _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; default: goto cleanup; } /* * See if we can write to it. */ CTRACE((tfp, "LYDownload: filename is %s\n", buffer->str)); SecondS = TRUE; HTInfoMsg(SAVING); #ifdef VMS /* * Try rename() first. - FM */ CTRACE((tfp, "command: rename(%s, %s)\n", file, buffer->str)); if (rename(file, buffer->str)) { /* * Failed. Use spawned COPY_COMMAND. - FM */ CTRACE((tfp, " FAILED!\n")); LYCopyFile(file, buffer->str); } else { /* * We don't have the temporary file (it was renamed to a permanent * file), so set a flag to pop out of the download menu. - FM */ LYDidRename = TRUE; } chmod(buffer->str, HIDE_CHMOD); #else /* Unix: */ LYCopyFile(file, buffer->str); LYRelaxFilePermissions(buffer->str); #endif /* VMS */ } else { /* * Use configured download commands. */ BStrCopy0(buffer, ""); for (count = 0, download_command = downloaders; count < method_number; count++, download_command = download_command->next) ; /* null body */ /* * Commands have the form "command %s [etc]" where %s is the filename. */ if (download_command->command != NULL) { /* * Check for two '%s' and ask for the local filename if there is. */ if (HTCountCommandArgs(download_command->command) >= 2) { _statusline(FILENAME_PROMPT); again: if (sug_file) { BStrCopy0(buffer, sug_file); } else { BStrCopy0(buffer, ""); } check_again: if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 || isBEmpty(buffer) || ch == UPARROW_KEY || ch == DNARROW_KEY) { if (recall && ch == UPARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the last Fname in the list. - FM */ FnameNum = 0; } else { /* * Go back to the previous Fname in the list. - FM */ FnameNum++; } if (FnameNum >= FnameTotal) { /* * Reset the FirstRecall flag, and use sug_file or * a blank. - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto again; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_again; } } else if (recall && ch == DNARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the first Fname in the list. - FM */ FnameNum = FnameTotal - 1; } else { /* * Advance to the next Fname in the list. - FM */ FnameNum--; } if (FnameNum < 0) { /* * Set the FirstRecall flag, and use sug_file or a * blank. - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto again; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_again; } } /* * Download cancelled. */ goto cancelled; } if (no_dotfiles || !show_dotfiles) { if (*LYPathLeaf(buffer->str) == '.') { HTAlert(FILENAME_CANNOT_BE_DOT); _statusline(NEW_FILENAME_PROMPT); goto again; } } /* * Cancel if the user entered "/dev/null" on Unix, or an "nl:" * path on VMS. - FM */ if (LYIsNullDevice(buffer->str)) { goto cancelled; } SecondS = TRUE; } /* * The following is considered a bug by the community. If the * command only takes one argument on the command line, then the * suggested file name is not used. It actually is not a bug at * all and does as it should, putting both names on the command * line. */ count = 1; HTAddParam(&the_command, download_command->command, count, file); if (HTCountCommandArgs(download_command->command) > 1) HTAddParam(&the_command, download_command->command, ++count, buffer->str); HTEndParam(&the_command, download_command->command, count); } else { HTAlert(MISCONF_DOWNLOAD_COMMAND); goto failed; } CTRACE((tfp, "command: %s\n", the_command)); stop_curses(); LYSystem(the_command); FREE(the_command); start_curses(); /* don't remove(file); */ } if (SecondS == TRUE) { #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 */ } goto cleanup; failed: HTAlert(CANNOT_DOWNLOAD_FILE); goto cleanup; cancelled: HTInfoMsg(CANCELLING); cleanup: FREE(Line); BStrFree(buffer); return; }
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." ) ); }
PUBLIC void edit_temporary_file ARGS3( char *, filename, char *, position, char *, message) { #ifdef UNIX struct stat stat_info; #endif char *format = "%s %s"; char *command = NULL; char *editor_arg = ""; int params = 1; int rv; if (strstr(editor, "pico")) { editor_arg = " -t"; /* No prompt for filename to use */ } if (editor_can_position() && *position) { #ifdef VMS format = "%s %s -%s%s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, filename); HTAddParam(&command, format, params++, position); HTAddParam(&command, format, params++, editor_arg); HTEndParam(&command, format, params); #else format = "%s +%s%s %s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, position); HTAddParam(&command, format, params++, editor_arg); HTAddParam(&command, format, params++, filename); HTEndParam(&command, format, params); #endif } #ifdef DOSPATH else if (strncmp(editor, "VZ", 2)==0) { /* for Vz editor */ format = "%s %s -%s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, HTDOS_short_name(filename)); HTAddParam(&command, format, params++, position); HTEndParam(&command, format, params); } else if (strncmp(editor, "edit", 4)==0) { /* for standard editor */ HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, HTDOS_short_name(filename)); HTEndParam(&command, format, params); } #endif else { #ifdef _WINDOWS if (strchr(editor, ' ')) HTAddXpand(&command, format, params++, HTDOS_short_name(editor)); else HTAddXpand(&command, format, params++, editor); #else HTAddXpand(&command, format, params++, editor); #endif HTAddParam(&command, format, params++, filename); HTEndParam(&command, format, params); } if (message != NULL) { _statusline(message); } CTRACE((tfp, "LYEdit: %s\n", command)); CTRACE_SLEEP(MessageSecs); stop_curses(); #ifdef UNIX set_errno(0); #endif if ((rv = LYSystem(command)) != 0) { /* Spawn Editor */ start_curses(); /* * If something went wrong, we should probably return soon; * currently we don't, but at least put out a message. - kw */ { #ifdef UNIX CTRACE((tfp, "ExtEditForm: system() returned %d (0x%x), %s\n", rv, rv, errno ? LYStrerror(errno) : "reason unknown")); LYFixCursesOn("show error warning:"); if (rv == -1) { HTUserMsg2(gettext("Error starting editor, %s"), LYStrerror(errno)); } else if (WIFSIGNALED(rv)) { HTAlwaysAlert(NULL, gettext("Editor killed by signal")); } else if (WIFEXITED(rv) && WEXITSTATUS(rv) != 127) { HTUserMsg2(gettext("Editor returned with exit code %d"), WEXITSTATUS(rv)); } else #endif HTAlwaysAlert(NULL, ERROR_SPAWNING_EDITOR); } } else { start_curses(); } #ifdef UNIX /* * Delete backup file, if that's your style. */ HTSprintf0 (&command, "%s~", filename); if (stat (command, &stat_info) == 0) remove (command); #endif FREE(command); }
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; } } } }
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, "<!-- X-URL: %s -->\n", &anchor->address ); if ( anchor->date && anchor->date[0] ) { fprintf( &ret_obj->fp, "<!-- Date: %s -->\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, "<!-- Last-Modified: %s -->\n", &anchor->last_modified ); } fprintf( &ret_obj->fp, "<BASE HREF=\"%s\">\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, "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\">\n\n", temp ); } if ( temp ) { free( temp ); } } return ret_obj; }
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; }
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; } } } }
int remote_session( char *acc_method, char *host ) { char *program; char *user = host; char *password = 0; char *cp; char *hostname; char *port; char *command = 0; enum _login_protocol login_protocol = rlogin; cp = host; for ( ; cp[0]; cp++ ) { if ( !( *(short*)(*(int*)(__ctype_b_loc( )) + ( cp[0] * 2 )) & 8 ) && cp[0] != '_' && cp[0] != '-' && cp[0] != ':' && cp[0] != '.' && cp[0] != '@' ) { cp[0] = 0; break; } else { // cp++; } } hostname = strchr( host, '@' ); if ( hostname ) { hostname[0] = 0; hostname++; } else { hostname = host; user = 0; } port = strchr( hostname, ':' ); if ( port ) { port[0] = 0; port++; } if ( hostname == 0 || hostname[0] == 0 ) { if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "HTTelnet: No host specified!\n" ); } return -204; } else { if ( ( valid_hostname( hostname ) & 255 ) == 0 ) { char *prefix = 0; char *line = 0; if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "HTTelnet: Invalid hostname %s!\n", host ); } HTSprintf0( &prefix, gettext( "remote %s session:" ), acc_method ); HTSprintf0( &line, gettext( "Invalid hostname %s" ), host ); HTAlwaysAlert( prefix, line ); if ( prefix ) { free( prefix ); prefix = 0; } if ( line ) { free( line ); line = 0; } return -204; } else { if ( user ) { password = strchr( user, ':' ); if ( password ) { password[0] = 0; password++; } } if ( HTSecure ) { puts( "\n\nSorry, but the service you have selected is one" ); puts( "to which you have to log in. If you were running www" ); puts( "on your own computer, you would be automatically connected." ); puts( "For security reasons, this is not allowed when" ); puts( "you log in to this information service remotely.\n" ); printf( "You can manually connect to this service using %s\n", acc_method ); printf( "to host %s", hostname ); if ( user ) printf( ", user name %s", user ); if ( password ) printf( ", password %s", password ); if ( port ) printf( ", port %s", port ); puts( ".\n" ); return -204; } else { if ( user && login_protocol != rlogin ) printf( "When you are connected, log in as: %s\n", user ); if ( password && login_protocol != rlogin ) printf( " The password is: %s\n", password ); fflush( stdout ); switch ( login_protocol ) { case rlogin: program = HTGetProgramPath( 11 ); if ( program == 0 ) { LYSystem( command ); return -204; } HTAddParam( &command, "%s %s%s%s", 1, program ); HTAddParam( &command, "%s %s%s%s", 2, hostname ); HTSACat( &command, "" ); HTAddParam( &command, "%s %s%s%s", 4, user ); HTEndParam( &command, "%s %s%s%s", 4 ); break; case tn3270: program = HTGetProgramPath( 17 ); if ( program == 0 ) { LYSystem( command ); return -204; } HTAddParam( &command, "%s %s %s", 1, program ); HTAddParam( &command, "%s %s %s", 2, hostname ); HTAddParam( &command, "%s %s %s", 3, port ); HTEndParam( &command, "%s %s %s", 3 ); break; case telnet: program = HTGetProgramPath( 16 ); if ( program == 0 ) { LYSystem( command ); return -204; } HTAddParam( &command, "%s %s %s", 1, program ); HTAddParam( &command, "%s %s %s", 2, hostname ); HTAddParam( &command, "%s %s %s", 3, port ); HTEndParam( &command, "%s %s %s", 3 ); break; } } } } }
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; }