1 /**
2  * @file
3  */
4 
5 /*
6 Copyright (C) 1997-2001 Id Software, Inc.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 #include "common.h"
28 #ifndef NO_HTTP
29 #ifndef CURL_STATICLIB
30 #define CURL_STATICLIB
31 #endif
32 #include <curl/curl.h>
33 
34 typedef enum {
35 	DLQ_STATE_NOT_STARTED,
36 	DLQ_STATE_RUNNING,
37 	DLQ_STATE_DONE
38 } dlq_state;
39 
40 typedef struct dlqueue_s {
41 	struct dlqueue_s	*next;
42 	char				ufoPath[MAX_QPATH];
43 	dlq_state			state;
44 } dlqueue_t;
45 
46 typedef struct dlhandle_s {
47 	CURL		*curl;
48 	char		filePath[MAX_OSPATH];
49 	FILE		*file;
50 	dlqueue_t	*queueEntry;
51 	size_t		fileSize;
52 	size_t		position;
53 	double		speed;
54 	char		URL[576];
55 	char		*tempBuffer;
56 } dlhandle_t;
57 #endif
58 
59 typedef struct upparam_s {
60 	const char* name;
61 	const char* value;
62 	struct upparam_s* next;
63 } upparam_t;
64 
65 typedef void (*http_callback_t) (const char* response, void* userdata);
66 
67 bool HTTP_Encode(const char* url, char* out, size_t outLength);
68 bool HTTP_GetToFile(const char* url, FILE* file, const char* postfields = nullptr);
69 bool HTTP_GetURL(const char* url, http_callback_t callback, void* userdata = nullptr, const char* postfields = nullptr);
70 bool HTTP_PutFile(const char* formName, const char* fileName, const char* url, const upparam_t* params);
71 size_t HTTP_Recv(void* ptr, size_t size, size_t nmemb, void* stream);
72 size_t HTTP_Header(void* ptr, size_t size, size_t nmemb, void* stream);
73 void HTTP_Cleanup(void);
74 bool HTTP_ExtractComponents(const char* url, char* server, size_t serverLength, char* path, size_t pathLength, int* port);
75