OpenClonk
C4Network2UpdateClient Class Reference

#include <C4Network2Reference.h>

Inheritance diagram for C4Network2UpdateClient:
[legend]
Collaboration diagram for C4Network2UpdateClient:
[legend]

Public Types

enum  ResponseType { NoPreference , XML }
 

Public Member Functions

 C4Network2UpdateClient ()
 
bool QueryUpdateURL ()
 
bool GetUpdateURL (StdStrBuf *pUpdateURL)
 
bool GetVersion (StdStrBuf *pVersion)
 
bool Init ()
 
bool Query (const StdBuf &Data, bool fBinary)
 
bool Query (const char *szData, bool fBinary)
 
bool isBusy () const
 
bool isConnected () const
 
bool isSuccess () const
 
size_t getTotalSize () const
 
size_t getDownloadedSize () const
 
const StdBufgetResultBin () const
 
const char * getResultString () const
 
const char * getURL () const
 
const char * getServerName () const
 
const C4NetIO::addr_tgetServerAddress () const
 
virtual const char * GetError () const
 
void ResetError ()
 
void Cancel (const char *szReason)
 
void Clear ()
 
bool SetServer (const char *szServerAddress)
 
void SetExpectedResponseType (ResponseType type)
 
void SetNotify (class C4InteractiveThread *pnNotify)
 
bool Execute (int iMaxTime=-1, pollfd *readyfds=nullptr) override
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow) override
 
void GetFDs (std::vector< struct pollfd > &) override
 
bool ExecuteUntil (int iTimeout=-1)
 
bool IsSignaled ()
 
virtual bool IsLowPriority ()
 
virtual bool IsNotify ()
 
virtual uint32_t TimerInterval ()
 

Protected Member Functions

void SetError (const char *strnError)
 
void Changed ()
 

Protected Attributes

StdCopyBuf ResultBin
 
StdCopyStrBuf ResultString
 
StdCopyStrBuf Error
 

Detailed Description

Definition at line 124 of file C4Network2Reference.h.

Member Enumeration Documentation

◆ ResponseType

Enumerator
NoPreference 
XML 

Definition at line 103 of file C4HTTP.h.

103 { NoPreference, XML };
@ NoPreference
Definition: C4HTTP.h:103

Constructor & Destructor Documentation

◆ C4Network2UpdateClient()

C4Network2UpdateClient::C4Network2UpdateClient ( )
inline

Definition at line 127 of file C4Network2Reference.h.

127 : C4HTTPClient() {}
C4HTTPClient()
Definition: C4HTTP.cpp:27

Member Function Documentation

◆ Cancel()

void C4HTTPClient::Cancel ( const char *  szReason)
inherited

Definition at line 277 of file C4HTTP.cpp.

278 {
279  if (CurlHandle)
280  {
281  curl_multi_remove_handle(MultiHandle, CurlHandle);
282  curl_easy_cleanup(CurlHandle);
283  CurlHandle = nullptr;
284  }
285  fBinary = false;
286  iDownloadedSize = iTotalSize = 0;
287  Error = szReason;
288 }
StdCopyStrBuf Error
Definition: C4HTTP.h:79

References C4HTTPClient::Error.

Referenced by C4HTTPClient::Clear(), C4StartupNetListEntry::Execute(), C4HTTPClient::Query(), C4DownloadDlg::UserClose(), and C4HTTPClient::~C4HTTPClient().

Here is the caller graph for this function:

◆ Changed()

void StdSchedulerProc::Changed ( )
protectedinherited

Definition at line 108 of file StdScheduler.cpp.

109 {
110  auto s = scheduler;
111  if (s)
112  s->Changed(this);
113 }
#define s

References s.

Referenced by C4NetIOTCP::Accept(), C4NetIOTCP::AddConnectWait(), C4NetIOUDP::AddPeer(), C4NetIOTCP::Listen(), and CStdTimerProc::SetDelay().

Here is the caller graph for this function:

◆ Clear()

void C4HTTPClient::Clear ( )
inherited

Definition at line 290 of file C4HTTP.cpp.

