File: WWW.h

package info (click to toggle)
xmoto 0.5.11+dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 80,908 kB
  • sloc: cpp: 96,757; ansic: 22,196; sh: 4,940; makefile: 1,073; yacc: 289; sed: 16
file content (257 lines) | stat: -rw-r--r-- 8,615 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*=============================================================================
XMOTO

This file is part of XMOTO.

XMOTO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

XMOTO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XMOTO; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=============================================================================*/

/* file contributed by Nicolas Adenis-Lamarre */

#ifndef __WWW_H__
#define __WWW_H__

#include "BuildConfig.h"

#include <string>
#include <vector>
#include <stdio.h>
#include <curl/curl.h>

#include "WWWAppInterface.h"
#include "Theme.h"
#include "XMSession.h"
#include "XMBuild.h"
#include "VFileIO_types.h"

class ThemeChoice;

#define DEFAULT_WEBHIGHSCORES_URL         "http://xmoto.tuxfamily.org/highscores.xml"
#define DEFAULT_WEBHIGHSCORES_FILENAME_PREFIX    "webhighscores"
#define DEFAULT_TRANSFERT_TIMEOUT         240
#define DEFAULT_TRANSFERT_CONNECT_TIMEOUT 15
#define DEFAULT_WEBLEVELS_URL             "http://xmoto.tuxfamily.org/levels.xml"
#define DEFAULT_UPLOADDBSYNC_URL          "http://xmoto.tuxfamily.org/tools/UploadDbSync.php"
#define DEFAULT_WEBLEVELS_FILENAME        "weblevels.xml"
#define DEFAULT_WEBLEVELS_DIR             "downloaded"
#define DEFAULT_WEBTHEMES_URL             "http://xmoto.tuxfamily.org/themes.xml"
#define DEFAULT_WEBTHEMES_FILENAME        "webthemes.xml"
#define DEFAULT_WEBTHEMES_SPRITESURLBASE  "http://xmoto.tuxfamily.org/sprites"
#define DEFAULT_UPLOADREPLAY_URL          "http://xmoto.tuxfamily.org/tools/UploadReplay.php"
#define DEFAULT_SENDVOTE_URL              "http://xmoto.tuxfamily.org/tools/SendVote.php"
#define DEFAULT_SENDREPORT_URL            "http://xmoto.tuxfamily.org/tools/SendReport.php"
#define DEFAULT_WEBROOMS_URL              "http://xmoto.tuxfamily.org/rooms.xml"
#define DEFAULT_WEBROOMS_FILENAME         "webrooms.xml"
#define DEFAULT_WEBROOM_NAME              "WR"

#define WWW_AGENT ("xmoto-" + XMBuild::getVersionString(true))

struct f_curl_download_data {
  WWWAppInterface *v_WebApp;
  int v_nb_files_to_download;
  int v_nb_files_performed;
};

struct f_curl_upload_data {
  WWWAppInterface *v_WebApp;
};


class WebRoom;
class xmDatabase;

class FSWeb {
 public:
  static void downloadFile(const std::string &p_local_file,
			   const std::string &p_web_file,
			   int (*curl_progress_callback_download)(void *clientp,
								  double dltotal,
								  double dlnow,
								  double ultotal,
								  double ulnow),
			   void *p_data,
			   const ProxySettings *p_proxy_settings);

  static void downloadFileBz2(const std::string &p_local_file,
			      const std::string &p_web_file,
			      int (*curl_progress_callback_download)(void *clientp,
								     double dltotal,
								     double dlnow,
								     double ultotal,
								     double ulnow),
			      void *p_data,
			      const ProxySettings *p_proxy_settings);

  static void downloadFileBz2UsingMd5(const std::string &p_local_file,
				      const std::string &p_web_file,
				      int (*curl_progress_callback_download)(void *clientp,
									     double dltotal,
									     double dlnow,
									     double ultotal,
									     double ulnow),
				      void *p_data,
				      const ProxySettings *p_proxy_settings);

  static void uploadReplay(const std::string& p_replayFilename,
			   const std::string& p_id_room,
			   const std::string& p_login,
			   const std::string& p_password,
			   const std::string& p_url_to_transfert,
			   WWWAppInterface *p_WebApp,
			   const ProxySettings *p_proxy_settings,
			   bool &p_msg_status,
			   std::string &p_msg);

  static void uploadDbSync(const std::string& p_dbSyncFilename,
			   const std::string& p_login,
			   const std::string& p_password,
			   const std::string& p_siteKey,
			   int p_dbSyncServer,
			   const std::string& p_url_to_transfert,
			   WWWAppInterface *p_WebApp,
			   const ProxySettings *p_proxy_settings,
			   bool &p_msg_status,
			   std::string& p_msg,
			   const std::string& p_answerFile);

