AMXX-BG.INFO httpx.inc Raw include

httpx.inc

Original include source with line numbers.

Back Download .inc
1 #if defined _HTTPX_included
2 #endinput
3 #endif
4 #define _HTTPX_included
5
6 enum {
7 REQUEST_GET,
8 REQUEST_POST
9 }
10
11 /**
12 * HTTPX_IsFilesizeLarge(DownloadID)
13 *
14 * If the filesize in bytes is beyond the limitations of integers the function will return true.
15 **/
16 native bool:HTTPX_IsFilesizeLarge(DownloadID)
17
18 /**
19 * HTTPX_GetBytesReceived(DownloadID)
20 *
21 * Returns total ammount of bytes received for DownloadID.
22 **/
23 native HTTPX_GetBytesReceived(DownloadID)
24
25 /**
26 * HTTPX_GetBytesReceivedLarge(DownloadID, string[], len)
27 *
28 * Formats total ammount of bytes received for DownloadID in string form.
29 **/
30 native HTTPX_GetBytesReceivedLarge(DownloadID, string[], len)
31
32 /**
33 * HTTPX_GetNewBytesReceived()
34 *
35 * Returns the ammount of bytes that was received in this chunk.
36 **/
37 native HTTPX_GetNewBytesReceived()
38
39 /**
40 * HTTPX_GetFilesize(DownloadID)
41 *
42 * Returns the filesize of DownloadID.
43 * If unknown it will return -1.
44 **/
45 native HTTPX_GetFilesize(DownloadID)
46
47 /**
48 * HTTPX_GetFilesizeLarge(DownloadID, string[], len)
49 *
50 * Formats the large filesize of DownloadID in string form.
51 **/
52 native HTTPX_GetFilesizeLarge(DownloadID, string[], len)
53
54 /**
55 * HTTPX_GetFilename(DownloadID)
56 *
57 * Returns the filename of DownloadID.
58 **/
59 native HTTPX_GetFilename(DownloadID, name[], len)
60
61 /**
62 * HTTPX_GetData(data[], len)
63 *
64 * Fills variable data[] with the last chunk downloaded.
65 *
66 * len decides maxlen for the data[] variable.
67 * Remember, this is raw data.
68 * No need to make room for null at the end unless you're passing it to any function that is
69 * trying to automatically find the end by searching for null (any string function).
70 *
71 * The function will return the ammount of bytes that was written to the data[] variable.
72 *
73 * By looping this function until it returns 0, you can get all the data.
74 **/
75 native HTTPX_GetData(data[], len)
76
77 /**
78 * Automatic updating
79 * Updates current plugin automatically (from AlliedModders webpage only to prevent spreading of malicious code).
80 *
81 *
82 * file_id[] has to be the same as it is on the forum webpage. (Check the link of the .amxx file ("Get Plugin" link))
83 *
84 *
85 * If frequency is supplied you can set how often to update the file. If none is provided it will update as soon as possible.
86 * Please use this respectfully. Don't overload the AM forums.
87 *
88 * You can however provide your own method of determining whether the file needs to be updated or not before calling this function.
89 * That way you don't stress AM servers when not required. An example of this is in the HTTPX source which uses this method.
90 *
91 * Examples:
92 * 1d = 86400
93 * 1w = 604800
94 * 30d = 2592000
95 *
96 *
97 * IMPORTANT!
98 * The reason for this not being a native is that it does not halt the plugin if HTTPX is not running. HTTPX and automatic updating is optional.
99 * Use this example instead. the File ID is the attachment in your post on the AM forums. Only use the ID, not the whole URL.
100 * For example:
101 * The plugin Name Replacer by anakin_cstrike, @http://forums.alliedmods.net/showthread.php?t=77401&highlight=replacer
102 * Scroll down and hover the "Get Plugin", there you see the file ID. Just replace the placeholder with that value.
103 * #define AUTOUPDATE_FILE_ID "76775"
104 * Add the time or create your own method of deciding when it's supposed to be updated and you're done.
105
106 #define AUTOUPDATE_FILE_ID "REPLACE_THIS_WITH_YOUR_FILE_ID"
107 #define AUTOUPDATE_HOW_OFTEN REPLACE_THIS_WITH_DESIRED_FREQUENCY // 1d = 86400, 1w = 604800, 30d = 2592000
108
109 UpdatePlugin() {
110 if ( callfunc_begin("AutoupdatePlugin", "httpx.amxx") == 1 ) { // Don't touch.
111 callfunc_push_int(get_plugin(-1)) // Plugin ID (to get the filename). Don't touch.
112 callfunc_push_str(AUTOUPDATE_FILE_ID, false) // The file_id in string format. Touch above.
113 callfunc_push_int(AUTOUPDATE_HOW_OFTEN) // Frequency of the automatic updates. Touch above.
114 callfunc_end() // Don't touch.
115 }
116 }
117
118 **/
119
120 /**
121 * bool:HTTPX_IsPaused(DownloadID)
122 *
123 * Returns true if the download is paused. Otherwise returns false.
124 **/
125 native bool:HTTPX_IsPaused(DownloadID)
126
127 /**
128 * HTTPX_Paused(DownloadID)
129 *
130 * Pauses the download.
131 **/
132 native HTTPX_Pause(DownloadID)
133
134 /**
135 * HTTPX_Unpause(DownloadID)
136 *
137 * Unpauses the download.
138 **/
139 native HTTPX_Unpause(DownloadID)
140
141 /**
142 * HTTPX_Abort(DownloadID, bool:DeleteFile = true)
143 *
144 * Aborts the transfer of selected download DownloadID.
145 * If DeleteFile is set to true the partially downloaded file will be deleted.
146 **/
147 native HTTPX_Abort(DownloadID, bool:DeleteFile = true)
148
149 /**
150 * HTTPX_AddPostVar(const variable[], const value[])
151 *
152 * Adds a POST variable to the request.
153 * This function is used before HTTPX_Download() or HTTP_AddToQue(), similar to set/show hudmessage.
154 * It can be used multiple times before each download.
155 **/
156 native HTTPX_AddPostVar(const variable[], const value[])
157
158 /**
159 * HTTPX_AddPostRaw(const data[])
160 *
161 * Adds raw POST data to the request.
162 * This function is used before HTTPX_Download() or HTTP_AddToQue(), similar to set/show hudmessage.
163 * It can be used multiple times before each download.
164 **/
165 native HTTPX_AddPostRaw(const data[])
166
167 /**
168 * Number of parameters for the callbacks are 1 (DownloadID) for the progress event and 2 (DownloadID, Error) for the complete event.
169 * Error codes:
170 * 0 Download done. No problems encountered.
171 * Positive returns is unhandled HTTP return codes. For example 404.
172 * Negative is internal errors.
173 * -1 No response code was found in the HTTP response header or it was outside the accepted range (200-307).
174 * -2 Server is sending bad data or sizes for a chunked transfer or HTTPX has problems reading them.
175 * -3 Nothing received in last packet. Most likely due to an error.
176 * -4 HTTPX was redirected but could not follow due to a socket error.
177 * -5 HTTPX was redirected too many times. Usually happens when server is insisting on a SSL/TLS connection which HTTPX does not support.
178 **/
179
180 /**
181 * HTTPX_Download(const URL[], const Filename[] = "", const CompleteHandler[] = "", const ProgressHandler[] = "", Port = (80<<443), RequestType = REQUEST_GET, const Username[] = "", const Password[] = "", ...)
182 *
183 * Begins download of a URL. Read parameters for information.
184 *
185 *
186 * Parameters:
187 *
188 * const URL[]
189 * URL that you want to download.
190 *
191 * (Optional) const Filename[]
192 * Where should the information be stored? If no filename is entered it will download as a "stream".
193 * This means the data will be thrown away after it passes the buffer.
194 * You can read the data on progress forward and make use of it there.
195 *
196 * (Optional) const CompleteHandler[] = ""
197 * The function you want called when the download is complete.
198 *
199 * (Optional) const ProgressHandler[] = ""
200 * The function you want called when the download is in progress.
201 * This will be called every time data is downloaded.
202 *
203 * (Optional) Port = 0
204 * The port that should be used.
205 * If this is left at default it will use 80 for http and 443 for https (when supported).
206 *
207 * (Optional) RequestType = REQUEST_GET
208 * What type of request should be used.
209 * If this is left at default it will use GET.
210 * Possible values so far are REQUEST_GET and REQUEST_POST.
211 *
212 * (Optional) const Username[] = ""
213 * (Optional) const Password[] = ""
214 * These are used to login to sites that require you to.
215 * It's only used for Basic authentication, not POST for example.
216 *
217 * Returns an DownloadID of the download that may be used to abort the download.
218 **/
219 native HTTPX_Download(const URL[], const Filename[] = "", const CompleteHandler[] = "", const ProgressHandler[] = "", Port = 0, RequestType = REQUEST_GET, const Username[] = "", const Password[] = "", ... /* For possible future use */)
220