From f86091d421989ead46940cc12b77e48cfb127608 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 1 Feb 2012 21:20:27 +0000 Subject: [PATCH] Use useragent for version, fix URl encoding --- src/Config.h | 18 ++++++++++++++++++ src/Misc.cpp | 29 +++++++++++++++++++++++++++++ src/Misc.h | 2 ++ src/client/Client.cpp | 7 ++++--- src/client/HTTP.cpp | 21 ++++++++++++--------- src/game/GameModel.cpp | 4 ++++ 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/Config.h b/src/Config.h index 37a1a659d..1f00e6213 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 1e735748e..fcea10039 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 2dd96b2ae..6aff3dad9 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 3706cf97d..ce7c9e68c 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 * 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 b4f4777bd..ba2c1bb67 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 dcad40598..4fe65eae7 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++) {