* Reads characters (bytes) from the packet until it finds a '\0', or reaches a * maximum of \c length characters. * When the '\0' has not been reached in the first \c length read characters, * more characters are read from the packet until '\0' has been reached. However, * these characters will not end up in the returned string. * The length of the returned string will be at most \c length -
| 423 | * @return The validated string. |
| 424 | */ |
| 425 | std::string Packet::Recv_string(size_t length, StringValidationSettings settings) |
| 426 | { |
| 427 | assert(length > 1); |
| 428 | |
| 429 | /* Both loops with Recv_uint8 terminate when reading past the end of the |
| 430 | * packet as Recv_uint8 then closes the connection and returns 0. */ |
| 431 | std::string str; |
| 432 | char character; |
| 433 | while (--length > 0 && (character = this->Recv_uint8()) != '\0') str.push_back(character); |
| 434 | |
| 435 | if (length == 0) { |
| 436 | /* The string in the packet was longer. Read until the termination. */ |
| 437 | while (this->Recv_uint8() != '\0') {} |
| 438 | } |
| 439 | |
| 440 | return StrMakeValid(str, settings); |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Get the amount of bytes that are still available for the Transfer functions. |
no test coverage detected