cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
http.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * cryptlib HTTP Interface Header *
4 * Copyright Peter Gutmann 1998-2006 *
5 * *
6 ****************************************************************************/
7 
8 #ifdef USE_HTTP
9 
10 #if defined( INC_ALL )
11  #include "stream_int.h"
12 #else
13  #include "io/stream_int.h"
14 #endif /* Compiler-specific includes */
15 
16 /* The size of the HTTP text-line buffer when we're using a dedicated buffer
17  to read header lines rather than the main stream buffer. Anything more
18  than this is dropped */
19 
20 #define HTTP_LINEBUF_SIZE 1024
21 
22 /* A macro to determine whether we're talking HTTP 1.0 or 1.1 */
23 
24 #define isHTTP10( stream ) ( ( stream )->flags & STREAM_NFLAG_HTTP10 )
25 
26 /* HTTP state information passed around the various read/write functions */
27 
28 #define HTTP_FLAG_NONE 0x00 /* No HTTP info */
29 #define HTTP_FLAG_CHUNKED 0x01 /* Message used chunked encoding */
30 #define HTTP_FLAG_TRAILER 0x02 /* Chunked encoding has trailer */
31 #define HTTP_FLAG_NOOP 0x04 /* No-op data (e.g. 100 Continue) */
32 #define HTTP_FLAG_TEXTMSG 0x08 /* HTTP content is plain text, probably
33  an error message */
34 #define HTTP_FLAG_GET 0x10 /* Operation is HTTP GET */
35 #define HTTP_FLAG_MAX 0x1F /* Maximum possible flag value */
36 
37 /* HTTP header parsing information as used by readHeaderLines() */
38 
39 typedef struct {
40  /* Returned status information: The body content-length, the HTTP error
41  status (if there is one), and general flags information. The flags
42  parameter is used as both an input and an output parameter */
43  int contentLength; /* HTTP body content length */
44  int httpStatus; /* HTTP error status, if an HTTP error occurs */
45  int flags; /* General flags */
46 
47  /* Range-checking information: The minimum and maximum allowable
48  content-length value */
49  int minContentLength, maxContentLength;
50  } HTTP_HEADER_INFO;
51 
52 #define initHeaderInfo( headerInfo, minLength, maxLength, hdrFlags ) \
53  memset( headerInfo, 0, sizeof( HTTP_HEADER_INFO ) ); \
54  ( headerInfo )->flags = ( hdrFlags ); \
55  ( headerInfo )->minContentLength = ( minLength ); \
56  ( headerInfo )->maxContentLength = ( maxLength );
57 
58 /* Prototypes for functions in http_wr.c */
59 
61 int writeRequestHeader( INOUT STREAM *stream,
63  IN_BUFFER_OPT( contentTypeLen ) const char *contentType,
64  IN_LENGTH_SHORT_Z const int contentTypeLen,
65  IN_LENGTH_Z const int contentLength,
66  const BOOLEAN forceGet );
67 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
68 int sendHTTPData( INOUT STREAM *stream,
69  IN_BUFFER( length ) void *buffer,
70  IN_LENGTH const int length,
71  IN_FLAGS( HTTP ) const int flags );
72 STDC_NONNULL_ARG( ( 1 ) ) \
73 void setStreamLayerHTTPwrite( INOUT NET_STREAM_INFO *netStream );
74 
75 /* Prototypes for functions in http_parse.c. Most of these functions don't
76  actually return anything in the buffer that's passed in but merely use it
77  as general scratch buffer to save having to give each function its own
78  (sizeable) scratch buffer */
79 
80 STDC_NONNULL_ARG( ( 1, 2 ) ) \
81 int sendHTTPError( INOUT STREAM *stream,
82  IN_BUFFER( headerBufMaxLen ) char *headerBuffer,
83  IN_LENGTH_SHORT_MIN( 256 ) const int headerBufMaxLen,
84  IN_INT const int httpStatus );
85 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
86 int checkHTTPID( IN_BUFFER( dataLength ) const char *data,
87  IN_LENGTH_SHORT const int dataLength,
88  INOUT STREAM *stream );
89 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3, 4 ) ) \
90 int parseUriInfo( INOUT_BUFFER( dataInLength, *dataOutLength ) char *data,
91  IN_LENGTH_SHORT const int dataInLength,
92  OUT_LENGTH_SHORT_Z int *dataOutLength,
93  INOUT HTTP_URI_INFO *uriInfo );
94 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4 ) ) \
95 int readFirstHeaderLine( INOUT STREAM *stream,
96  OUT_BUFFER_FIXED( dataMaxLength ) char *dataBuffer,
97  IN_LENGTH_SHORT const int dataMaxLength,
98  OUT_RANGE( 0, 999 ) int *httpStatus );
99 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4 ) ) \
100 int readHeaderLines( INOUT STREAM *stream,
101  OUT_BUFFER_FIXED( lineBufMaxLen ) char *lineBuffer,
102  IN_LENGTH_SHORT_MIN( 256 ) const int lineBufMaxLen,
103  INOUT HTTP_HEADER_INFO *headerInfo );
104 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
105 int readTrailerLines( INOUT STREAM *stream,
106  OUT_BUFFER_FIXED( lineBufMaxLen ) char *lineBuffer,
107  IN_LENGTH_SHORT_MIN( 256 ) const int lineBufMaxLen );
108 STDC_NONNULL_ARG( ( 1, 4 ) ) \
109 int retTextLineError( INOUT STREAM *stream, IN_ERROR const int status,
110  const BOOLEAN isTextLineError,
111  FORMAT_STRING const char *format,
112  const int value );
113 
114 #endif /* USE_HTTP */