diff --git a/src/debug.c b/src/debug.c index d1824dfd796b26c97d50b56697cdbe65bdf02410..6cc734c321b5722542b2ecc746e782bf50f6c4e9 100644 --- a/src/debug.c +++ b/src/debug.c @@ -576,6 +576,8 @@ NULL addReplyBool(c,1); } else if (!strcasecmp(name,"false")) { addReplyBool(c,0); + } else if (!strcasecmp(name,"verbatim")) { + addReplyVerbatim(c,"This is a verbatim\nstring",25,"txt"); } else { addReplyError(c,"Wrong protocol type name. Please use one of the following: string|integer|double|bignum|null|array|set|map|attrib|push|verbatim|true|false|state|err|bloberr"); } diff --git a/src/networking.c b/src/networking.c index 75312a1f27f744c61a1215fef0a8b840b6d06bbf..6b13db8e34e7d45a2c4bfaf880919aad5c74c828 100644 --- a/src/networking.c +++ b/src/networking.c @@ -696,6 +696,35 @@ void addReplyBulkLongLong(client *c, long long ll) { addReplyBulkCBuffer(c,buf,len); } +/* Reply with a verbatim type having the specified extension. + * + * The 'ext' is the "extension" of the file, actually just a three + * character type that describes the format of the verbatim string. + * For instance "txt" means it should be interpreted as a text only + * file by the receiver, "md " as markdown, and so forth. Only the + * three first characters of the extension are used, and if the + * provided one is shorter than that, the remaining is filled with + * spaces. */ +void addReplyVerbatim(client *c, const char *s, size_t len, const char *ext) { + if (c->resp == 2) { + addReplyBulkCBuffer(c,s,len); + } else { + char buf[32]; + size_t preflen = snprintf(buf,sizeof(buf),"=%zu\r\nxxx:",len+4); + char *p = buf+preflen-4; + for (int i = 0; i < 3; i++) { + if (*ext == '\0') { + p[i] = ' '; + } else { + p[i] = *ext++; + } + } + addReplyString(c,buf,preflen); + addReplyString(c,s,len); + addReplyString(c,"\r\n",2); + } +} + /* Add an array of C strings as status replies with a heading. * This function is typically invoked by from commands that support * subcommands in response to the 'help' subcommand. The help array diff --git a/src/server.h b/src/server.h index 0362c03a27e520008f9b8fc67aa94c32bcfe327b..8c1e6a775e6001b6131cfc90ebc2aa5f52af5939 100644 --- a/src/server.h +++ b/src/server.h @@ -1440,6 +1440,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask); void addReplyNull(client *c); void addReplyNullArray(client *c); void addReplyBool(client *c, int b); +void addReplyVerbatim(client *c, const char *s, size_t len, const char *ext); void addReplyString(client *c, const char *s, size_t len); void addReplyBulk(client *c, robj *obj); void addReplyBulkCString(client *c, const char *s);