291 {
292  Cancel(nullptr);
293  ServerAddr.Clear();
294  ResultBin.Clear();
296 }
StdCopyStrBuf ResultString
Definition: C4HTTP.h:78
StdCopyBuf ResultBin
Definition: C4HTTP.h:77
void Cancel(const char *szReason)
Definition: C4HTTP.cpp:277
void Clear()
Definition: StdBuf.h:190
void Clear()
Definition: StdBuf.h:466

References C4HTTPClient::Cancel(), StdBuf::Clear(), StdStrBuf::Clear(), C4NetIO::EndpointAddress::Clear(), C4HTTPClient::ResultBin, and C4HTTPClient::ResultString.

Referenced by C4Network2::StreamOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute()

bool C4HTTPClient::Execute ( int  iMaxTime = -1,
pollfd *  readyfds = nullptr 
)
overridevirtualinherited

Implements StdSchedulerProc.

Definition at line 59 of file C4HTTP.cpp.

60 {
61  int running;
62 #ifdef STDSCHEDULER_USE_EVENTS
63  // On Windows, StdScheduler doesn't inform us about which fd triggered the
64  // event, so we have to check manually.
65  if (WaitForSingleObject(Event, 0) == WAIT_OBJECT_0)
66  {
67  // sockets might be modified during the call to curl_multi_socket_action() below.
68  auto sockets_tmp = sockets;
69  for (const auto& kv : sockets_tmp)
70  {
71  auto socket = kv.first;
72  WSANETWORKEVENTS NetworkEvents;
73  if (WSAEnumNetworkEvents(socket, Event, &NetworkEvents) != SOCKET_ERROR)
74  {
75  int ev_bitmask = 0;
76  if (NetworkEvents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE)) ev_bitmask |= CURL_CSELECT_IN;
77  if (NetworkEvents.lNetworkEvents & (FD_WRITE|FD_CONNECT)) ev_bitmask |= CURL_CSELECT_OUT;
78  curl_multi_socket_action(MultiHandle, socket, ev_bitmask, &running);
79  }
80  }
81  }
82 #else
83  if (readyfd)
84  {
85  int ev_bitmask = 0;
86  if (readyfd->revents & POLLIN) ev_bitmask |= CURL_CSELECT_IN;
87  if (readyfd->revents & POLLOUT) ev_bitmask |= CURL_CSELECT_OUT;
88  if (readyfd->revents & POLLERR) ev_bitmask |= CURL_CSELECT_ERR;
89  curl_multi_socket_action(MultiHandle, readyfd->fd, ev_bitmask, &running);
90  }
91 #endif
92  else
93  {
94  curl_multi_socket_action(MultiHandle, CURL_SOCKET_TIMEOUT, 0, &running);
95  }
96 
97  CURLMsg *m;
98  do {
99  int msgq = 0;
100  m = curl_multi_info_read(MultiHandle, &msgq);
101  if(m && (m->msg == CURLMSG_DONE)) {
102  CURL *e = m->easy_handle;
103  assert(e == CurlHandle);
104  CurlHandle = nullptr;
105  curl_multi_remove_handle(MultiHandle, e);
106 
107  // Check for errors and notify listeners. Note that curl fills
108  // the Error buffer automatically.
109  fSuccess = m->data.result == CURLE_OK;
110  if (!fSuccess && !*Error.getData())
111  Error.Copy(curl_easy_strerror(m->data.result));
112  char *ip;
113  curl_easy_getinfo(e, CURLINFO_PRIMARY_IP, &ip);
114  ServerAddr.SetHost(StdStrBuf(ip));
115  if (pNotify)
116  pNotify->PushEvent(Ev_HTTP_Response, this);
117 
118  curl_easy_cleanup(e);
119  }
120  } while(m);
121 
122  return true;
123 }
@ Ev_HTTP_Response
#define SOCKET_ERROR
Definition: C4NetIO.cpp:47
bool PushEvent(C4InteractiveEventType eEventType, void *pData=nullptr)
const char * getData() const
Definition: StdBuf.h:442
void Copy()
Definition: StdBuf.h:467
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346

References StdStrBuf::Copy(), C4HTTPClient::Error, Ev_HTTP_Response, StdStrBuf::getData(), C4InteractiveThread::PushEvent(), C4NetIO::HostAddress::SetHost(), and SOCKET_ERROR.

