]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: Add internal function which strip spaces
authorThierry Fournier <tfournier@arpalert.org>
Wed, 24 Feb 2016 07:06:32 +0000 (08:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 13:45:45 +0000 (15:45 +0200)
Some internal HAproxy error message are provided with a final '\n'.
Its typically for the integration in the CLI. Sometimes, these messages
are returned as Lua string. These string must be without "\n" or final
spaces.

This patch adds a function whoch removes unrequired parameters.

src/hlua_fcn.c

index 215058a879d74625664e48a05c37702f009cdcb2..1e58f7ab2eaaea22784e3cef21e4190939fd6a9a 100644 (file)
 
 #include <types/hlua.h>
 
+#include <proto/proto_http.h>
+
 /* Contains the class reference of the concat object. */
 static int class_concat_ref;
 
+/* Some string are started or terminated by blank chars,
+ * this function removes the spaces, tabs, \r and
+ * \n at the begin and at the end of the string "str", and
+ * push the result in the lua stack.
+ * Returns a pointer to the Lua internal copy of the string.
+ */
+const char *hlua_pushstrippedstring(lua_State *L, const char *str)
+{
+       const char *p;
+       const char *e;
+
+       for (p = str; HTTP_IS_LWS(*p); p++);
+       for (e = p + strlen(p) - 1; e > p && HTTP_IS_LWS(*e); e--);
+
+       return lua_pushlstring(L, p, e - p);
+}
+
 /* The three following functions are useful for adding entries
  * in a table. These functions takes a string and respectively an
  * integer, a string or a function and add it to the table in the