]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move dump_text(), dump_text_line(), and dump_binary() to standard.c
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Nov 2016 17:00:20 +0000 (18:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:27 +0000 (16:59 +0100)
These are general purpose functions, move them away.

include/common/standard.h
src/cli.c
src/standard.c

index 33a3054b5b0c40fc366e798a902b988a6e9bff08..e16b30414fdf8f2e2fed6e2058ea16117ab1308a 100644 (file)
@@ -1129,6 +1129,11 @@ static inline unsigned long long rdtsc()
 struct list;
 int list_append_word(struct list *li, const char *str, char **err);
 
+int dump_text(struct chunk *out, const char *buf, int bsize);
+int dump_binary(struct chunk *out, const char *buf, int bsize);
+int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
+                   int *line, int ptr);
+
 /* same as realloc() except that ptr is also freed upon failure */
 static inline void *my_realloc2(void *ptr, size_t size)
 {
index a395e238bec6739497af432c40d1eb5e7169241c..4db420c61e6153525bd705a143d985eb23276de3 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -409,73 +409,6 @@ int cli_has_level(struct appctx *appctx, int level)
 }
 
 
-/* print a string of text buffer to <out>. The format is :
- * Non-printable chars \t, \n, \r and \e are * encoded in C format.
- * Other non-printable chars are encoded "\xHH". Space, '\', and '=' are also escaped.
- * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
- */
-static int dump_text(struct chunk *out, const char *buf, int bsize)
-{
-       unsigned char c;
-       int ptr = 0;
-
-       while (buf[ptr] && ptr < bsize) {
-               c = buf[ptr];
-               if (isprint(c) && isascii(c) && c != '\\' && c != ' ' && c != '=') {
-                       if (out->len > out->size - 1)
-                               break;
-                       out->str[out->len++] = c;
-               }
-               else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ' || c == '=') {
-                       if (out->len > out->size - 2)
-                               break;
-                       out->str[out->len++] = '\\';
-                       switch (c) {
-                       case ' ': c = ' '; break;
-                       case '\t': c = 't'; break;
-                       case '\n': c = 'n'; break;
-                       case '\r': c = 'r'; break;
-                       case '\e': c = 'e'; break;
-                       case '\\': c = '\\'; break;
-                       case '=': c = '='; break;
-                       }
-                       out->str[out->len++] = c;
-               }
-               else {
-                       if (out->len > out->size - 4)
-                               break;
-                       out->str[out->len++] = '\\';
-                       out->str[out->len++] = 'x';
-                       out->str[out->len++] = hextab[(c >> 4) & 0xF];
-                       out->str[out->len++] = hextab[c & 0xF];
-               }
-               ptr++;
-       }
-
-       return ptr;
-}
-
-/* print a buffer in hexa.
- * Print stopped if <bsize> is reached, or if no more place in the chunk.
- */
-static int dump_binary(struct chunk *out, const char *buf, int bsize)
-{
-       unsigned char c;
-       int ptr = 0;
-
-       while (ptr < bsize) {
-               c = buf[ptr];
-
-               if (out->len > out->size - 2)
-                       break;
-               out->str[out->len++] = hextab[(c >> 4) & 0xF];
-               out->str[out->len++] = hextab[c & 0xF];
-
-               ptr++;
-       }
-       return ptr;
-}
-
 /* Dump the status of a table to a stream interface's
  * read buffer. It returns 0 if the output buffer is full
  * and needs to be called again, otherwise non-zero.
@@ -1996,64 +1929,6 @@ static int stats_table_request(struct stream_interface *si, int action)
        return 1;
 }
 
-/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
- * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
- * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
- * encoded in C format. Other non-printable chars are encoded "\xHH". Original
- * lines are respected within the limit of 70 output chars. Lines that are
- * continuation of a previous truncated line begin with "+" instead of " "
- * after the offset. The new pointer is returned.
- */
-static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
-                         int *line, int ptr)
-{
-       int end;
-       unsigned char c;
-
-       end = out->len + 80;
-       if (end > out->size)
-               return ptr;
-
-       chunk_appendf(out, "  %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
-
-       while (ptr < len && ptr < bsize) {
-               c = buf[ptr];
-               if (isprint(c) && isascii(c) && c != '\\') {
-                       if (out->len > end - 2)
-                               break;
-                       out->str[out->len++] = c;
-               } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
-                       if (out->len > end - 3)
-                               break;
-                       out->str[out->len++] = '\\';
-                       switch (c) {
-                       case '\t': c = 't'; break;
-                       case '\n': c = 'n'; break;
-                       case '\r': c = 'r'; break;
-                       case '\e': c = 'e'; break;
-                       case '\\': c = '\\'; break;
-                       }
-                       out->str[out->len++] = c;
-               } else {
-                       if (out->len > end - 5)
-                               break;
-                       out->str[out->len++] = '\\';
-                       out->str[out->len++] = 'x';
-                       out->str[out->len++] = hextab[(c >> 4) & 0xF];
-                       out->str[out->len++] = hextab[c & 0xF];
-               }
-               if (buf[ptr++] == '\n') {
-                       /* we had a line break, let's return now */
-                       out->str[out->len++] = '\n';
-                       *line = ptr;
-                       return ptr;
-               }
-       }
-       /* we have an incomplete line, we return it as-is */
-       out->str[out->len++] = '\n';
-       return ptr;
-}
-
 /* This function dumps all captured errors onto the stream interface's
  * read buffer. It returns 0 if the output buffer is full and it needs
  * to be called again, otherwise non-zero.
index afb2c836e2ce417e6f1974dc432f28914c626fd5..079aef8f7575c62d655233b97758eb1377746365 100644 (file)
@@ -3640,6 +3640,131 @@ fail_wl:
        return 0;
 }
 
+/* print a string of text buffer to <out>. The format is :
+ * Non-printable chars \t, \n, \r and \e are * encoded in C format.
+ * Other non-printable chars are encoded "\xHH". Space, '\', and '=' are also escaped.
+ * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
+ */
+int dump_text(struct chunk *out, const char *buf, int bsize)
+{
+       unsigned char c;
+       int ptr = 0;
+
+       while (buf[ptr] && ptr < bsize) {
+               c = buf[ptr];
+               if (isprint(c) && isascii(c) && c != '\\' && c != ' ' && c != '=') {
+                       if (out->len > out->size - 1)
+                               break;
+                       out->str[out->len++] = c;
+               }
+               else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ' || c == '=') {
+                       if (out->len > out->size - 2)
+                               break;
+                       out->str[out->len++] = '\\';
+                       switch (c) {
+                       case ' ': c = ' '; break;
+                       case '\t': c = 't'; break;
+                       case '\n': c = 'n'; break;
+                       case '\r': c = 'r'; break;
+                       case '\e': c = 'e'; break;
+                       case '\\': c = '\\'; break;
+                       case '=': c = '='; break;
+                       }
+                       out->str[out->len++] = c;
+               }
+               else {
+                       if (out->len > out->size - 4)
+                               break;
+                       out->str[out->len++] = '\\';
+                       out->str[out->len++] = 'x';
+                       out->str[out->len++] = hextab[(c >> 4) & 0xF];
+                       out->str[out->len++] = hextab[c & 0xF];
+               }
+               ptr++;
+       }
+
+       return ptr;
+}
+
+/* print a buffer in hexa.
+ * Print stopped if <bsize> is reached, or if no more place in the chunk.
+ */
+int dump_binary(struct chunk *out, const char *buf, int bsize)
+{
+       unsigned char c;
+       int ptr = 0;
+
+       while (ptr < bsize) {
+               c = buf[ptr];
+
+               if (out->len > out->size - 2)
+                       break;
+               out->str[out->len++] = hextab[(c >> 4) & 0xF];
+               out->str[out->len++] = hextab[c & 0xF];
+
+               ptr++;
+       }
+       return ptr;
+}
+
+/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
+ * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
+ * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
+ * encoded in C format. Other non-printable chars are encoded "\xHH". Original
+ * lines are respected within the limit of 70 output chars. Lines that are
+ * continuation of a previous truncated line begin with "+" instead of " "
+ * after the offset. The new pointer is returned.
+ */
+int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
+                   int *line, int ptr)
+{
+       int end;
+       unsigned char c;
+
+       end = out->len + 80;
+       if (end > out->size)
+               return ptr;
+
+       chunk_appendf(out, "  %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
+
+       while (ptr < len && ptr < bsize) {
+               c = buf[ptr];
+               if (isprint(c) && isascii(c) && c != '\\') {
+                       if (out->len > end - 2)
+                               break;
+                       out->str[out->len++] = c;
+               } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
+                       if (out->len > end - 3)
+                               break;
+                       out->str[out->len++] = '\\';
+                       switch (c) {
+                       case '\t': c = 't'; break;
+                       case '\n': c = 'n'; break;
+                       case '\r': c = 'r'; break;
+                       case '\e': c = 'e'; break;
+                       case '\\': c = '\\'; break;
+                       }
+                       out->str[out->len++] = c;
+               } else {
+                       if (out->len > end - 5)
+                               break;
+                       out->str[out->len++] = '\\';
+                       out->str[out->len++] = 'x';
+                       out->str[out->len++] = hextab[(c >> 4) & 0xF];
+                       out->str[out->len++] = hextab[c & 0xF];
+               }
+               if (buf[ptr++] == '\n') {
+                       /* we had a line break, let's return now */
+                       out->str[out->len++] = '\n';
+                       *line = ptr;
+                       return ptr;
+               }
+       }
+       /* we have an incomplete line, we return it as-is */
+       out->str[out->len++] = '\n';
+       return ptr;
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8