OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
ghttp.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 _GHTTP_H_
12#define _GHTTP_H_
13
14#include <stdlib.h>
15
16#include "../common/gsCommon.h"
17#include "../common/gsXML.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#ifndef GSI_UNICODE
24#define ghttpGet ghttpGetA
25#define ghttpGetEx ghttpGetExA
26#define ghttpSave ghttpSaveA
27#define ghttpSaveEx ghttpSaveExA
28#define ghttpStream ghttpStreamA
29#define ghttpStreamEx ghttpStreamExA
30#define ghttpHead ghttpHeadA
31#define ghttpHeadEx ghttpHeadExA
32#define ghttpPost ghttpPostA
33#define ghttpPostEx ghttpPostExA
34#define ghttpPostAddString ghttpPostAddStringA
35#define ghttpPostAddFileFromDisk ghttpPostAddFileFromDiskA
36#define ghttpPostAddFileFromMemory ghttpPostAddFileFromMemoryA
37#else
38#define ghttpGet ghttpGetW
39#define ghttpGetEx ghttpGetExW
40#define ghttpSave ghttpSaveW
41#define ghttpSaveEx ghttpSaveExW
42#define ghttpStream ghttpStreamW
43#define ghttpStreamEx ghttpStreamExW
44#define ghttpHead ghttpHeadW
45#define ghttpHeadEx ghttpHeadExW
46#define ghttpPost ghttpPostW
47#define ghttpPostEx ghttpPostExW
48#define ghttpPostAddString ghttpPostAddStringW
49#define ghttpPostAddFileFromDisk ghttpPostAddFileFromDiskW
50#define ghttpPostAddFileFromMemory ghttpPostAddFileFromMemoryW
51#endif
52
53// Boolean.
55typedef enum
56{
57 GHTTPFalse,
58 GHTTPTrue
59} GHTTPBool;
60
61// ByteCount.
63#if (GSI_MAX_INTEGRAL_BITS >= 64)
64typedef gsi_i64 GHTTPByteCount;
65#else
66typedef gsi_i32 GHTTPByteCount;
67#endif
68
69// The current state of an http request.
71typedef enum
72{
73 GHTTPSocketInit, // Socket creation and initialization.
74 GHTTPHostLookup, // Resolving hostname to IP (asynchronously if possible).
75 GHTTPLookupPending, // Asychronous DNS lookup pending.
76 GHTTPConnecting, // Waiting for socket connect to complete.
77 GHTTPSecuringSession, // Setup secure channel.
78 GHTTPSendingRequest, // Sending the request.
79 GHTTPPosting, // Positing data (skipped if not posting).
80 GHTTPWaiting, // Waiting for a response.
81 GHTTPReceivingStatus, // Receiving the response status.
82 GHTTPReceivingHeaders, // Receiving the headers.
83 GHTTPReceivingFile // Receiving the file.
84} GHTTPState;
85
86// The result of an http request.
88typedef enum
89{
90 GHTTPSuccess, // 0: Successfully retrieved file.
91 GHTTPOutOfMemory, // 1: A memory allocation failed.
92 GHTTPBufferOverflow, // 2: The user-supplied buffer was too small to hold the file.
93 GHTTPParseURLFailed, // 3: There was an error parsing the URL.
94 GHTTPHostLookupFailed, // 4: Failed looking up the hostname.
95 GHTTPSocketFailed, // 5: Failed to create/initialize/read/write a socket.
96 GHTTPConnectFailed, // 6: Failed connecting to the http server.
97 GHTTPBadResponse, // 7: Error understanding a response from the server.
98 GHTTPRequestRejected, // 8: The request has been rejected by the server.
99 GHTTPUnauthorized, // 9: Not authorized to get the file.
100 GHTTPForbidden, // 10: The server has refused to send the file.
101 GHTTPFileNotFound, // 11: Failed to find the file on the server.
102 GHTTPServerError, // 12: The server has encountered an internal error.
103 GHTTPFileWriteFailed, // 13: An error occured writing to the local file (for ghttpSaveFile[Ex]).
104 GHTTPFileReadFailed, // 14: There was an error reading from a local file (for posting files from disk).
105 GHTTPFileIncomplete, // 15: Download started but was interrupted. Only reported if file size is known.
106 GHTTPFileToBig, // 16: The file is to big to be downloaded (size exceeds range of interal data types)
107 GHTTPEncryptionError, // 17: Error with encryption engine.
108 GHTTPRequestCancelled // 18: User requested cancel and/or graceful close.
109} GHTTPResult;
110
111// Encryption engines
112typedef enum
113{
114 GHTTPEncryptionEngine_None,
115 GHTTPEncryptionEngine_GameSpy, // must add /common/gsSSL.h and /common/gsSSL.c to project
116 GHTTPEncryptionEngine_MatrixSsl, // must define MATRIXSSL and include matrixssl source files
117 GHTTPEncryptionEngine_RevoEx, // must define REVOEXSSL and include RevoEX SSL source files
118
119 GHTTPEncryptionEngine_Default // Will use GameSpy unless another engine is defined
120 // using MATRIXSSL or REVOEXSSL
121} GHTTPEncryptionEngine;
122
123// Represents an http file request.
125typedef int GHTTPRequest;
126
127// Invalid GHTTPRequest values represent an error
129#ifdef GHTTP_EXTENDEDERROR
130 typedef enum
131 {
132 GHTTPErrorStart = -8,
133 GHTTPFailedToOpenFile,
134 GHTTPInvalidPost,
135 GHTTPInsufficientMemory,
136 GHTTPInvalidFileName,
137 GHTTPInvalidBufferSize,
138 GHTTPInvalidURL,
139 GHTTPUnspecifiedError = -1
140 } GHTTPRequestError;
141#else
142 // Backwards compatibility, developers may have relied on -1 as the only error code
143 typedef enum
144 {
145 GHTTPErrorStart = -1,
146 GHTTPFailedToOpenFile = -1,
147 GHTTPInvalidPost = -1,
148 GHTTPInsufficientMemory = -1,
149 GHTTPInvalidFileName = -1,
150 GHTTPInvalidBufferSize = -1,
151 GHTTPInvalidURL = -1,
152 GHTTPUnspecifiedError = -1
153 } GHTTPRequestError;
154#endif
155
156#define IS_GHTTP_ERROR(x) (x<0)
157
158// Data that can be posted to the server.
159// Don't try to access this object directly,
160// use the ghttpPost*() functions.
162typedef struct GHIPost * GHTTPPost;
163
164
165// Called with updates on the current state of the request.
166// The buffer should not be accessed once this callback returns.
167// If ghttpGetFile[Ex] was used, buffer contains all of the data that has been
168// received so far, and bufferSize is the total number of bytes received.
169// If ghttpSaveFile[Ex] was used, buffer only contains the most recent data
170// that has been received. This same data is saved to the file. The buffer
171// will not be valid after this callback returns.
172// If ghttpStreamFileEx was used, buffer only contains the most recent data
173// that has been received. This data will be lost once the callback
174// returns, and should be copied if it needs to be saved. bufferSize
175// is the number of bytes in the current block of data.
177typedef void (* ghttpProgressCallback)
178(
179 GHTTPRequest request, // The request.
180 GHTTPState state, // The current state of the request.
181 const char * buffer, // The file's bytes so far, NULL if state<GHTTPReceivingFile.
182 GHTTPByteCount bufferLen, // The number of bytes in the buffer, 0 if state<GHTTPReceivingFile.
183 GHTTPByteCount bytesReceived, // The total number of bytes receivied, 0 if state<GHTTPReceivingFile.
184 GHTTPByteCount totalSize, // The total size of the file, -1 if unknown.
185 void * param // User-data.
186);
187
188// Called when the entire file has been received.
189// If ghttpStreamFileEx or ghttpSaveFile[Ex] was used,
190// buffer is NULL, bufferLen is the number of bytes
191// in the file, and the return value is ignored.
192// If ghttpGetFile[Ex] was used, return true to have
193// the buffer freed, false if the app will free the
194// buffer. If true, the buffer cannot be accessed
195// once the callback returns. If false, the app can
196// use the buffer even after this call returns, but
197// must free it at some later point. There will always
198// be a file, even if there was an error, although for
199// errors it may be an empty file.
201typedef GHTTPBool (* ghttpCompletedCallback)
202(
203 GHTTPRequest request, // The request.
204 GHTTPResult result, // The result (success or an error).
205 char * buffer, // The file's bytes (only valid if ghttpGetFile[Ex] was used).
206 GHTTPByteCount bufferLen, // The file's length.
207 void * param // User-data.
208);
209
210// Does all necessary initialization.
211// Startup/Cleanup is reference counted, so always call
212// ghttpStartup() and ghttpCleanup() in pairs.
214void ghttpStartup
215(
216 void
217);
218
219// Cleans up any resources being used by this library.
220// Startup/Cleanup is reference counted, so always call
221// ghttpStartup() and ghttpCleanup() in pairs.
223void ghttpCleanup
224(
225 void
226);
227
228// Get a file from an http server.
229// Returns GHTTPRequestError if an error occurs.
231GHTTPRequest ghttpGet
232(
233 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
234 GHTTPBool blocking, // If true, this call doesn't return until the file has been recevied.
235 ghttpCompletedCallback completedCallback, // Called when the file has been received.
236 void * param // User-data to be passed to the callbacks.
237);
238
239// Get a file from an http server.
240// Returns GHTTPRequestError if an error occurs.
241// Allows an optional user-supplied buffer to be used,
242// optional extra http headers,
243// and an optional progress callback.
244// The optional headers must be 0 or more HTTP headers,
245// each terminated by a CR-LF pair (0xD, 0xA).
246// If using a user-supplied buffer:
247// set buffer to the buffer to use,
248// set bufferSize to the size of the buffer in bytes.
249// To have the library allocate a buffer:
250// set buffer to NULL, set bufferSize to 0
252GHTTPRequest ghttpGetEx
253(
254 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
255 const gsi_char * headers, // Optional headers to pass with the request. Can be NULL or "".
256 char * buffer, // Optional user-supplied buffer. Set to NULL to have one allocated.
257 int bufferSize, // The size of the user-supplied buffer in bytes. 0 if buffer is NULL.
258 GHTTPPost post, // Optional data to be posted.
259 GHTTPBool throttle, // If true, throttle this connection's download speed.
260 GHTTPBool blocking, // If true, this call doesn't return until the file has been recevied.
261 ghttpProgressCallback progressCallback, // Called periodically with progress updates.
262 ghttpCompletedCallback completedCallback, // Called when the file has been received.
263 void * param // User-data to be passed to the callbacks.
264);
265
266// Gets a file and saves it to disk.
267// Returns GHTTPRequestError if an error occurs.
269GHTTPRequest ghttpSave
270(
271 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
272 const gsi_char * filename, // The path and name to store the file as locally.
273 GHTTPBool blocking, // If true, this call doesn't return until the file has been recevied.
274 ghttpCompletedCallback completedCallback, // Called when the file has been received.
275 void * param // User-data to be passed to the callbacks.
276);
277
278// Gets a file and saves it to disk.
279// Returns GHTTPRequestError if an error occurs.
280// Allows optional extra http headers and
281// an optional progress callback.
283GHTTPRequest ghttpSaveEx
284(
285 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
286 const gsi_char * filename, // The path and name to store the file as locally.
287 const gsi_char * headers, // Optional headers to pass with the request. Can be NULL or "".
288 GHTTPPost post, // Optional data to be posted.
289 GHTTPBool throttle, // If true, throttle this connection's download speed.
290 GHTTPBool blocking, // If true, this call doesn't return until the file has been recevied.
291 ghttpProgressCallback progressCallback, // Called periodically with progress updates.
292 ghttpCompletedCallback completedCallback, // Called when the file has been received.
293 void * param // User-data to be passed to the callbacks.
294);
295
296// Streams a file from an http server.
297// Returns GHTTPRequestError if an error occurs.
299GHTTPRequest ghttpStream
300(
301 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
302 GHTTPBool blocking, // If true, this call doesn't return until the file has finished streaming.
303 ghttpProgressCallback progressCallback, // Called whenever new data is received.
304 ghttpCompletedCallback completedCallback, // Called when the file has finished streaming.
305 void * param // User-data to be passed to the callbacks.
306);
307
308// Streams a file from an http server.
309// Returns GHTTPRequestError if an error occurs.
310// Allows optional extra http headers.
312GHTTPRequest ghttpStreamEx
313(
314 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
315 const gsi_char * headers, // Optional headers to pass with the request. Can be NULL or "".
316 GHTTPPost post, // Optional data to be posted.
317 GHTTPBool throttle, // If true, throttle this connection's download speed.
318 GHTTPBool blocking, // If true, this call doesn't return until the file has finished streaming.
319 ghttpProgressCallback progressCallback, // Called whenever new data is received.
320 ghttpCompletedCallback completedCallback, // Called when the file has finished streaming.
321 void * param // User-data to be passed to the callbacks.
322);
323
324// Does a file request without actually getting the file.
325// Use this to check the headers returned by a server when a request is made.
326// Returns GHTTPRequestError if an error occurs.
328GHTTPRequest ghttpHead
329(
330 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
331 GHTTPBool blocking, // If true, this call doesn't return until finished
332 ghttpCompletedCallback completedCallback, // Called when the request has finished.
333 void * param // User-data to be passed to the callbacks.
334);
335
336// Does a file request without actually getting the file.
337// Use this to check the headers returned by a server when a request is made.
338// Returns GHTTPRequestError if an error occurs.
339// Allows optional extra http headers.
341GHTTPRequest ghttpHeadEx
342(
343 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
344 const gsi_char * headers, // Optional headers to pass with the request. Can be NULL or "".
345 GHTTPBool throttle, // If true, throttle this connection's download speed.
346 GHTTPBool blocking, // If true, this call doesn't return until finished
347 ghttpProgressCallback progressCallback, // Called whenever new data is received.
348 ghttpCompletedCallback completedCallback, // Called when the request has finished.
349 void * param // User-data to be passed to the callbacks.
350);
351
352// Does an HTTP POST, which can be used to upload data to a web server.
353// The post parameter must be a valid GHTTPPost, setup with the data to be uploaded.
354// No data will be returned from this request. If data is needed, use one of the
355// ghttp*FileEx() functions, and pass in a GHTTPPost object.
356// Returns GHTTPRequestError if an error occurs.
358GHTTPRequest ghttpPost
359(
360 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
361 GHTTPPost post, // The data to be posted.
362 GHTTPBool blocking, // If true, this call doesn't return until finished
363 ghttpCompletedCallback completedCallback, // Called when the file has finished streaming.
364 void * param // User-data to be passed to the callbacks.
365);
366
367// Does an HTTP POST, which can be used to upload data to a web server.
368// The post parameter must be a valid GHTTPPost, setup with the data to be uploaded.
369// No data will be returned from this request. If data is needed, use one of the
370// ghttp*FileEx() functions, and pass in a GHTTPPost object.
371// Returns GHTTPRequestError if an error occurs.
372// Allows optional extra http headers and
373// an optional progress callback.
375GHTTPRequest ghttpPostEx
376(
377 const gsi_char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
378 const gsi_char * headers, // Optional headers to pass with the request. Can be NULL or "".
379 GHTTPPost post, // The data to be posted.
380 GHTTPBool throttle, // If true, throttle this connection's download speed.
381 GHTTPBool blocking, // If true, this call doesn't return until finished
382 ghttpProgressCallback progressCallback, // Called whenever new data is received.
383 ghttpCompletedCallback completedCallback, // Called when the file has finished streaming.
384 void * param // User-data to be passed to the callbacks.
385);
386
387// Processes all current http requests.
389void ghttpThink
390(
391 void
392);
393
394// Process one particular http request.
396GHTTPBool ghttpRequestThink
397(
398 GHTTPRequest request
399);
400
401// Cancels the request. Socket is closed.
403void ghttpCancelRequest
404(
405 GHTTPRequest request
406);
407
408// Closes a request gracefull using shutdown(s, SD_SEND)
409// PS2-Insock does not support partial shutdown.
410void ghttpCloseRequest
411(
412 GHTTPRequest request
413);
414
415
416// Gets the current state of this request.
418GHTTPState ghttpGetState
419(
420 GHTTPRequest request
421);
422
423// Gets the status code and status string for a request.
424// A pointer to the status string is returned, or NULL on error.
425// Only valid if the GHTTPState for this request
426// is greater than GHTTPReceivingStatus.
428const char * ghttpGetResponseStatus
429(
430 GHTTPRequest request, // The request to get the response state of.
431 int * statusCode // If not NULL, the status code is stored here.
432);
433
434// Gets headers returned by the http server.
435// Only valid if the GHTTPState for this
436// request is GHTTPReceivingFile.
438const char * ghttpGetHeaders
439(
440 GHTTPRequest request
441);
442
443// Gets the URL for a given request.
445const char * ghttpGetURL
446(
447 GHTTPRequest request
448);
449
450// Sets a proxy server address. The address should be of the
451// form "<server>[:port]". If port is omitted, 80 will be used.
452// If server is NULL or "", no proxy server will be used.
453// This should not be called while there are any current requests.
455GHTTPBool ghttpSetProxy
456(
457 const char * server
458);
459
460// Sets a proxy server for a specific request. The address should be of the
461// form "<server>[:port]". If port is omitted, 80 will be used.
462// If server is NULL or "", no proxy server will be used.
464GHTTPBool ghttpSetRequestProxy
465(
466 GHTTPRequest request,
467 const char * server
468);
469
470// Used to start/stop throttling an existing connection.
471// This may not be as efficient as starting a request
472// with the desired setting.
474void ghttpSetThrottle
475(
476 GHTTPRequest request,
477 GHTTPBool throttle
478);
479
480// Used to adjust the throttle settings.
482void ghttpThrottleSettings
483(
484 int bufferSize, // The number of bytes to get each receive.
485 gsi_time timeDelay // How often to receive data, in milliseconds.
486);
487
488// Used to throttle based on time, not on bandwidth
489// Prevents recv-loop blocking on ultrafast connections without directly limiting transfer rate
491void ghttpSetMaxRecvTime
492(
493 GHTTPRequest request,
494 gsi_time maxRecvTime
495);
496
497// Creates a new post object, which is used to represent data to send to
498// the web server as part of a request.
499// After getting the post object, use the ghttpPostAdd*() functions
500// to add data to the object, and ghttPostSetCallback() to add a
501// callback to monitor the progress of the data upload.
502// By default post objects automatically free themselves after posting.
503// To use the same post with more than one request, set auto-free to false,
504// then use ghttpFreePost to free it _after_ every request its being used
505// in is _completed_.
506// Returns NULL on error.
508GHTTPPost ghttpNewPost
509(
510 void
511);
512
513// Sets a post object's auto-free flag.
514// By default post objects automatically free themselves after posting.
515// To use the same post with more than one request, set auto-free to false,
516// then use ghttpFreePost to free it _after_ every request its being used
517// in is _completed_.
519void ghttpPostSetAutoFree
520(
521 GHTTPPost post,
522 GHTTPBool autoFree
523);
524
525// Frees a post object.
527void ghttpFreePost
528(
529 GHTTPPost post // The post object to free.
530);
531
532// Adds a string to the post object.
534GHTTPBool ghttpPostAddString
535(
536 GHTTPPost post, // The post object to add to.
537 const gsi_char * name, // The name to attach to this string.
538 const gsi_char * string // The actual string.
539);
540
541// Adds a disk file to the post object.
542// The reportFilename is what is reported to the server as the filename.
543// If NULL or empty, the filename will be used (including any possible path).
544// The contentType is the MIME type to report for this file.
545// If NULL, "application/octet-stream" is used.
546// The file isn't read from until the data is actually sent to the server.
547// Returns false for any error.
549GHTTPBool ghttpPostAddFileFromDisk
550(
551 GHTTPPost post, // The post object to add to.
552 const gsi_char * name, // The name to attach to this file.
553 const gsi_char * filename, // The name (and possibly path) to the file to upload.
554 const gsi_char * reportFilename,// The filename given to the web server.
555 const gsi_char * contentType // The MIME type for this file.
556);
557
558// Adds a file, in memory, to the post object.
559// The reportFilename is what is reported to the server as the filename.
560// Cannot be NULL or empty.
561// The contentType is the MIME type to report for this file.
562// If NULL, "application/octet-stream" is used.
563// The data is NOT copied off in this call. The data pointer is read from
564// as the data is actually sent to the server. The pointer must remain
565// valid during requests.
566// Returns false for any error.
568GHTTPBool ghttpPostAddFileFromMemory
569(
570 GHTTPPost post, // The post object to add to.
571 const gsi_char * name, // The name to attach to this string.
572 const char * buffer, // The data to send.
573 int bufferLen, // The number of bytes of data to send.
574 const gsi_char * reportFilename, // The filename given to the web server.
575 const gsi_char * contentType // The MIME type for this file.
576);
577
578// Adds an XML SOAP object to the post object.
579// See ghttpNewSoap and other Soap related functions
580// Content-Type = text/xml
581// The most common use of this function is to add ghttpSoap data
582GHTTPBool ghttpPostAddXml
583(
584 GHTTPPost post,
585 GSXmlStreamWriter xmlSoap
586);
587
588// Called during requests to let the app know how much of the post
589// data has been uploaded.
591typedef void (* ghttpPostCallback)
592(
593 GHTTPRequest request, // The request.
594 int bytesPosted, // The number of bytes of data posted so far.
595 int totalBytes, // The total number of bytes being posted.
596 int objectsPosted, // The total number of data objects uploaded so far.
597 int totalObjects, // The total number of data objects to upload.
598 void * param // User-data.
599);
600
601// Set the callback for a post object.
603void ghttpPostSetCallback
604(
605 GHTTPPost post, // The post object to set the callback on.
606 ghttpPostCallback callback, // The callback to call when using this post object.
607 void * param // User-data passed to the callback.
608);
609
610// Use ssl encryption engine
611GHTTPBool ghttpSetRequestEncryptionEngine
612(
613 GHTTPRequest request,
614 GHTTPEncryptionEngine engine
615);
616
617
618// These are defined for backwards compatibility with the "file" function names.
620#define ghttpGetFile(a, b, c, d) ghttpGet(a, b, c, d)
621#define ghttpGetFileEx(a, b, c, d, e, f, g, h, i, j) ghttpGetEx(a, b, c, d, e, f, g, h, i, j)
622#define ghttpSaveFile(a, b, c, d, e) ghttpSave(a, b, c, d, e)
623#define ghttpSaveFileEx(a, b, c, d, e, f, g, h, i) ghttpSaveEx(a, b, c, d, e, f, g, h, i)
624#define ghttpStreamFile(a, b, c, d, e) ghttpStream(a, b, c, d, e)
625#define ghttpStreamFileEx(a, b, c, d, e, f, g, h) ghttpStreamEx(a, b, c, d, e, f, g, h)
626#define ghttpHeadFile(a, b, c, d) ghttpHead(a, b, c, d)
627#define ghttpHeadFileEx(a, b, c, d, e, f, g) ghttpHeadEx(a, b, c, d, e, f, g)
628
629// This ASCII version needs to be define even in UNICODE mode
630GHTTPRequest ghttpGetA
631(
632 const char * URL, // The URL for the file ("http://host.domain[:port]/path/filename").
633 GHTTPBool blocking, // If true, this call doesn't return until the file has been recevied.
634 ghttpCompletedCallback completedCallback, // Called when the file has been received.
635 void * param // User-data to be passed to the callbacks.
636);
637#define ghttpGetFileA(a, b, c, d) ghttpGetA(a, b, c, d)
638
639
640#ifdef __cplusplus
641}
642#endif
643
644#endif
Definition ghttpPost.c:76
Definition puff.c:88