[dovecot-cvs] dovecot/src/lib Makefile.am, 1.43, 1.44 str-sanitize.c, NONE, 1.1 str-sanitize.h, NONE, 1.1

cras at dovecot.org cras at dovecot.org
Tue Oct 5 18:29:40 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv32307/lib

Modified Files:
	Makefile.am 
Added Files:
	str-sanitize.c str-sanitize.h 
Log Message:
Added string sanitization functions.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- Makefile.am	5 Sep 2004 21:10:00 -0000	1.43
+++ Makefile.am	5 Oct 2004 15:29:38 -0000	1.44
@@ -59,6 +59,7 @@
 	sendfile-util.c \
 	sha1.c \
 	str.c \
+	str-sanitize.c \
 	strescape.c \
 	strfuncs.c \
 	unlink-directory.c \
@@ -117,6 +118,7 @@
 	sendfile-util.h \
 	sha1.h \
 	str.h \
+	str-sanitize.h \
 	strescape.h \
 	strfuncs.h \
 	unlink-directory.h \

--- NEW FILE: str-sanitize.c ---
/* Copyright (c) 2004 Timo Sirainen */

#include "lib.h"
#include "str.h"
#include "str-sanitize.h"

void str_sanitize_append(string_t *dest, const char *src, size_t max_len)
{
	const char *p;

	for (p = src; *p != '\0'; p++) {
		if ((unsigned char)*p < 32)
			break;
	}

	str_append_n(dest, src, (size_t)(p - src));
	for (; *p != '\0' && max_len > 0; p++, max_len--) {
		if ((unsigned char)*p < 32)
			str_append_c(dest, '?');
		else
			str_append_c(dest, *p);
	}

	if (*p != '\0') {
		str_truncate(dest, str_len(dest)-3);
		str_append(dest, "...");
	}
}

const char *str_sanitize(const char *src, size_t max_len)
{
	string_t *str;

	str = t_str_new(I_MIN(max_len, 256));
	str_sanitize_append(str, src, max_len);
	return str_c(str);
}

--- NEW FILE: str-sanitize.h ---
#ifndef __STR_SANITIZE_H
#define __STR_SANITIZE_H

/* All control characters in src will be appended as '?'. If src is longer
   than max_len, it's truncated with "..." appended to the end. */
void str_sanitize_append(string_t *dest, const char *src, size_t max_len);
const char *str_sanitize(const char *src, size_t max_len);

#endif



More information about the dovecot-cvs mailing list