c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef STRESCAPE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define STRESCAPE_H
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen
839c67ba93b58e394daa435f7b99587eec97cefbTimo Sirainen#define IS_ESCAPED_CHAR(c) ((c) == '"' || (c) == '\\' || (c) == '\'')
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen
839c67ba93b58e394daa435f7b99587eec97cefbTimo Sirainen/* escape all '\', '"' and "'" characters */
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainenconst char *str_escape(const char *str);
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen/* remove all '\' characters, append to given string */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid str_append_unescaped(string_t *dest, const void *src, size_t src_size);
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen/* remove all '\' characters */
4d3e576109a91270c04821f8d727cd1afec8c801Timo Sirainenchar *str_unescape(char *str);
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen
6b35ba747072480bfc86ed7cc69df1d418e2ae20Timo Sirainen/* Remove all '\' chars from str until '"' is reached and return the unescaped
6b35ba747072480bfc86ed7cc69df1d418e2ae20Timo Sirainen string. *str is updated to point to the character after the '"'. Returns 0
6b35ba747072480bfc86ed7cc69df1d418e2ae20Timo Sirainen if ok, -1 if '"' wasn't found. */
6b35ba747072480bfc86ed7cc69df1d418e2ae20Timo Sirainenint str_unescape_next(const char **str, const char **unescaped_r);
6b35ba747072480bfc86ed7cc69df1d418e2ae20Timo Sirainen
047ebb958b682bc058097eddc34df574c3f3d6d4Timo Sirainen/* For Dovecot's internal protocols: Escape \001, \t, \r and \n characters
146e7e3fabdd843d50680cdb6e4f7829890f5fcfTimo Sirainen using \001. */
146e7e3fabdd843d50680cdb6e4f7829890f5fcfTimo Sirainenconst char *str_tabescape(const char *str);
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainenvoid str_append_tabescaped(string_t *dest, const char *src);
51aceed49d7edcf1ce385d6d97f0acb7067a6608Aki Tuomivoid str_append_tabescaped_n(string_t *dest, const unsigned char *src, size_t src_size);
047ebb958b682bc058097eddc34df574c3f3d6d4Timo Sirainenvoid str_append_tabunescaped(string_t *dest, const void *src, size_t src_size);
03b33ccb012636e453189ceef3865dee7812392eTimo Sirainenchar *str_tabunescape(char *str);
6ea49f0ffe92ac0d709ac9282e136a94df0053eeTimo Sirainenconst char *t_str_tabunescape(const char *str);
146e7e3fabdd843d50680cdb6e4f7829890f5fcfTimo Sirainen
8d85926bc5484cf5f8de2ab3218298fe01d62696Timo Sirainenchar **p_strsplit_tabescaped(pool_t pool, const char *str);
8d85926bc5484cf5f8de2ab3218298fe01d62696Timo Sirainenconst char *const *t_strsplit_tabescaped(const char *str);
7de17a595a44e61714d3fc7e55491449d38a8e62Timo Sirainen/* Same as t_strsplit_tabescaped(), but the input string is modified and the
7de17a595a44e61714d3fc7e55491449d38a8e62Timo Sirainen returned pointers inside the array point to the original string. */
7de17a595a44e61714d3fc7e55491449d38a8e62Timo Sirainenconst char *const *t_strsplit_tabescaped_inplace(char *str);
8d85926bc5484cf5f8de2ab3218298fe01d62696Timo Sirainen
4a6f9ed8e5412508dcba1eabb58a3680ad5e9b68Timo Sirainen#endif