summaryrefslogtreecommitdiff
path: root/src/client/HTTP.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-22 17:51:05 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-22 17:51:05 (GMT)
commit97bf9a517e63e87eebeedd6a6d393e83f6354a23 (patch)
tree9c523987a49d8cd2ae28becc3b2c520b8fbbf35d /src/client/HTTP.cpp
parenta1b4168b30979fc9bb8571d382b4bfc6aa8f87f0 (diff)
downloadpowder-97bf9a517e63e87eebeedd6a6d393e83f6354a23.zip
powder-97bf9a517e63e87eebeedd6a6d393e83f6354a23.tar.gz
Snapshot checking
Diffstat (limited to 'src/client/HTTP.cpp')
-rw-r--r--src/client/HTTP.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp
index d622a81..686a6ee 100644
--- a/src/client/HTTP.cpp
+++ b/src/client/HTTP.cpp
@@ -20,6 +20,8 @@
*/
+#include <string>
+#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -68,6 +70,7 @@
#define PCLOSE close
#endif
+char * userAgent;
static int http_up = 0;
static long http_timeout = 15;
static int http_use_proxy = 0;
@@ -180,6 +183,15 @@ void http_init(char *proxy)
free(host);
free(port);
}
+ std::stringstream userAgentBuilder;
+ userAgentBuilder << "PowderToy/" << SAVE_VERSION << "." << MINOR_VERSION << " ";
+ userAgentBuilder << "(" << IDENT_PLATFORM << "; " << IDENT_BUILD << "; M0) ";
+ userAgentBuilder << "TPTPP/" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << IDENT_RELTYPE << "." << SNAPSHOT_ID;
+ std::string newUserAgent = userAgentBuilder.str();
+ userAgent = new char[newUserAgent.length()+1];
+ std::copy(newUserAgent.begin(), newUserAgent.end(), userAgent);
+ userAgent[newUserAgent.length()] = 0;
+ //"User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s.%d\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE, SNAPSHOT_ID
}
void http_done(void)
@@ -468,7 +480,7 @@ int http_async_req_status(void *ctx)
if (cx->txdl)
{
// generate POST
- cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 141 + 128 + cx->txdl + cx->thlen);
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 126 + strlen(userAgent) + cx->txdl + cx->thlen);
cx->tptr = 0;
cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path);
@@ -484,7 +496,7 @@ int http_async_req_status(void *ctx)
cx->thlen = 0;
}
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl);
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE);
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: %s\n", userAgent);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl;
@@ -495,7 +507,7 @@ int http_async_req_status(void *ctx)
else
{
// generate GET
- cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 100 + 128 + cx->thlen);
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 93 + strlen(userAgent) + cx->thlen);
cx->tptr = 0;
cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path);
@@ -510,7 +522,7 @@ int http_async_req_status(void *ctx)
}
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE);
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: %s\n", userAgent);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
}
cx->state = HTS_XMIT;