Referenced by C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueWaitNotBusy(), and C4DownloadDlg::OnIdle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExecuteUntil()

bool StdSchedulerProc::ExecuteUntil ( int  iTimeout = -1)
inherited

Definition at line 33 of file StdScheduler.cpp.

34 {
35  // Infinite?
36  if (iTimeout < 0)
37  for (;;)
38  if (!Execute())
39  return false;
40  // Calculate endpoint
41  C4TimeMilliseconds tStopTime = C4TimeMilliseconds::Now() + iTimeout;
42  for (;;)
43  {
44  // Call execute with given timeout
45  if (!Execute(std::max(iTimeout, 0)))
46  return false;
47  // Calculate timeout
49  if (tTime >= tStopTime)
50  break;
51  iTimeout = tStopTime - tTime;
52  }
53  // All ok.
54  return true;
55 }
static C4TimeMilliseconds Now()
virtual bool Execute(int iTimeout=-1, pollfd *readyfds=nullptr)=0

References StdSchedulerProc::Execute(), and C4TimeMilliseconds::Now().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDownloadedSize()

size_t C4HTTPClient::getDownloadedSize ( ) const
inlineinherited

Definition at line 90 of file C4HTTP.h.

90 { return iDownloadedSize; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ GetError()

virtual const char* C4HTTPClient::GetError ( ) const
inlinevirtualinherited

Definition at line 96 of file C4HTTP.h.

96 { return Error.getData(); }

References C4HTTPClient::Error, and StdStrBuf::getData().

Referenced by C4DownloadDlg::GetError(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueUpdate(), C4Network2::LeagueUpdateProcessReply(), C4StartupNetListEntry::OnReference(), and C4StartupNetListEntry::SetRefQuery().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFDs()

void C4HTTPClient::GetFDs ( std::vector< struct pollfd > &  pollfds)
overridevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 135 of file C4HTTP.cpp.

136 {
137  for (const auto& kv : sockets)
138  {
139  pollfd pfd;
140  pfd.fd = kv.first;
141  pfd.revents = 0;
142  switch (kv.second)
143  {
144  case CURL_POLL_IN:
145  pfd.events = POLLIN; break;
146  case CURL_POLL_OUT:
147  pfd.events = POLLOUT; break;
148  case CURL_POLL_INOUT:
149  pfd.events = POLLIN | POLLOUT; break;
150  default:
151  pfd.events = 0;
152  }
153  pollfds.push_back(pfd);
154  }
155 }

◆ GetNextTick()

C4TimeMilliseconds C4HTTPClient::GetNextTick ( C4TimeMilliseconds  tNow)
overridevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 125 of file C4HTTP.cpp.

126 {
127  long timeout;
128  curl_multi_timeout(MultiHandle, &timeout);
129  if (timeout < 0)
130  timeout = 1000;
131  return tNow + timeout;
132 }

◆ getResultBin()

const StdBuf& C4HTTPClient::getResultBin ( ) const
inlineinherited

Definition at line 91 of file C4HTTP.h.

91 { assert(fBinary); return ResultBin; }

References C4HTTPClient::ResultBin.

Referenced by C4DownloadDlg::ShowModal().

Here is the caller graph for this function:

◆ getResultString()

const char* C4HTTPClient::getResultString ( ) const
inlineinherited

Definition at line 92 of file C4HTTP.h.

92 { assert(!fBinary); return ResultString.getData(); }

References StdStrBuf::getData(), and C4HTTPClient::ResultString.

Here is the call graph for this function:

◆ getServerAddress()

const C4NetIO::addr_t& C4HTTPClient::getServerAddress ( ) const
inlineinherited

Definition at line 95 of file C4HTTP.h.

95 { return ServerAddr; }

Referenced by C4Network2RefClient::GetReferences().

Here is the caller graph for this function:

◆ getServerName()

const char* C4HTTPClient::getServerName ( ) const
inlineinherited

Definition at line 94 of file C4HTTP.h.

94 { return ServerName.getData(); }

References StdStrBuf::getData().

Referenced by C4StartupNetListEntry::GetJoinAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), and C4StartupNetListEntry::SetRefQuery().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTotalSize()

size_t C4HTTPClient::getTotalSize ( ) const
inlineinherited

Definition at line 89 of file C4HTTP.h.

89 { return iTotalSize; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ GetUpdateURL()

bool C4Network2UpdateClient::GetUpdateURL ( StdStrBuf pUpdateURL)

Definition at line 244 of file C4Network2Reference.cpp.

245 {
246  // Sanity check
247  if (isBusy() || !isSuccess()) return false;
248  // Parse response
249  try
250  {
251  CompileFromBuf<StdCompilerINIRead>(mkNamingAdapt(
252  mkNamingAdapt(mkParAdapt(*pUpdateURL, StdCompiler::RCT_All), "UpdateURL", ""),
253  C4ENGINENAME), ResultString);
254  }
255  catch (StdCompiler::Exception *pExc)
256  {
257  SetError(pExc->Msg.getData());
258  return false;
259  }
260  // done; version OK!
261  return true;
262 }
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void SetError(const char *strnError)
Definition: C4HTTP.h:80
bool isSuccess() const
Definition: C4HTTP.h:88
bool isBusy() const
Definition: C4HTTP.h:86

References StdStrBuf::getData(), C4HTTPClient::isBusy(), C4HTTPClient::isSuccess(), mkNamingAdapt(), mkParAdapt(), StdCompiler::Exception::Msg, StdCompiler::RCT_All, C4HTTPClient::ResultString, and C4HTTPClient::SetError().

Here is the call graph for this function:

◆ getURL()

const char* C4HTTPClient::getURL ( ) const
inlineinherited

Definition at line 93 of file C4HTTP.h.

93 { return URL.getData(); }

References StdStrBuf::getData().

Referenced by C4DownloadDlg::OnIdle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetVersion()

bool C4Network2UpdateClient::GetVersion ( StdStrBuf pVersion)

Definition at line 264 of file C4Network2Reference.cpp.

265 {
266  // Sanity check
267  if (isBusy() || !isSuccess()) return false;
268  // Parse response
269  try
270  {
271  CompileFromBuf<StdCompilerINIRead>(mkNamingAdapt(
272  mkNamingAdapt(mkParAdapt(*pVersion, StdCompiler::RCT_All), "Version", ""),
273  C4ENGINENAME), ResultString);
274  }
275  catch (StdCompiler::Exception *pExc)
276  {
277  SetError(pExc->Msg.getData());
278  return false;
279  }
280  // done; version OK!
281  return true;
282 }

References StdStrBuf::getData(), C4HTTPClient::isBusy(), C4HTTPClient::isSuccess(), mkNamingAdapt(), mkParAdapt(), StdCompiler::Exception::Msg, StdCompiler::RCT_All, C4HTTPClient::ResultString, and C4HTTPClient::SetError().

Here is the call graph for this function:

◆ Init()

bool C4HTTPClient::Init ( )
inherited

Definition at line 42 of file C4HTTP.cpp.

43 {
44  MultiHandle = curl_multi_init();
45  if (!MultiHandle) return false;
46 #ifdef STDSCHEDULER_USE_EVENTS
47  if ((Event = WSACreateEvent()) == WSA_INVALID_EVENT)
48  {
49  SetError("could not create socket event");
50  curl_multi_cleanup(MultiHandle);
51  return false;
52  }
53 #endif
54  curl_multi_setopt(MultiHandle, CURLMOPT_SOCKETFUNCTION, &C4HTTPClient::SSocketCallback);
55  curl_multi_setopt(MultiHandle, CURLMOPT_SOCKETDATA, this);
56  return true;
57 }

References C4HTTPClient::SetError().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StartStreaming().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBusy()

bool C4HTTPClient::isBusy ( ) const
inlineinherited

◆ isConnected()

bool C4HTTPClient::isConnected ( ) const
inlineinherited

Definition at line 87 of file C4HTTP.h.

87 { return iDownloadedSize + iTotalSize != 0; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ IsLowPriority()

virtual bool StdSchedulerProc::IsLowPriority ( )
inlinevirtualinherited

Definition at line 82 of file StdScheduler.h.

82 { return false; }

◆ IsNotify()

virtual bool StdSchedulerProc::IsNotify ( )
inlinevirtualinherited

Reimplemented in CStdNotifyProc, and C4NetIO.

Definition at line 83 of file StdScheduler.h.

83 { return false; }

◆ IsSignaled()

bool StdSchedulerProc::IsSignaled ( )
inherited

◆ isSuccess()

bool C4HTTPClient::isSuccess ( ) const
inlineinherited

Definition at line 88 of file C4HTTP.h.

88 { return fSuccess; }

Referenced by C4Network2RefClient::GetReferences(), C4LeagueClient::GetStartReply(), GetUpdateURL(), GetVersion(), C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueUpdateProcessReply(), C4DownloadDlg::OnIdle(), C4StartupNetListEntry::OnReference(), and C4Network2::StreamOut().

Here is the caller graph for this function:

◆ Query() [1/2]

bool C4HTTPClient::Query ( const char *  szData,
bool  fBinary 
)
inlineinherited

Definition at line 84 of file C4HTTP.h.

84 { return Query(StdBuf(szData, SLen(szData)), fBinary); }
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool Query(const StdBuf &Data, bool fBinary)
Definition: C4HTTP.cpp:158
Definition: StdBuf.h:30

References C4HTTPClient::Query(), and SLen().

Referenced by C4HTTPClient::Query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Query() [2/2]

bool C4HTTPClient::Query ( const StdBuf Data,
bool  fBinary 
)
inherited

Definition at line 158 of file C4HTTP.cpp.

159 {
160  if (URL.isNull()) return false;
161  // Cancel previous request
162  if (CurlHandle)
163  Cancel("Cancelled");
164  // No result known yet
166  // store mode
167  this->fBinary = fBinary;
168  // Create request
169  CURL *curl = curl_easy_init();
170  if (!curl) return false;
171 #ifdef C4HTTP_DEBUG
172  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
173 #endif
174  curl_easy_setopt(curl, CURLOPT_URL, URL.getData());
175  curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
176  curl_easy_setopt(curl, CURLOPT_USERAGENT, C4ENGINENAME "/" C4VERSION );
177  curl_easy_setopt(curl, CURLOPT_TIMEOUT, C4HTTPQueryTimeout);
178  curl_slist *headers = nullptr;
179  headers = curl_slist_append(headers, "Accept-Charset: utf-8");
180  headers = curl_slist_append(headers, FormatString("Accept-Language: %s", Config.General.LanguageEx).getData());
181  if (!headerAcceptedResponseType.empty())
182  headers = curl_slist_append(headers, headerAcceptedResponseType.c_str());
183 
184  if (Data.getSize())
185  {
186  RequestData = Data;
187  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, RequestData.getData());
188  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, RequestData.getSize());
189  // Disable the Expect: 100-Continue header which curl automatically
190  // adds for POST requests.
191  headers = curl_slist_append(headers, "Expect:");
192  headers = curl_slist_append(headers, "Content-Type: text/plain; charset=utf-8");
193  }
194 
195  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
196  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &C4HTTPClient::SWriteCallback);
197  curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
198  curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &C4HTTPClient::SProgressCallback);
199  curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this);
200  Error.Clear();
201  Error.SetLength(CURL_ERROR_SIZE);
202  *Error.getMData() = '\0';
203  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, Error.getMData());
204 
205  curl_multi_add_handle(MultiHandle, curl);
206  CurlHandle = curl;
207  iDownloadedSize = iTotalSize = 0;
208 
209  int running;
210  curl_multi_socket_action(MultiHandle, CURL_SOCKET_TIMEOUT, 0, &running);
211 
212  return true;
213 }
C4Config Config
Definition: C4Config.cpp:930
const int C4HTTPQueryTimeout
Definition: C4HTTP.h:30
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
C4ConfigGeneral General
Definition: C4Config.h:255
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
void SetLength(size_t iLength)
Definition: StdBuf.h:509
char * getMData()
Definition: StdBuf.h:443
bool isNull() const
Definition: StdBuf.h:441

