OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
ghttpBuffer.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 _GHTTPBUFFER_H_
12#define _GHTTPBUFFER_H_
13
14#include "ghttpMain.h"
15#include "ghttpEncryption.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21// A data buffer.
23typedef struct GHIBuffer
24{
25 struct GHIConnection * connection; // The connection.
26 char * data; // The actual bytes of data.
27 int size; // The number of bytes allocated for data.
28 int len; // The number of actual data bytes filled in.
29 int pos; // A marker to keep track of position.
30 int sizeIncrement; // How much to increment the buffer by when needed.
31 GHTTPBool fixed; // If true, don't resize the buffer.
32 GHTTPBool dontFree; // Don't free the data when the buffer is cleaned up.
33 GHTTPBool readOnly; // Read Only, write operations will fail
34} GHIBuffer;
35
36// Initializes a buffer and allocates the initial data bytes.
37// The initialSize and sizeIncrement must both be >0.
39GHTTPBool ghiInitBuffer
40(
41 struct GHIConnection * connection, // The connection.
42 GHIBuffer * buffer, // The buffer to init.
43 int initialSize, // The initial size of the buffer.
44 int sizeIncrement // The size increment for the buffer.
45);
46
47// Initializes a fixed-size buffer. This will not get resized.
49GHTTPBool ghiInitFixedBuffer
50(
51 struct GHIConnection * connection, // The connection.
52 GHIBuffer * buffer, // The buffer to init.
53 char * userBuffer, // The user-buffer to use.
54 int size // The size of the buffer.
55);
56
57// Initializes a read-only fixed-size buffer. This will not get resized.
59GHTTPBool ghiInitReadOnlyBuffer
60(
61 struct GHIConnection * connection, // The connection.
62 GHIBuffer * buffer, // The buffer to init.
63 const char * userBuffer, // The user-buffer to use.
64 int size // The size of the buffer.
65);
66
67// Free's a buffer's allocated memory (does
68// not free the actual GHIBuffer structure).
70void ghiFreeBuffer
71(
72 GHIBuffer * buffer
73);
74
75// Appends data to the buffer.
76// If data is a NUL-terminated string, 0 can be
77// used for dataLen to use the length of the string.
79GHTTPBool ghiAppendDataToBuffer
80(
81 GHIBuffer * buffer, // The buffer to append to.
82 const char * data, // The data to append.
83 int dataLen // The number of bytes of data to append, 0 for NUL-terminated string.
84);
85
86// Appends data to the buffer, wrapped in an SSL record
87// If data is a NUL-terminated string, 0 can be
88// used for dataLen to use the length of the string.
89// Encryption has some size overhead, so call this sparingly.
91GHTTPBool ghiEncryptDataToBuffer
92(
93 GHIBuffer * buffer, // The buffer to append to.
94 const char * data, // The data to append.
95 int dataLen // The number of bytes of data to append, 0 for NUL-terminated string.
96);
97
98// Appends a header to the buffer.
99// Both the name and value must be NUL-terminated.
100// The header will be added to the buffer as:
101// <name>: <value>\n
103GHTTPBool ghiAppendHeaderToBuffer
104(
105 GHIBuffer * buffer, // The buffer to append to.
106 const char * name, // The name of the header.
107 const char * value // The value of the header.
108);
109
110// Appends a single character to the buffer.
112GHTTPBool ghiAppendCharToBuffer
113(
114 GHIBuffer * buffer, // The buffer to append to.
115 int c // The char to append.
116);
117
118// Read data from a buffer
119GHTTPBool ghiReadDataFromBuffer
120(
121 GHIBuffer * bufferIn, // the GHIBuffer to read from
122 char bufferOut[], // the raw buffer to write to
123 int * len // max number of bytes to append, becomes actual length written
124);
125
126// Read a fixed number of bytes from a buffer
127GHTTPBool ghiReadDataFromBufferFixed
128(
129 GHIBuffer * bufferIn,
130 char bufferOut[],
131 int len
132);
133
134// Converts the int to a string and appends it to the buffer.
136GHTTPBool ghiAppendIntToBuffer
137(
138 GHIBuffer * buffer, // The buffer to append to.
139 int i // The int to append.
140);
141
142// Resets a buffer.
143// Does this by setting both len and pos to 0.
145void ghiResetBuffer
146(
147 GHIBuffer * buffer // The buffer to reset.
148);
149
150// Sends as much buffer data as it can.
151// Returns false if there was an error.
153GHTTPBool ghiSendBufferedData
154(
155 struct GHIConnection * connection
156);
157
158// Increases the size of a buffer.
159// This happens automatically when using the ghiAppend* functions
160GHTTPBool ghiResizeBuffer
161(
162 GHIBuffer * buffer,
163 int sizeIncrement
164);
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif
Definition ghttpBuffer.h:24
Definition ghttpConnection.h:84