OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
ghttpConnection.h
1 /*
2GameSpy GHTTP SDK
3Dan "Mr. Pants" Schoenblum
4dan@gamespy.com
5
6Copyright 1999-2007 GameSpy Industries, Inc
7
8devsupport@gamespy.com
9*/
10
11#ifndef _GHTTPCONNECTION_H_
12#define _GHTTPCONNECTION_H_
13
14#include "ghttpMain.h"
15#include "ghttpEncryption.h"
16#include "ghttpBuffer.h"
17#include "ghttpPost.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23// Initial size and increment amount for the send buffer.
25#define SEND_BUFFER_INITIAL_SIZE (2 * 1024)
26#define SEND_BUFFER_INCREMENT_SIZE (4 * 1024)
27
28// Initial size and increment amount for the recv buffer.
30#define RECV_BUFFER_INITIAL_SIZE (2 * 1024)
31#define RECV_BUFFER_INCREMENT_SIZE (2 * 1024)
32
33// Initial size and increment amount for the get file buffer.
35#define GET_FILE_BUFFER_INITIAL_SIZE (2 * 1024)
36#define GET_FILE_BUFFER_INCREMENT_SIZE (2 * 1024)
37
38// Initial size and increment amount for the ssl encoding buffer.
40#define ENCODE_BUFFER_INITIAL_SIZE (2 * 1024)
41#define ENCODE_BUFFER_INCREMENT_SIZE (1 * 1024)
42
43// Initial size and increment amount for the ssl decoding buffer.
45#define DECODE_BUFFER_INITIAL_SIZE (2 * 1024)
46#define DECODE_BUFFER_INCREMENT_SIZE (1 * 1024)
47
48// The size of the buffer for chunk headers (NOT including the NUL).
50#define CHUNK_HEADER_SIZE 10
51
52// The type of request made.
54typedef enum
55{
56 GHIGET, // Buffer the file.
57 GHISAVE, // Save the file to disk.
58 GHISTREAM, // Stream the file.
59 GHIHEAD, // Get just the headers for a request.
60 GHIPOST // Only posting data (all types can post).
61} GHIRequestType;
62
63// Chunk-reading states.
65typedef enum
66{
67 CRHeader, // Reading a chunk header.
68 CRChunk, // Reading chunk (actual content).
69 CRCRLF, // Reading the CRLF at the end of a chunk.
70 CRFooter // Reading the footer at the end of the file (chunk with size of 0).
71} CRState;
72
73// Protocol.
75typedef enum
76{
77 GHIHttp,
78 GHIHttps
79} GHIProtocol;
80
81// This is the data for a single http connection.
83typedef struct GHIConnection
84{
85 GHTTPBool inUse; // If true, this connection object is being used.
86 GHTTPRequest request; // This object's request index.
87 int uniqueID; // Every connection object has a unqiue ID.
88
89 GHIRequestType type; // The type of request this connection is for.
90
91 GHTTPState state; // The state of the request.
92
93 char * URL; // The URL for the file.
94 char * serverAddress; // The address of the server as contained in the URL.
95 unsigned int serverIP; // The server's IP.
96 unsigned short serverPort; // The server's port.
97 char * requestPath; // The path as contained in the URL.
98
99 GHIProtocol protocol; // Protocol used for this connection.
100
101 char * sendHeaders; // Optional headers to pass with the request.
102
103 FILE * saveFile; // If saving to disk, the file being saved to.
104
105 GHTTPBool blocking; // Blocking flag.
106
107 GHTTPBool persistConnection; // If TRUE, Connection: close will not be sent in the headers and the connection will be left open
108
109 GHTTPResult result; // The result of the request.
110 ghttpProgressCallback progressCallback; // Called periodically with progress updates.
111 ghttpCompletedCallback completedCallback; // Called when the file has been received.
112 void * callbackParam; // User-data to be passed to the callbacks.
113
114 SOCKET socket; // The socket for this connection.
115 int socketError; // If there was a socket error, the last error code is stored here.
116
117 GHIBuffer sendBuffer; // The buffer for outgoing data.
118 GHIBuffer encodeBuffer; // The buffer for outgoing data. (will be encrypted; only used with https)
119 GHIBuffer recvBuffer; // The buffer for incoming data. (plain text)
120 GHIBuffer decodeBuffer; // The buffer for incoming data. (encrypted)(only used with https)
121
122 GHIBuffer getFileBuffer; // ghttpGetFile[Ex] uses this buffer (which may be user-supplied).
123 GHTTPBool userBufferSupplied; // True if a user buffer was supplied.
124
125 int statusMajorVersion; // The major-version number from the server's response.
126 int statusMinorVersion; // The minor-version number from the server's response.
127 int statusCode; // The status-code from the server's response.
128 int statusStringIndex; // Index in the recvBuffer where the status string starts.
129
130 int headerStringIndex; // Index in the recvBuffer where the headers begin
131
132 GHTTPBool completed; // This connection is completed - call the callback and kill it.
133
134 GHTTPByteCount fileBytesReceived; // Number of file bytes received.
135 GHTTPByteCount totalSize; // Total size of the file, -1 if unknown.
136
137 char * redirectURL; // If this is not NULL, we need to redirect the download to this URL.
138 int redirectCount; // Number of redirections done for this request.
139
140 GHTTPBool chunkedTransfer; // The body of the response is chunky ("Transfer-Encoding: chunked").
141 char chunkHeader[CHUNK_HEADER_SIZE + 1]; // Partial chunk headers are stored in here.
142 int chunkHeaderLen; // The number of bytes in chunkHeader.
143 int chunkBytesLeft; // Number of bytes left in the chunk (only valid for CRChunk).
144 CRState chunkReadingState; // Determines if a chunk header or chunk data is being read.
145
146 GHTTPBool processing; // If true, being processed. Used to prevent recursive processing.
147 GHTTPBool connectionClosed; // If true, the connection has been closed (orderly or abortive)
148
149 GHTTPBool throttle; // If true, throttle this connection.
150 gsi_time lastThrottleRecv; // The last time we received on a throttled connection.
151
152 GHTTPPost post; // If not NULL, a reference to a post object to upload with the request.
153 GHIPostingState postingState; // If posting, the state of the upload.
154
155 gsi_time maxRecvTime; // Max time spent receiving per call to "Think" - Prevents blocking on ultrafast connections
156 char * proxyOverrideServer; // Allows use of a different proxy than the global proxy
157 unsigned short proxyOverridePort;
158
159 struct GHIEncryptor encryptor;
160
161#if !defined(GSI_NO_THREADS)
162 GSIResolveHostnameHandle handle; //handle used for asychronous DNS lookups
163#endif
164
166
167// Create a new connection object.
168// Returns NULL on failure.
170GHIConnection * ghiNewConnection
171(
172 void
173);
174
175// Frees the connection object.
177GHTTPBool ghiFreeConnection
178(
179 GHIConnection * connection
180);
181
182// Returns the connection object for a request index.
183// Returns NULL if the index is bad.
185GHIConnection * ghiRequestToConnection
186(
187 GHTTPRequest request
188);
189
190// Calls the callback on each connection.
192void ghiEnumConnections
193(
194 GHTTPBool (* callback)(GHIConnection *)
195);
196
197// Redirects the given connection.
198// Resets the connection to get the
199// file at connection->redirectURL.
201void ghiRedirectConnection
202(
203 GHIConnection * connection
204);
205
206// Kills all connections and frees up all memory.
208void ghiCleanupConnections
209(
210 void
211);
212
213#ifdef __cplusplus
214}
215#endif
216
217#endif
Definition ghttpBuffer.h:24
Definition ghttpConnection.h:84
Definition ghttpEncryption.h:76
Definition ghttpPost.h:31