References C4HTTPQueryTimeout, C4HTTPClient::Cancel(), StdStrBuf::Clear(), Config, C4HTTPClient::Error, FormatString(), C4Config::General, StdBuf::getData(), StdStrBuf::getData(), StdStrBuf::getMData(), StdBuf::getSize(), StdStrBuf::isNull(), C4ConfigGeneral::LanguageEx, C4HTTPClient::ResultString, and StdStrBuf::SetLength().

Referenced by C4LeagueClient::Auth(), C4LeagueClient::AuthCheck(), C4LeagueClient::End(), C4Network2RefClient::QueryReferences(), QueryUpdateURL(), C4LeagueClient::ReportDisconnect(), C4DownloadDlg::ShowModal(), C4LeagueClient::Start(), C4Network2::StreamOut(), and C4LeagueClient::Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ QueryUpdateURL()

bool C4Network2UpdateClient::QueryUpdateURL ( )

Definition at line 238 of file C4Network2Reference.cpp.

239 {
240  // Perform an Query query
241  return Query(nullptr, false);
242 }

References C4HTTPClient::Query().

Referenced by C4StartupNetDlg::CheckVersionUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetError()

void C4HTTPClient::ResetError ( )
inlineinherited

Definition at line 97 of file C4HTTP.h.

97 { Error.Clear(); }

