summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-02-01 21:20:27 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-02-01 21:20:27 (GMT)
commitf86091d421989ead46940cc12b77e48cfb127608 (patch)
tree978f64c6ab2e90789e73ab3af52f9528429fe8a0 /src
parent038da72c61ea6a251d805e2de3662f240da52b02 (diff)
downloadpowder-f86091d421989ead46940cc12b77e48cfb127608.zip
powder-f86091d421989ead46940cc12b77e48cfb127608.tar.gz
Use useragent for version, fix URl encoding
Diffstat (limited to 'src')
-rw-r--r--src/Config.h18
-rw-r--r--src/Misc.cpp29
-rw-r--r--src/Misc.h2
-rw-r--r--src/client/Client.cpp7
-rw-r--r--src/client/HTTP.cpp21
-rw-r--r--src/game/GameModel.cpp4
6 files changed, 69 insertions, 12 deletions
diff --git a/src/Config.h b/src/Config.h
index 37a1a65..1f00e62 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -22,6 +22,24 @@
#define BUILD_NUM 133
//VersionInfoEnd
+#ifdef BETA
+#define IDENT_RELTYPE "B"
+#else
+#define IDENT_RELTYPE "S"
+#endif
+
+#ifdef WIN32
+#define IDENT_PLATFORM "WIN32"
+#elif defined(MACOSX)
+#define IDENT_PLATFORM "MACOSX"
+#elif defined(LIN32)
+#define IDENT_PLATFORM "LIN32"
+#elif defined(LIN64)
+#define IDENT_PLATFORM "LIN64"
+#else
+#define IDENT_PLATFORM "UNKNOWN"
+#endif
+
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter
#define MTOS_EXPAND(str) #str
diff --git a/src/Misc.cpp b/src/Misc.cpp
index 1e73574..fcea100 100644
--- a/src/Misc.cpp
+++ b/src/Misc.cpp
@@ -205,6 +205,35 @@ void strcaturl(char *dst, char *src)
*d = 0;
}
+std::string URLEscape(std::string source)
+{
+ char * src = (char *)source.c_str();
+ char * dst = (char *)calloc((source.length()*3)+2, 1);
+ char *d;
+ unsigned char *s;
+
+ for (d=dst; *d; d++) ;
+
+ for (s=(unsigned char *)src; *s; s++)
+ {
+ if ((*s>='0' && *s<='9') ||
+ (*s>='a' && *s<='z') ||
+ (*s>='A' && *s<='Z'))
+ *(d++) = *s;
+ else
+ {
+ *(d++) = '%';
+ *(d++) = hex[*s>>4];
+ *(d++) = hex[*s&15];
+ }
+ }
+ *d = 0;
+
+ std::string finalString(dst);
+ free(dst);
+ return finalString;
+}
+
void strappend(char *dst, char *src)
{
char *d;
diff --git a/src/Misc.h b/src/Misc.h
index 2dd96b2..6aff3da 100644
--- a/src/Misc.h
+++ b/src/Misc.h
@@ -69,6 +69,8 @@ int load_string(FILE *f, char *str, int max);
void strcaturl(char *dst, char *src);
+std::string URLEscape(std::string source);
+
void strappend(char *dst, char *src);
void *file_load(char *fn, int *size);
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 3706cf9..ce7c9e6 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -9,6 +9,7 @@
#include "Client.h"
#include "MD5.h"
#include "Graphics.h"
+#include "Misc.h"
#include "interface/Point.h"
@@ -434,12 +435,12 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
{
urlStream << "&Search_Query=";
if(query.length())
- urlStream << query;
+ urlStream << URLEscape(query);
if(sort == "date")
{
if(query.length())
- urlStream << " ";
- urlStream << "sort:" << sort;
+ urlStream << URLEscape(" ");
+ urlStream << URLEscape("sort:") << URLEscape(sort);
}
}
diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp
index b4f4777..ba2c1bb 100644
--- a/src/client/HTTP.cpp
+++ b/src/client/HTTP.cpp
@@ -464,7 +464,7 @@ int http_async_req_status(void *ctx)
if (cx->txdl)
{
// generate POST
- cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 121 + cx->txdl + cx->thlen);
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 121 + 128 + 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);
@@ -480,11 +480,12 @@ int http_async_req_status(void *ctx)
cx->thlen = 0;
}
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl);
-#ifdef BETA
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#else
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#endif
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; M%d) TPTPP/%s%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, 0, IDENT_VERSION, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE);
+//#ifdef BETA
+// cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+//#else
+// cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+//#endif
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl;
@@ -495,7 +496,7 @@ int http_async_req_status(void *ctx)
else
{
// generate GET
- cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 89 + cx->thlen);
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 89 + 128 + cx->thlen);
cx->tptr = 0;
cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path);
@@ -510,11 +511,13 @@ int http_async_req_status(void *ctx)
}
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
-#ifdef BETA
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; M%d) TPTPP/%s%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, 0, IDENT_VERSION, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE);
+
+/*#ifdef BETA
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#else
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#endif
+#endif*/
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
}
cx->state = HTS_XMIT;
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index dcad405..4fe65ea 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -33,6 +33,10 @@ GameModel::GameModel():
menuList[sim->ptypes[i].menusection]->AddTool(tempTool);
}
}
+
+ //Build menu for GOL types
+ //for(int i = 0; i < GOL_)
+
//Build other menus from wall data
for(int i = 0; i < UI_WALLCOUNT; i++)
{