Codechange: Use null pointer literal instead of the NULL macro
This commit is contained in:

committed by
Michael Lutz

parent
3b4f224c0b
commit
7c8e7c6b6e
@@ -43,11 +43,11 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s,
|
||||
redirect_depth(depth),
|
||||
sock(s)
|
||||
{
|
||||
size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == NULL ? 0 : strlen(data)) + 128;
|
||||
size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == nullptr ? 0 : strlen(data)) + 128;
|
||||
char *buffer = AllocaM(char, bufferSize);
|
||||
|
||||
DEBUG(net, 7, "[tcp/http] requesting %s%s", host, url);
|
||||
if (data != NULL) {
|
||||
if (data != nullptr) {
|
||||
seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, GetNetworkRevisionString(), (int)strlen(data), data);
|
||||
} else {
|
||||
seprintf(buffer, buffer + bufferSize - 1, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\n\r\n", url, host, GetNetworkRevisionString());
|
||||
@@ -108,7 +108,7 @@ static const char * const LOCATION = "Location: "; ///< Header for l
|
||||
int NetworkHTTPSocketHandler::HandleHeader()
|
||||
{
|
||||
assert(strlen(HTTP_1_0) == strlen(HTTP_1_1));
|
||||
assert(strstr(this->recv_buffer, END_OF_HEADER) != NULL);
|
||||
assert(strstr(this->recv_buffer, END_OF_HEADER) != nullptr);
|
||||
|
||||
/* We expect a HTTP/1.[01] reply */
|
||||
if (strncmp(this->recv_buffer, HTTP_1_0, strlen(HTTP_1_0)) != 0 &&
|
||||
@@ -122,7 +122,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
|
||||
|
||||
/* Get the length of the document to receive */
|
||||
char *length = strcasestr(this->recv_buffer, CONTENT_LENGTH);
|
||||
if (length == NULL) return_error("[tcp/http] missing 'content-length' header");
|
||||
if (length == nullptr) return_error("[tcp/http] missing 'content-length' header");
|
||||
|
||||
/* Skip the header */
|
||||
length += strlen(CONTENT_LENGTH);
|
||||
@@ -163,7 +163,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
|
||||
|
||||
/* Redirect to other URL */
|
||||
char *uri = strcasestr(this->recv_buffer, LOCATION);
|
||||
if (uri == NULL) return_error("[tcp/http] missing 'location' header for redirect");
|
||||
if (uri == nullptr) return_error("[tcp/http] missing 'location' header for redirect");
|
||||
|
||||
uri += strlen(LOCATION);
|
||||
|
||||
@@ -178,7 +178,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
|
||||
if (ret != 0) return ret;
|
||||
|
||||
/* We've relinquished control of data now. */
|
||||
this->data = NULL;
|
||||
this->data = nullptr;
|
||||
|
||||
/* Restore the header. */
|
||||
*end_of_line = '\r';
|
||||
@@ -195,22 +195,22 @@ int NetworkHTTPSocketHandler::HandleHeader()
|
||||
/* static */ int NetworkHTTPSocketHandler::Connect(char *uri, HTTPCallback *callback, const char *data, int depth)
|
||||
{
|
||||
char *hname = strstr(uri, "://");
|
||||
if (hname == NULL) return_error("[tcp/http] invalid location");
|
||||
if (hname == nullptr) return_error("[tcp/http] invalid location");
|
||||
|
||||
hname += 3;
|
||||
|
||||
char *url = strchr(hname, '/');
|
||||
if (url == NULL) return_error("[tcp/http] invalid location");
|
||||
if (url == nullptr) return_error("[tcp/http] invalid location");
|
||||
|
||||
*url = '\0';
|
||||
|
||||
/* Fetch the hostname, and possible port number. */
|
||||
const char *company = NULL;
|
||||
const char *port = NULL;
|
||||
const char *company = nullptr;
|
||||
const char *port = nullptr;
|
||||
ParseConnectionString(&company, &port, hname);
|
||||
if (company != NULL) return_error("[tcp/http] invalid hostname");
|
||||
if (company != nullptr) return_error("[tcp/http] invalid hostname");
|
||||
|
||||
NetworkAddress address(hname, port == NULL ? 80 : atoi(port));
|
||||
NetworkAddress address(hname, port == nullptr ? 80 : atoi(port));
|
||||
|
||||
/* Restore the URL. */
|
||||
*url = '/';
|
||||
@@ -246,7 +246,7 @@ int NetworkHTTPSocketHandler::Receive()
|
||||
if (res == 0) {
|
||||
if (this->recv_length != 0) return -1;
|
||||
|
||||
this->callback->OnReceiveData(NULL, 0);
|
||||
this->callback->OnReceiveData(nullptr, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ int NetworkHTTPSocketHandler::Receive()
|
||||
char *end_of_header = strstr(this->recv_buffer, END_OF_HEADER);
|
||||
this->recv_buffer[end] = prev;
|
||||
|
||||
if (end_of_header == NULL) {
|
||||
if (end_of_header == nullptr) {
|
||||
if (read == lengthof(this->recv_buffer)) {
|
||||
DEBUG(net, 0, "[tcp/http] header too big");
|
||||
return -1;
|
||||
@@ -308,7 +308,7 @@ int NetworkHTTPSocketHandler::Receive()
|
||||
}
|
||||
|
||||
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
|
||||
int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
|
||||
int n = select(FD_SETSIZE, &read_fd, nullptr, nullptr, &tv);
|
||||
if (n == -1) return;
|
||||
|
||||
for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) {
|
||||
|
Reference in New Issue
Block a user