References StdStrBuf::Clear(), and C4HTTPClient::Error.

Referenced by C4Network2RefClient::GetReferences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetError()

void C4HTTPClient::SetError ( const char *  strnError)
inlineprotectedinherited

Definition at line 80 of file C4HTTP.h.

80 { Error = strnError; }

References C4HTTPClient::Error.

Referenced by C4Network2RefClient::GetReferences(), GetUpdateURL(), GetVersion(), C4HTTPClient::Init(), and C4HTTPClient::SetServer().

Here is the caller graph for this function:

◆ SetExpectedResponseType()

void C4HTTPClient::SetExpectedResponseType ( C4HTTPClient::ResponseType  type)
inherited

Definition at line 315 of file C4HTTP.cpp.

316 {
317  switch (type)
318  {
319  case C4HTTPClient::ResponseType::XML:
320  headerAcceptedResponseType = "Accept: application/xml";
321  break;
322  case C4HTTPClient::ResponseType::NoPreference: // fallthrough
323  default:
324  headerAcceptedResponseType = "";
325  break;
326  };
327 }

◆ SetNotify()

void C4HTTPClient::SetNotify ( class C4InteractiveThread pnNotify)
inlineinherited

Definition at line 106 of file C4HTTP.h.

106 { pNotify = pnNotify; }

