Exemplo n.º 1
0
char *LYCopyValue( char *s )
{
  char *t;
  char *result = 0;
  int j, k;
  if ( s[0] == '"' )
  {
    t = LYSkipQuoted( s );
    HTSACopy( &result, &s[1] );
    result[ ( t - s ) + -2 ] = 0;
    j = k = 0;
    while ( result[ j ] != '\\' )
    {
      if ( result[ k ] == 0 )
        break;
      j++;
      k++;
    }
    j++;
  }
  else
  {
    t = LYSkipToken( s );
    HTSACopy( &result, s );
    result[ t - s ] = 0;
  }
  return result;
}
Exemplo n.º 2
0
void dt_String( FILE *fp, char *label, char *value )
{
  int have;
  int need;
  char *the_label = 0;
  char *the_value = 0;
  HTSACopy( &the_label, label );
  HTSACopy( &the_value, value );
  have = strlen( the_label );
  need = LYstrExtent( the_label, have, label_columns );
  LYEntify( &the_label, 1 );
  LYEntify( &the_value, 1 );
  fwrite( "<dt>", 1, 4, fp );
  while ( need++, ( need < label_columns ) & 255 )
  {
    fwrite( "&nbsp;", 1, 6, fp );
  }
  fprintf( fp, "&lt;em&gt;%s&lt;/em&gt; %s\n", the_label, the_value );
  if ( the_label )
  {
    free( the_label );
    the_label = 0;
  }
  if ( the_value )
  {
    free( the_value );
    the_value = 0;
  }
  return;
}
Exemplo n.º 3
0
void HTMLSRC_init_caches( BOOLEAN dont_exit )
{
    int i;
    char *p;
    char buf[1000];
    if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
    {
        fprintf( TraceFP( ), "HTMLSRC_init_caches(%d tagspecs)\n", 12 );
    }
    i = 0;
    for ( ; i <= 11; i++ )
    {
        LYstrncpy( buf, HTL_tagspecs_defaults[ i ], 999 );
        HTSACopy( &HTL_tagspecs[ i ], buf );
        if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
        {
            fprintf( TraceFP( ), "parsing lexeme %d: %s\n", i + 1, buf );
        }
        p = strchr( buf, ':' );
        if ( p )
            p = 0;
        if ( html_src_parse_tagspec( buf, i, 0, 1 ) == 0 && dont_exit == 0 )
            failed_init( "1st", i );
        if ( html_src_parse_tagspec( 0, i, 0, 0 ) == 0 && dont_exit == 0 )
            failed_init( "2nd", i );
        // i++;
    }
    return;
}
Exemplo n.º 4
0
HTStyle *HTStyleNewNamed( char *name )
{
  HTStyle *self = HTStyleNew( );
  HTSACopy( &self->name, name );
  self->id = -1;
  return self;
}
Exemplo n.º 5
0
BOOLEAN setup( char *terminal )
{
  char *term_putenv = 0;
  char *buffer = 0;
  char *cp = LYgetXDisplay( );
  if ( cp )
    HTSACopy( &x_display, cp );
  else
  if ( x_display )
  {
    free( x_display );
    x_display = 0;
  }
  if ( terminal )
  {
    HTSprintf0( &term_putenv, "TERM=%.106s", terminal );
    putenv( term_putenv );
  }
  if ( dumbterm( LYGetEnv( "TERM" ) ) )
  {
    printf( "\n\n  %s\n\n", gettext( "Your Terminal type is unknown!" ) );
    printf( "  %s [vt100] ", gettext( "Enter a terminal type:" ) );
    if ( LYSafeGets( &buffer, stdin ) )
    {
      LYTrimLeading( buffer );
      LYTrimTrailing( buffer );
    }
    if ( buffer == 0 || buffer[0] == 0 )
      HTSACopy( &buffer, "vt100" );
    HTSprintf0( &term_putenv, "TERM=%.106s", buffer );
    if ( buffer )
    {
      free( buffer );
      buffer = 0;
    }
    putenv( term_putenv );
    printf( "\n%s %s\n", gettext( "TERMINAL TYPE IS SET TO" ), LYGetEnv( "TERM" ) );
    LYSleepMsg( );
  }
  start_curses( );
  if ( strncmp( ttytype, "sun", 3 ) == 0 )
    LYnoVideo( 2 );
  LYlines = LYscreenHeight( );
  LYcols = LYscreenWidth( );
  return 1;
}
Exemplo n.º 6
0
int get_editor( char *value )
{
  if ( system_editor == 0 )
  {
    HTSACopy( &editor, value );
  }
  return 0;
}
Exemplo n.º 7
0
char *key_for_func( int func )
{
  static char *buf;
  int i = LYReverseKeymap( func );
  char *formatted;
  if ( i >= 0 )
  {
    formatted = LYKeycodeToString( i, 1 );
    HTSACopy( &buf, "?" );
  }
  else
  if ( buf == 0 )
  {
    HTSACopy( &buf, "" );
  }
  return buf;
}
Exemplo n.º 8
0
char *LYMakeMailcapCommand( char *command, char *params, char *filename )
{
  HTChunk *expanded = 0;
  char *result = 0;
  expanded = HTChunkCreate( 1024 );
  BuildCommand( expanded, command, filename, params );
  HTSACopy( &result, &expanded->data );
  HTChunkFree( expanded );
  return result;
}
Exemplo n.º 9
0
void HTAA_setIds( HTAAProt *prot, char *ids )
{
  if ( ids )
  {
    char *local_copy = 0;
    char *point;
    HTSACopy( &local_copy, ids );
    point = strchr( local_copy, '.' );
    if ( point )
    {
      point[0] = 0;
      point++;
      HTSACopy( &prot->gid_name, point );
    }
    else
      HTSACopy( &prot->gid_name, "nogroup" );
    HTSACopy( &prot->uid_name, local_copy );
    if ( local_copy == 0 )
    {
      return;
    }
    free( local_copy );
    local_copy = 0;
  }
  else
  {
    HTSACopy( &prot->uid_name, "nobody" );
    HTSACopy( &prot->gid_name, "nogroup" );
  }
  return;
}
Exemplo n.º 10
0
void append_open_tag( char *tagname, char *classname, HT_tagspec **head, HT_tagspec **tail )
{
    HT_tagspec *subj;
    HTTag *tag;
    static int hcode;
    append_close_tag( tagname, head, tail );
    subj = tail[0];
    subj->start = 1;
    tag = &tags[ subj->element ];
    hcode = hash_code_lowercase_on_fly( tagname );
    if ( classname && classname[0] )
    {
        hcode = hash_code_aggregate_char( '.', hcode );
        hcode = hash_code_aggregate_lower_str( classname, hcode );
        HTSACopy( &subj->class_name, classname );
    }
    else
    {
        HTSACopy( &subj->class_name, "" );
    }
    subj->style = hcode;
    return;
}
Exemplo n.º 11
0
int RememberTestResult( int mode, char *cmd, int result )
{
  static struct cmdlist_s *cmdlist;
  struct cmdlist_s *cur;
  switch ( mode )
  {
  case 0:
    if ( cmdlist == 0 )
    {
      return 0;
    }
    cur = &cmdlist->next;
    if ( cmdlist->cmd[0] )
    {
      free( &cmdlist->cmd[0] );
      *(int*)&cmdlist->cmd[0] = 0;
    }
    if ( cmdlist )
    {
      free( cmdlist );
      cmdlist = 0;
    }
    cmdlist = cur;
    break;
  case 1:
    cur = cmdlist;
    for ( ; cur;  )
    {
      if ( strcmp( cmd, &cur->cmd[0] ) == 0 )
      {
        return cur->result;
      }
      cur = &cur->next;
    }
    return -1;
    break;
  case 2:
    cur = calloc( 1, sizeof( struct cmdlist_s ) );
    if ( cur == 0 )
      outofmem( "./HTInit.c", "RememberTestResult" );
    cur->next = cmdlist;
    HTSACopy( &cur->cmd, cmd );
    return result;
    cmdlist = cur;
    break;
  default:
    break;
  }
}
Exemplo n.º 12
0
char *LYgetTableString( int code )
{
  int eax;
  int mask = decode_mono_code( code );
  int second = encode_color_attr( mask );
  int pair = ( second & 65280 ) >> 8;
  int mono = 0;
  int fg = lynx_color_pairs[ pair ].fg;
  int bg = lynx_color_pairs[ pair ].bg;
  unsigned int n;
  char *result = 0;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "LYgetTableString(%d)\n", code );
  }
  if ( fg == 0 && bg == 0 )
    fg = 7;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "%#x -&gt; %#x (mono %#x pair %d) fg=%d, bg=%d\n", mask, second, mono, pair, fg, bg );
  }
  n = 0;
  for ( ; n <= 6; n++ )
  {
    if ( Mono_Attrs[ n ].code & mono )
    {
      if ( result )
        HTSACat( &result, "+" );
      HTSACat( &result, Mono_Attrs[ n ].name );
    }
    // n++;
  }
  if ( result == 0 )
    HTSACopy( &result, "normal" );
  HTSACat( &result, ":" );
  HTSACat( &result, lookup_color( fg ) );
  if ( bg >= 0 )
  {
    HTSACat( &result, ":" );
    HTSACat( &result, lookup_color( bg ) );
  }
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "-&gt;%s\n", result );
  }
  return result;
}
Exemplo n.º 13
0
void save_uid_info( char *name, int user )
{
  USER_DATA *data = calloc( 1, sizeof( USER_DATA ) );
  if ( data )
  {
    if ( known_pwd == 0 )
    {
      known_pwd = HTList_new( );
      if ( uidgid_cache_inited == 0 )
        uidgid_cache_inited = 1;
    }
    HTSACopy( &data->name, name );
    data->user = user;
    HTList_addObject( known_pwd, (void*)data );
  }
  return;
}
Exemplo n.º 14
0
char *LYGetContentType( char *name, char *params )
{
  char *result = 0;
  if ( params )
  {
    if ( name == 0 )
    {
      HTSACopy( &result, params );
      *(char*)(LYSkipNonBlanks( result )) = 0;
    }
  {
    size_t length = strlen( name );
    char *test = strchr( params, ';' );
    char *next;
    do
    {
      if ( test == 0 )
        break;
    {
      BOOLEAN found = 0;
      test++;
      test = LYSkipCBlanks( test );
      next = LYSkipToken( test );
      if ( length == next - test && strncmp( test, name, length ) == 0 )
        found = 1;
      test = LYSkipCBlanks( next );
      if ( test[0] == '=' )
      {
        test++;
        test = LYSkipCBlanks( test );
        if ( found )
        {
          result = LYCopyValue( test );
          break;
        }
        test = LYSkipValue( test );
        test = LYSkipCBlanks( test );
      }
    }
    }
    while ( test[0] != ';' );
  }
  }
  return result;
}
Exemplo n.º 15
0
void setHashStyle( int style, int color, int cattr, int mono, char *element )
{
  bucket *ds = &hashStyles[ style ];
  if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
  {
    fprintf( TraceFP( ), "CSS(SET): &lt;%s&gt; hash=%d, ca=%#x, ma=%#x\n", element, style, color, mono );
  }
  ds->color = color;
  ds->cattr = cattr;
  ds->mono = mono;
  ds->code = style;
  if ( ds->name[0] )
  {
    free( &ds->name[0] );
    *(int*)&ds->name[0] = 0;
  }
  HTSACopy( &ds->name, element );
  return;
}
Exemplo n.º 16
0
char *fmt_keys( int lkc_first, int lkc_second )
{
  char *buf = 0;
  BOOLEAN quotes = 0;
  char *fmt_first;
  char *fmt_second;
  if ( lkc_first < 0 )
  {
    return 0;
  }
  fmt_first = LYKeycodeToString( lkc_first, 1 );
  if ( fmt_first && strlen( fmt_first ) == 1 && fmt_first[0] != '\'' )
    quotes = 1;
  if ( quotes )
  {
    if ( lkc_second < 0 )
    {
      HTSprintf0( &buf, "'%s'", fmt_first );
      return buf;
    }
    HTSprintf0( &buf, "'%s", fmt_first );
  }
  else
    HTSACopy( &buf, fmt_first );
  if ( lkc_second >= 0 )
  {
    fmt_second = LYKeycodeToString( lkc_second, 1 );
    if ( fmt_second == 0 )
    {
      if ( buf )
      {
        free( buf );
        buf = 0;
      }
      return 0;
    }
    else
    {
      HTSprintf( &buf, "%s%s%s", "", fmt_second, "" );
    }
  }
  return buf;
}
Exemplo n.º 17
0
HTList *LYcommandList( void )
{
  static HTList *myList;
  if ( myList == 0 )
  {
    unsigned int j;
    myList = HTList_new( );
    j = 0;
    for ( ; revmap[ j ]->name; j++ )
    {
      if ( revmap[ j ].doc )
      {
        char *data = 0;
        HTSACopy( &data, revmap[ j ].name );
        HTList_addObject( myList, (void*)data );
      }
      // j++;
    }
  }
  return myList;
}
Exemplo n.º 18
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.º 19
0
void HTAA_parseProtFile( HTAAProt *prot, FILE *fp )
{
  if ( prot && fp )
  {
    LexItem lex_item;
    char *fieldname = 0;
    do
    {
      lex_item = lex( fp );
      if ( lex_item != LEX_EOF )
      {
        for ( ; lex_item == LEX_REC_SEP;  )
        {
          lex_item = lex( fp );
        }
        if ( lex_item == LEX_EOF )
          goto B7;
        else
        {
          if ( lex_item == LEX_ALPH_STR )
          {
            HTSACopy( &fieldname, HTlex_buffer );
            lex_item = lex( fp );
            if ( lex_item != LEX_FIELD_SEP )
              unlex( lex_item );
            if ( strncasecomp( fieldname, "Auth", 4 ) == 0 )
            {
              lex_item = lex( fp );
              do
              {
                if ( lex_item == LEX_ALPH_STR )
                {
                  HTAAScheme scheme = HTAAScheme_enum( HTlex_buffer );
                  if ( scheme )
                  {
                    if ( prot->valid_schemes == 0 )
                    {
                      prot->valid_schemes = HTList_new( );
                    }
                    HTList_addObject( &prot->valid_schemes, &scheme );
                    if ( WWW_TraceFlag )
                    {
                      fprintf( TraceFP( ), "%s %s `%s'\n", "HTAA_parseProtFile: valid", "authentication scheme:", HTAAScheme_name( scheme ) );
                    }
                  }
                  else
                  if ( WWW_TraceFlag )
                  {
                    fprintf( TraceFP( ), "%s %s `%s'\n", "HTAA_parseProtFile: unknown", "authentication scheme:", HTlex_buffer );
                  }
                  lex( fp );
                  while ( lex_item = lex( fp ), lex_item == LEX_ITEM_SEP )
                  {
                    lex( fp );
                  }
                }
              }
              while ( lex_item != LEX_REC_SEP );
            }
            else
            {
              if ( strncasecomp( fieldname, "mask", 4 ) == 0 )
              {
                prot->mask_group = HTAA_parseGroupDef( fp );
                lex_item = LEX_REC_SEP;
                if ( WWW_TraceFlag )
                {
                  if ( prot->mask_group )
                  {
                    fwrite( "HTAA_parseProtFile: Mask group:\n", 1, 32, TraceFP( ) );
                    HTAA_printGroupDef( &prot->mask_group );
                  }
                  else
                  {
                    fwrite( "HTAA_parseProtFile: Mask group syntax error\n", 1, 44, TraceFP( ) );
                  }
                }
              }
              else
              {
                lex_item = lex( fp );
                if ( lex_item == LEX_ALPH_STR )
                {
                  if ( prot->values == 0 )
                  {
                    prot->values = HTAssocList_new( );
                  }
                  HTAssocList_add( &prot->values, fieldname, HTlex_buffer );
                  lex_item = lex( fp );
                  if ( WWW_TraceFlag )
                  {
                    fprintf( TraceFP( ), "%s `%s' bound to value `%s'\n", "HTAA_parseProtFile: Name", fieldname, HTlex_buffer );
                  }
                }
              }
            }
          }
          if ( lex_item != LEX_EOF && lex_item != LEX_REC_SEP )
          {
            if ( WWW_TraceFlag )
            {
              fprintf( TraceFP( ), "%s %s %d (that line ignored)\n", "HTAA_parseProtFile: Syntax error", "in protection setup file at line", HTlex_line );
            }
            do
            {
              lex_item = lex( fp );
            }
            while ( lex_item != LEX_EOF && lex_item != LEX_REC_SEP );
          }
        }
      }
B7:;
      if ( fieldname == 0 )
        break;
      free( fieldname );
      break;
    }
    while ( lex_item != LEX_REC_SEP );
  }
  return;
}
Exemplo n.º 20
0
HTAAProt *HTAAProt_new( char *cur_docname, char *prot_filename, char *ids )
{
  int eax;
  HTList *cur = prot_cache;
  HTAAProtCache *cache_item = 0;
  HTAAProt *prot;
  FILE *fp;
  if ( prot_cache == 0 )
  {
    prot_cache = HTList_new( );
    do
    {
      if ( cur )
      {
        cur = &cur->next;
        cache_item = 0;
      }
    }
    while ( cache_item && strcmp( &cache_item->prot_filename[0], prot_filename ) );
    if ( cache_item )
    {
      prot = &cache_item->prot;
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "%s `%s' already in cache\n", "HTAAProt_new: Protection file", prot_filename );
      }
    }
    else
    {
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "HTAAProt_new: Loading protection file `%s'\n", prot_filename );
      }
      prot = calloc( 1, sizeof( HTAAProt ) );
      if ( prot == 0 )
        outofmem( "../../../WWW/Library/Implementation/HTAAProt.c", "HTAAProt_new" );
      *(int*)&prot->ctemplate[0] = 0;
      *(int*)&prot->filename = 0;
      *(int*)&prot->uid_name = 0;
      *(int*)&prot->gid_name = 0;
      prot->valid_schemes = HTList_new( );
      *(int*)&prot->mask_group = 0;
      prot->values = HTAssocList_new( );
      if ( prot_filename )
      {
        fp = fopen64( prot_filename, "r" );
        if ( fp )
        {
          HTAA_parseProtFile( prot, fp );
          fclose( fp );
          cache_item = calloc( 1, sizeof( HTAAProtCache ) );
          if ( cache_item == 0 )
            outofmem( "../../../WWW/Library/Implementation/HTAAProt.c", "HTAAProt_new" );
          cache_item->prot = prot;
          *(int*)&cache_item->prot_filename[0] = 0;
          HTSACopy( &cache_item->prot_filename, prot_filename );
          HTList_addObject( prot_cache, (void*)cache_item );
        }
      }
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "HTAAProt_new: %s `%s'\n", "Unable to open protection setup file", "(null)" );
      }
    }
    if ( cur_docname )
      HTSACopy( &prot->filename, cur_docname );
    HTAA_setIds( prot, ids );
    return prot;
  }
}
Exemplo n.º 21
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.º 22
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.º 23
0
void read_rc( FILE *fp )
{
  char *buffer = 0;
  char rcfile[256];
  char MBM_line[256];
  int n;
  if ( fp == 0 )
  {
    LYAddPathToHome( rcfile, 256, ".lynxrc" );
    fp = fopen64( rcfile, "r" );
    if ( fp )
    {
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "read_rc opened %s\n", rcfile );
        while ( LYSafeGets( &buffer, fp ) == 0 )
        {
          char *name, *value, *notes;
          Config_Type *tbl;
          ParseUnion *q;
          LYTrimTrailing( buffer );
          name = LYSkipBlanks( buffer );
          if ( !( *(short*)(*(int*)(__ctype_b_loc( )) + ( name[0] * 2 )) & 4 ) && name[0] )
          {
            value = strchr( name, '=' );
            if ( value == 0 )
            {
              if ( WWW_TraceFlag )
              {
                fprintf( TraceFP( ), "LYrcFile: missing '=' %s\n", name );
              }
            }
            else
            {
              value[0] = 0;
              value++;
              LYTrimTrailing( name );
              value = LYSkipBlanks( value );
              if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
              {
                fprintf( TraceFP( ), "LYrcFile %s:%s\n", name, value );
              }
              tbl = lookup_config( name );
              if ( tbl->name[0] == 0 )
              {
                char *special = "multi_bookmark";
                if ( strncasecomp( name, special, strlen( special ) ) == 0 )
                {
                  tbl = lookup_config( special );
                }
                if ( tbl->name[0] == 0 )
                {
                  if ( WWW_TraceFlag )
                  {
                    fprintf( TraceFP( ), "LYrcFile: ignored %s=%s\n", name, value );
                  }
                }
              }
              q = &tbl->value;
              switch ( tbl->type )
              {
              case 0:
                break;
              case 2:
                if ( q->add_value[0] )
                {
                  q->override_primary_action = getBool( value );
                }
                break;
              case 3:
                if ( q->add_value[0] )
                {
                  ;
                }
                break;
              case 1:
                n = 0;
                for ( ; tbl->strings[ n ]; n++ )
                {
                  if ( strcasecomp( value, &tbl->strings[ n ] ) == 0 )
                  {
                    q->add_value = &n;
                  }
                  else
                  {
                    // n++;
                  }
                }
                break;
              case 5:
                if ( tbl->table )
                {
                  LYgetEnum( &tbl->table, value, (int*)q->add_value[0] );
                }
                break;
              case 4:
                if ( q->add_value[0] && sscanf( value, value, "%d", ival ) == 1 )
                {
                  q->add_value = &ival;
                }
                break;
              case 6:
                if ( q->add_value[0] )
                {
                  if ( q->add_value )
                    HTSACat( (int)( &q->add_value[0]->next ), "," );
                  HTSACat( (int)( &q->add_value[0]->next ), value );
                }
                break;
              case 7:
                n = 1;
                for ( ; n <= 25; n++ )
                {
                  sprintf( MBM_line, "multi_bookmark%c", LYindex2MBM( n ) );
                  if ( strcasecomp( name, MBM_line ) == 0 )
                  {
                    notes = strchr( value, ',' );
                    if ( notes )
                    {
                      notes = 0;
                      notes++;
                      LYTrimTrailing( value );
                      notes = LYSkipBlanks( notes );
                    }
                    else
                    {
                      notes = value + strlen( value );
                    }
                    HTSACopy( &MBM_A_subbookmark[ n ], value );
                    HTSACopy( &MBM_A_subdescript[ n ], notes );
                  }
                  else
                  {
                    // n++;
                  }
                }
                break;
              case 8:
                if ( q->add_value[0] )
                {
                  HTSACopy( (int)( &q->add_value[0]->next ), value );
                }
                break;
              }
            }
          }
        }
      }
    }
  }
  else
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "read_rc used passed-in stream\n" );
  }
  return;
}
Exemplo n.º 24
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.º 25
0
int ProcessMailcapEntry( FILE *fp, struct MailcapEntry *mc, AcceptMedia media )
{
  size_t rawentryalloc = 2000;
  size_t len;
  size_t need;
  char *rawentry, *s, *t;
  char *LineBuf = 0;
  rawentry = malloc( ( rawentryalloc ) * sizeof( char ) );
  if ( rawentry == 0 )
  {
    ExitWithError( gettext( "Memory exhausted!  Program aborted!" ) );
  }
  rawentry[0] = 0;
  while ( LYSafeGets( &LineBuf, fp ) == 0 )
  {
    LYTrimNewline( LineBuf );
    if ( LineBuf[0] != '#' && LineBuf[0] )
    {
      len = strlen( LineBuf );
      need = len + strlen( rawentry ) + 1;
      if ( rawentryalloc < need )
      {
        rawentryalloc = rawentryalloc + need + 2000;
        rawentry = realloc( rawentry, ( rawentryalloc ) * sizeof( char ) );
        if ( rawentry == 0 )
        {
          ExitWithError( gettext( "Memory exhausted!  Program aborted!" ) );
        }
      }
      if ( len && LineBuf[ len + -1 ] == '\\' )
      {
        LineBuf[ len + -1 ] = 0;
        strcat( rawentry, LineBuf );
      }
      else
      {
        strcat( rawentry, LineBuf );
        break;
      }
    }
  }
  if ( LineBuf )
  {
    free( LineBuf );
    LineBuf = 0;
  }
  t = s = LYSkipBlanks( rawentry );
  if ( s[0] == 0 )
  {
    if ( rawentry )
    {
      free( rawentry );
      rawentry = 0;
    }
    return 0;
  }
  else
  {
    s = strchr( rawentry, ';' );
    if ( s == 0 )
    {
      if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
      {
        fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring invalid mailcap entry: %s\n", rawentry );
      }
      if ( rawentry )
      {
        free( rawentry );
        rawentry = 0;
      }
      return 0;
    }
    else
    {
      s[0] = 0;
      s++;
      if ( strncasecomp( t, "text/html", 9 ) == 0 || strncasecomp( t, "text/plain", 10 ) == 0 )
      {
        s = &s[ -1 ];
        s[0] = ';';
        if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
        {
          fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring mailcap entry: %s\n", rawentry );
        }
        if ( rawentry )
        {
          free( rawentry );
          rawentry = 0;
        }
        return 0;
      }
      else
      {
        LYRemoveBlanks( rawentry );
        LYLowerCase( rawentry );
        *(int*)&mc->needsterminal = 0;
        *(int*)&mc->copiousoutput = 0;
        *(int*)&mc->needtofree = 1;
        *(int*)&mc->testcommand = 0;
        *(int*)&mc->label = 0;
        *(int*)&mc->printcommand = 0;
        *(int*)&mc->contenttype[0] = 0;
        HTSACopy( &mc->contenttype, rawentry );
        *(int*)&mc->quality = 0x3f800000;
        *(int*)&mc->maxbytes = 0;
        t = GetCommand( s, &mc->command );
        if ( t )
        {
          s = LYSkipBlanks( t );
          for ( ; s;  )
          {
            char *arg, *eq, *mallocd_string;
            t = GetCommand( s, &mallocd_string );
            arg = mallocd_string;
            eq = strchr( arg, '=' );
            if ( eq )
            {
              eq[0] = 0;
              eq++;
              eq = LYSkipBlanks( eq );
            }
            if ( arg && arg[0] )
            {
              arg = Cleanse( arg );
              if ( strcmp( arg, "needsterminal" ) == 0 )
                *(int*)&mc->needsterminal = 1;
              else
              {
                if ( strcmp( arg, "copiousoutput" ) == 0 )
                  *(int*)&mc->copiousoutput = 1;
                else
                if ( eq && strcmp( arg, "test" ) == 0 )
                {
                  *(int*)&mc->testcommand = 0;
                  HTSACopy( &mc->testcommand, eq );
                  TrimCommand( &mc->testcommand );
                  if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
                  {
                    fprintf( TraceFP( ), "ProcessMailcapEntry: Found testcommand:%s\n", &mc->testcommand );
                  }
                }
                else
                if ( eq && strcmp( arg, "description" ) == 0 )
                  mc->label = eq;
                else
                if ( eq && strcmp( arg, "label" ) == 0 )
                  mc->label = eq;
                else
                if ( eq && strcmp( arg, "print" ) == 0 )
                  mc->printcommand = eq;
                else
                if ( eq == 0 || strcmp( arg, "textualnewlines" ) )
                {
                  if ( eq && strcmp( arg, "q" ) == 0 )
                  {
                    mc->quality = atof( eq );
                    if ( mc->quality > 0 && mc->quality < 0.001000000000 )
                      *(int*)&mc->quality = 0x3a83126f;
                  }
                  else
                  if ( eq && strcmp( arg, "mxb" ) == 0 )
                  {
                    mc->maxbytes = atol( eq );
                    if ( mc->maxbytes < 0 )
                      *(int*)&mc->maxbytes = 0;
                  }
                  else
                  {
                    if ( strcmp( arg, "notes" ) && arg[0] && WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
                    {
                      fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring mailcap flag '%s'.\n", arg );
                    }
                  }
                }
              }
            }
            if ( mallocd_string )
            {
              free( mallocd_string );
              mallocd_string = 0;
            }
            s = t;
          }
        }
        if ( rawentry )
        {
          free( rawentry );
          rawentry = 0;
        }
        if ( PassesTest( mc ) )
        {
          if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
          {
            fprintf( TraceFP( ), "ProcessMailcapEntry Setting up conversion %s : %s\n", &mc->contenttype[0], &mc->command );
          }
          HTSetPresentation( &mc->contenttype[0], &mc->command, &mc->testcommand, mc->quality, 3.000000000000, 0.000000000000, mc->maxbytes, media );
        }
        if ( mc->command )
        {
          free( &mc->command );
          *(int*)&mc->command = 0;
        }
        if ( mc->testcommand )
        {
          free( &mc->testcommand );
          *(int*)&mc->testcommand = 0;
        }
        if ( mc->contenttype[0] )
        {
          free( &mc->contenttype[0] );
          *(int*)&mc->contenttype[0] = 0;
        }
        return 1;
      }
    }
  }
}
Exemplo n.º 26
0
int HTLoadExtensionsConfigFile( char *fn )
{
  int eax;
  char line[256];
  char word[256];
  char *ct;
  FILE *f;
  int count = 0;
  if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
  {
    fprintf( TraceFP( ), "HTLoadExtensionsConfigFile: Loading file '%s'.\n", fn );
  }
  f = fopen64( fn, "r" );
  if ( f == 0 )
  {
    if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
    {
      fprintf( TraceFP( ), "HTLoadExtensionsConfigFile: Could not open '%s'.\n", fn );
    }
    return count;
  }
  else
  {
    while ( HTGetLine( line, 256, f ) == 0 )
    {
      HTGetWord( word, line, ' ', '\t' );
      if ( line[0] && word[0] != '#' )
      {
        ct = 0;
        HTSACopy( &ct, word );
        LYLowerCase( ct );
        while ( line[0] )
        {
          HTGetWord( word, line, ' ', '\t' );
          if ( word[0] && word[0] != ' ' )
          {
            char *ext = 0;
            HTSprintf0( &ext, ".%s", word[0] );
            LYLowerCase( ext );
            if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
            {
              fprintf( TraceFP( ), "setting suffix '%s' to '%s'.\n", ext, ct );
            }
            if ( strstr( ct, "tex" ) || strstr( ct, "postscript" ) || strstr( ct, "sh" ) || strstr( ct, "troff" ) || strstr( ct, "rtf" ) )
              HTSetSuffix5( ext, ct, "8bit", 0, 1.000000000000 );
            else
              HTSetSuffix5( ext, ct, "binary", 0, 1.000000000000 );
            count++;
            if ( ext )
            {
              free( ext );
            }
          }
        }
        if ( ct )
        {
          free( ct );
          ct = 0;
        }
      }
    }
    LYCloseInput( f );
    return count;
  }
}
Exemplo n.º 27
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.º 28
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;
}