(svn r15135) -Fix/Change: allow str_validate (part of receiving strings from the network) to pass newlines instead of replacing them with question marks, but only when asked to do so.

This commit is contained in:
rubidium 2009-01-18 13:12:57 +00:00
parent b8219eb7a1
commit 07e135547e
5 changed files with 13 additions and 6 deletions

View File

@ -233,7 +233,7 @@ uint64 Packet::Recv_uint64()
} }
/** Reads a string till it finds a '\0' in the stream */ /** Reads a string till it finds a '\0' in the stream */
void Packet::Recv_string(char *buffer, size_t size) void Packet::Recv_string(char *buffer, size_t size, bool allow_newlines)
{ {
PacketSize pos; PacketSize pos;
char *bufp = buffer; char *bufp = buffer;
@ -253,7 +253,7 @@ void Packet::Recv_string(char *buffer, size_t size)
} }
this->pos = pos; this->pos = pos;
str_validate(bufp); str_validate(bufp, allow_newlines);
} }
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -62,7 +62,7 @@ public:
uint16 Recv_uint16(); uint16 Recv_uint16();
uint32 Recv_uint32(); uint32 Recv_uint32();
uint64 Recv_uint64(); uint64 Recv_uint64();
void Recv_string(char *buffer, size_t size); void Recv_string(char *buffer, size_t size, bool allow_newlines = false);
}; };
Packet *NetworkSend_Init(PacketType type); Packet *NetworkSend_Init(PacketType type);

View File

@ -53,7 +53,7 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_INFO)
p->Recv_string(ci->name, lengthof(ci->name)); p->Recv_string(ci->name, lengthof(ci->name));
p->Recv_string(ci->version, lengthof(ci->name)); p->Recv_string(ci->version, lengthof(ci->name));
p->Recv_string(ci->url, lengthof(ci->url)); p->Recv_string(ci->url, lengthof(ci->url));
p->Recv_string(ci->description, lengthof(ci->description)); p->Recv_string(ci->description, lengthof(ci->description), true);
ci->unique_id = p->Recv_uint32(); ci->unique_id = p->Recv_uint32();
for (uint j = 0; j < sizeof(ci->md5sum); j++) { for (uint j = 0; j < sizeof(ci->md5sum); j++) {

View File

@ -98,7 +98,7 @@ char *CDECL str_fmt(const char *str, ...)
} }
void str_validate(char *str) void str_validate(char *str, bool allow_newlines)
{ {
char *dst = str; char *dst = str;
WChar c; WChar c;
@ -113,7 +113,14 @@ void str_validate(char *str)
do { do {
*dst++ = *str++; *dst++ = *str++;
} while (--len != 0); } while (--len != 0);
} else if (allow_newlines && c == '\n') {
*dst++ = *str++;
} else { } else {
if (allow_newlines && c == '\r' && str[1] == '\n') {
str += len;
continue;
}
assert(c != '\r');
/* Replace the undesirable character with a question mark */ /* Replace the undesirable character with a question mark */
str += len; str += len;
*dst++ = '?'; *dst++ = '?';

View File

@ -95,7 +95,7 @@ char *CDECL str_fmt(const char *str, ...);
/** Scans the string for valid characters and if it finds invalid ones, /** Scans the string for valid characters and if it finds invalid ones,
* replaces them with a question mark '?' */ * replaces them with a question mark '?' */
void str_validate(char *str); void str_validate(char *str, bool allow_newlines = false);
/** Scans the string for colour codes and strips them */ /** Scans the string for colour codes and strips them */
void str_strip_colours(char *str); void str_strip_colours(char *str);