added function to create HTTP response object from buffer
[rocksndiamonds.git] / src / libgame / http.h
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2021 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // http.h
10 // ============================================================================
11
12 #ifndef HTTP_H
13 #define HTTP_H
14
15 #include "system.h"
16
17 #define MAX_HTTP_HEAD_SIZE              4096
18 #define MAX_HTTP_BODY_SIZE              1048576
19 #define MAX_HTTP_ERROR_SIZE             1024
20
21 #define HTTP_SUCCESS(c)                 ((c) >= 200 && (c) < 300)
22
23
24 struct HttpRequest
25 {
26   char head[MAX_HTTP_HEAD_SIZE + 1];
27   char body[MAX_HTTP_BODY_SIZE + 1];
28
29   char *hostname;
30   int port;
31   char *method;
32   char *uri;
33 };
34
35 struct HttpResponse
36 {
37   char head[MAX_HTTP_HEAD_SIZE + 1];
38   char body[MAX_HTTP_BODY_SIZE + 1];
39   int body_size;
40
41   int status_code;
42   char status_text[MAX_HTTP_ERROR_SIZE + 1];
43 };
44
45
46 char *GetHttpError(void);
47 void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *);
48 void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *);
49 struct HttpResponse *GetHttpResponseFromBuffer(void *, int);
50 boolean DoHttpRequest(struct HttpRequest *, struct HttpResponse *);
51
52 #endif