  static void sendVote(const std::string& p_id_level,
		       const std::string& p_difficulty_value,
		       const std::string& p_quality_value,
		       bool p_adminMode,
		       const std::string& p_id_profile,
		       const std::string& p_password,
		       const std::string& p_url_to_transfert,
		       WWWAppInterface *p_WebApp,
		       const ProxySettings *p_proxy_settings,
		       bool &p_msg_status,
		       std::string &p_msg);

  static void sendReport(const std::string& p_reportauthor,
			 const std::string& p_reportmsg,
			 const std::string& p_url_to_transfert,
			 WWWAppInterface *p_WebApp,
			 const ProxySettings *p_proxy_settings,
			 bool &p_msg_status,
			 std::string &p_msg);

  static int f_curl_progress_callback_upload(void *clientp,
					     double dltotal,
					     double dlnow,
					     double ultotal,
					     double ulnow);

  static int f_curl_progress_callback_download(void *clientp,
					       double dltotal,
					       double dlnow,
					       double ultotal,
					       double ulnow);

 private:
  static size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream);
  static void   uploadAnalyseMsg(const std::string& p_key,
				 const std::string& p_filename,
				 bool &p_msg_status_ok,
				 std::string &p_msg);

  static CURLcode performPostCurl(CURL *p_curl,
				  struct curl_httppost *p_post,
				  const std::string& p_url_to_transfert,
				  FILE* p_destinationFile,
				  WWWAppInterface *p_WebApp,
				  const ProxySettings *p_proxy_settings);
};

class WebRoom {
 public:
  WebRoom(WWWAppInterface* p_WebRoomApp);
  ~WebRoom();

  void update(const std::string& i_id_room); /* throws exceptions */
  void upgrade(const std::string& i_id_room, xmDatabase* i_db); /* throws exceptions */

  /* return NULL if no data found */
  void setProxy(const ProxySettings* pProxySettings);

  // only required for update and upgrade
  void setHighscoresUrl(const std::string& i_webhighscores_url);

  void downloadReplay(const std::string& i_url);
  bool downloadReplayExists(const std::string& i_url);

 private:
  WWWAppInterface* m_WebRoomApp;
  std::string m_userFilename_prefix;
  std::string m_webhighscores_url;
  const ProxySettings* m_proxy_settings;
};

class WebLevels {
 public:
  WebLevels(WWWAppInterface* p_WebLevelApp);
  ~WebLevels();

  /* check for new levels to download */
  void update(xmDatabase* i_db); /* throws exceptions */

  /* download new levels */
  void upgrade(xmDatabase* i_db, int i_nb_levels = -1 /* -1 for all levels */); /* throws exceptions */
  
  /* Get names of new files downloaded OK */
  const std::vector<std::string> &getNewDownloadedLevels();
  
  /* Get names of updated files downloaded OK*/
  const std::vector<std::string> &getUpdatedDownloadedLevels();
  
  /* Set URL */
  void setWebsiteInfos(const std::string &p_url, const ProxySettings* p_proxy_settings);

  static std::string getDestinationFile(std::string p_url);

  /* return the number of level files required to download for an upgrade */
  int nbLevelsToGet(xmDatabase *i_db) const;

 private:
  WWWAppInterface* m_WebLevelApp;

  std::vector<std::string> m_webLevelsNewDownloadedOK; /* file names of those levels 
           which where downloaded OK (so we can load them right away) and which are new */
  std::vector<std::string> m_webLevelsUpdatedDownloadedOK;

  const ProxySettings *m_proxy_settings;
  
  std::string m_levels_url;

  std::string getXmlFileName();
  void downloadXml(); /* throw exceptions */
  static std::string getDestinationDir();
  void createDestinationDirIfRequired();
};

class WebThemes {
 public:
  static void updateTheme(xmDatabase* i_pDb, const std::string& i_id_theme, WWWAppInterface* i_WebLevelApp);
  static void updateThemeList(xmDatabase* i_pDb, WWWAppInterface* i_WebLevelApp);
  static bool isUpdatable(xmDatabase* i_pDb, const std::string& i_id_theme);
};

class XMSync {
 public:
  static void syncUp(xmDatabase* i_pDb, const ProxySettings* pProxySettings,
		     const std::string& i_sitekey, const std::string& i_profile);
  static void syncDown();
};

#endif /* WEBSTUFFS */