w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

istream.h (3496B)


      1 /* $Id$ */
      2 #ifndef IO_STREAM_H
      3 #define IO_STREAM_H
      4 
      5 #include <stdio.h>
      6 #ifdef USE_SSL
      7 #include <openssl/bio.h>
      8 #include <openssl/x509.h>
      9 #include <openssl/ssl.h>
     10 #endif
     11 #include "Str.h"
     12 #include <sys/types.h>
     13 #include <sys/stat.h>
     14 #include <fcntl.h>
     15 
     16 struct stream_buffer {
     17     unsigned char *buf;
     18     int size, cur, next;
     19 };
     20 
     21 typedef struct stream_buffer *StreamBuffer;
     22 
     23 struct file_handle {
     24     FILE *f;
     25     void (*close) ();
     26 };
     27 
     28 #ifdef USE_SSL
     29 struct ssl_handle {
     30     SSL *ssl;
     31     int sock;
     32 };
     33 #endif
     34 
     35 union input_stream;
     36 
     37 struct ens_handle {
     38     union input_stream *is;
     39     Str s;
     40     int pos;
     41     char encoding;
     42 };
     43 
     44 
     45 struct base_stream {
     46     struct stream_buffer stream;
     47     void *handle;
     48     char type;
     49     char iseos;
     50     int (*read) ();
     51     void (*close) ();
     52 };
     53 
     54 struct file_stream {
     55     struct stream_buffer stream;
     56     struct file_handle *handle;
     57     char type;
     58     char iseos;
     59     int (*read) ();
     60     void (*close) ();
     61 };
     62 
     63 struct str_stream {
     64     struct stream_buffer stream;
     65     Str handle;
     66     char type;
     67     char iseos;
     68     int (*read) ();
     69     void (*close) ();
     70 };
     71 
     72 #ifdef USE_SSL
     73 struct ssl_stream {
     74     struct stream_buffer stream;
     75     struct ssl_handle *handle;
     76     char type;
     77     char iseos;
     78     int (*read) ();
     79     void (*close) ();
     80 };
     81 #endif				/* USE_SSL */
     82 
     83 struct encoded_stream {
     84     struct stream_buffer stream;
     85     struct ens_handle *handle;
     86     char type;
     87     char iseos;
     88     int (*read) ();
     89     void (*close) ();
     90 };
     91 
     92 union input_stream {
     93     struct base_stream base;
     94     struct file_stream file;
     95     struct str_stream str;
     96 #ifdef USE_SSL
     97     struct ssl_stream ssl;
     98 #endif				/* USE_SSL */
     99     struct encoded_stream ens;
    100 };
    101 
    102 typedef struct base_stream *BaseStream;
    103 typedef struct file_stream *FileStream;
    104 typedef struct str_stream *StrStream;
    105 #ifdef USE_SSL
    106 typedef struct ssl_stream *SSLStream;
    107 #endif				/* USE_SSL */
    108 typedef struct encoded_stream *EncodedStrStream;
    109 
    110 typedef union input_stream *InputStream;
    111 
    112 extern InputStream newInputStream(int des);
    113 extern InputStream newFileStream(FILE * f, void (*closep) ());
    114 extern InputStream newStrStream(Str s);
    115 #ifdef USE_SSL
    116 extern InputStream newSSLStream(SSL * ssl, int sock);
    117 #endif
    118 extern InputStream newEncodedStream(InputStream is, char encoding);
    119 extern int ISclose(InputStream stream);
    120 extern int ISgetc(InputStream stream);
    121 extern int ISundogetc(InputStream stream);
    122 extern Str StrISgets(InputStream stream);
    123 extern Str StrmyISgets(InputStream stream);
    124 extern int ISread(InputStream stream, Str buf, int count);
    125 extern int ISfileno(InputStream stream);
    126 extern int ISeos(InputStream stream);
    127 #ifdef USE_SSL
    128 extern void ssl_accept_this_site(char *hostname);
    129 extern Str ssl_get_certificate(SSL * ssl, char *hostname);
    130 #endif
    131 
    132 #define IST_BASIC	0
    133 #define IST_FILE	1
    134 #define IST_STR		2
    135 #define IST_SSL		3
    136 #define IST_ENCODED	4
    137 #define IST_UNCLOSE	0x10
    138 
    139 #define IStype(stream) ((stream)->base.type)
    140 #define is_eos(stream) ISeos(stream)
    141 #define iseos(stream) ((stream)->base.iseos)
    142 #define file_of(stream) ((stream)->file.handle->f)
    143 #define set_close(stream,closep) ((IStype(stream)==IST_FILE)?((stream)->file.handle->close=(closep)):0)
    144 #define str_of(stream) ((stream)->str.handle)
    145 #ifdef USE_SSL
    146 #define ssl_socket_of(stream) ((stream)->ssl.handle->sock)
    147 #define ssl_of(stream) ((stream)->ssl.handle->ssl)
    148 #endif
    149 
    150 #ifdef USE_BINMODE_STREAM
    151 #define openIS(path) newInputStream(open((path),O_RDONLY|O_BINARY))
    152 #else
    153 #define openIS(path) newInputStream(open((path),O_RDONLY))
    154 #endif				/* USE_BINMODE_STREAM */
    155 #endif