| 1799 | * CLIENT_PROTOCOL_ERROR. */ |
| 1800 | #define PROTO_DUMP_LEN 128 |
| 1801 | static void setProtocolError(const char *errstr, client *c) { |
| 1802 | if (server.verbosity <= LL_VERBOSE || c->flags & CLIENT_MASTER) { |
| 1803 | sds client = catClientInfoString(sdsempty(),c); |
| 1804 | |
| 1805 | /* Sample some protocol to given an idea about what was inside. */ |
| 1806 | char buf[256]; |
| 1807 | if (sdslen(c->querybuf)-c->qb_pos < PROTO_DUMP_LEN) { |
| 1808 | snprintf(buf,sizeof(buf),"Query buffer during protocol error: '%s'", c->querybuf+c->qb_pos); |
| 1809 | } else { |
| 1810 | snprintf(buf,sizeof(buf),"Query buffer during protocol error: '%.*s' (... more %zu bytes ...) '%.*s'", PROTO_DUMP_LEN/2, c->querybuf+c->qb_pos, sdslen(c->querybuf)-c->qb_pos-PROTO_DUMP_LEN, PROTO_DUMP_LEN/2, c->querybuf+sdslen(c->querybuf)-PROTO_DUMP_LEN/2); |
| 1811 | } |
| 1812 | |
| 1813 | /* Remove non printable chars. */ |
| 1814 | char *p = buf; |
| 1815 | while (*p != '\0') { |
| 1816 | if (!isprint(*p)) *p = '.'; |
| 1817 | p++; |
| 1818 | } |
| 1819 | |
| 1820 | /* Log all the client and protocol info. */ |
| 1821 | int loglevel = (c->flags & CLIENT_MASTER) ? LL_WARNING : |
| 1822 | LL_VERBOSE; |
| 1823 | serverLog(loglevel, |
| 1824 | "Protocol error (%s) from client: %s. %s", errstr, client, buf); |
| 1825 | sdsfree(client); |
| 1826 | } |
| 1827 | c->flags |= (CLIENT_CLOSE_AFTER_REPLY|CLIENT_PROTOCOL_ERROR); |
| 1828 | } |
| 1829 | |
| 1830 | /* Process the query buffer for client 'c', setting up the client argument |
| 1831 | * vector for command execution. Returns C_OK if after running the function |