Referenced by C4StartupNetDlg::CheckVersionUpdate(), and C4StartupNetListEntry::SetRefQuery().

Here is the caller graph for this function:

◆ SetServer()

bool C4HTTPClient::SetServer ( const char *  szServerAddress)
inherited

Definition at line 298 of file C4HTTP.cpp.

299 {
300  static std::regex HostnameRegex(R"(^(:?[a-z]+:\/\/)?([^/:]+).*)", std::regex::icase);
301  std::cmatch match;
302  if (std::regex_match(szServerAddress, match, HostnameRegex))
303  {
304  // CURL validates URLs only on connect.
305  URL.Copy(szServerAddress);
306  ServerName.Copy(match[2].str().c_str());
307  return true;
308  }
309  // The HostnameRegex above is pretty stupid, so we will reject only very
310  // malformed URLs immediately.
311  SetError("Malformed URL");
312  return false;
313 }

References StdStrBuf::Copy(), and C4HTTPClient::SetError().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StreamOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TimerInterval()

virtual uint32_t StdSchedulerProc::TimerInterval ( )
inlinevirtualinherited

Reimplemented in CStdTimerProc.

Definition at line 84 of file StdScheduler.h.

84 { return 0; }

Member Data Documentation

◆ Error

◆ ResultBin

StdCopyBuf C4HTTPClient::ResultBin
protectedinherited

Definition at line 77 of file C4HTTP.h.

Referenced by C4HTTPClient::Clear(), and C4HTTPClient::getResultBin().

◆ ResultString


The documentation for this class was generated from the following files: