changeset 7912:81806d402514 HEAD

Added more consts, ATTR_CONSTs and ATTR_PUREs.
author Timo Sirainen <tss@iki.fi>
date Fri, 20 Jun 2008 10:41:44 +0300
parents 3d65aeed7ea0
children e04513064165
files src/imap/commands-util.c src/imap/commands-util.h src/lib-charset/charset-utf8.h src/lib-imap/imap-bodystructure.c src/lib-imap/imap-bodystructure.h src/lib-mail/message-header-parser.c src/lib-mail/message-header-parser.h src/lib-storage/mail-namespace.c src/lib-storage/mail-namespace.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/mailbox-list.c src/lib-storage/mailbox-list.h src/lib/aqueue.h src/lib/array.c src/lib/array.h src/lib/buffer.c src/lib/buffer.h src/lib/crc32.h src/lib/data-stack.h src/lib/hash.h src/lib/hex-dec.h src/lib/istream.c src/lib/istream.h src/lib/lib.h src/lib/network.h src/lib/ostream-file.c src/lib/ostream-internal.h src/lib/ostream.c src/lib/ostream.h src/lib/primes.h src/lib/priorityq.h src/lib/seq-range-array.h src/lib/str.h src/lib/strfuncs.h src/lib/unichar.h src/lib/var-expand.h src/login-common/client-common.h src/login-common/login-proxy.c src/login-common/login-proxy.h src/login-common/ssl-proxy-openssl.c src/login-common/ssl-proxy.c src/login-common/ssl-proxy.h
diffstat 43 files changed, 136 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/commands-util.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/imap/commands-util.c	Fri Jun 20 10:41:44 2008 +0300
@@ -321,8 +321,8 @@
 	return array_idx(dest, 0);
 }
 
-bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
-		    const char *name2)
+bool mailbox_equals(const struct mailbox *box1,
+		    const struct mail_storage *storage2, const char *name2)
 {
 	struct mail_storage *storage1 = mailbox_get_storage(box1);
 	const char *name1;
--- a/src/imap/commands-util.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/imap/commands-util.h	Fri Jun 20 10:41:44 2008 +0300
@@ -61,8 +61,9 @@
 client_get_keyword_names(struct client *client, ARRAY_TYPE(keywords) *dest,
 			 const ARRAY_TYPE(keyword_indexes) *src);
 
-bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
-		    const char *name2);
+bool mailbox_equals(const struct mailbox *box1,
+		    const struct mail_storage *storage2,
+		    const char *name2) ATTR_PURE;
 
 void msgset_generator_init(struct msgset_generator_context *ctx, string_t *str);
 void msgset_generator_next(struct msgset_generator_context *ctx, uint32_t uid);
--- a/src/lib-charset/charset-utf8.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-charset/charset-utf8.h	Fri Jun 20 10:41:44 2008 +0300
@@ -21,7 +21,7 @@
 void charset_to_utf8_reset(struct charset_translation *t);
 
 /* Returns TRUE if charset is UTF-8 or ASCII */
-bool charset_is_utf8(const char *charset);
+bool charset_is_utf8(const char *charset) ATTR_PURE;
 
 /* Translate src to UTF-8. src_size is updated to contain the number of
    characters actually translated from src. */
--- a/src/lib-imap/imap-bodystructure.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-imap/imap-bodystructure.c	Fri Jun 20 10:41:44 2008 +0300
@@ -446,9 +446,9 @@
 	}
 }
 
-bool imap_bodystructure_is_plain_7bit(struct message_part *part)
+bool imap_bodystructure_is_plain_7bit(const struct message_part *part)
 {
-	struct message_part_body_data *data = part->context;
+	const struct message_part_body_data *data = part->context;
 
 	i_assert(part->parent == NULL);
 
--- a/src/lib-imap/imap-bodystructure.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-imap/imap-bodystructure.h	Fri Jun 20 10:41:44 2008 +0300
@@ -10,7 +10,8 @@
 
 /* Returns TRUE if BODYSTRUCTURE is
    ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" n n NIL NIL NIL) */
-bool imap_bodystructure_is_plain_7bit(struct message_part *part);
+bool imap_bodystructure_is_plain_7bit(const struct message_part *part)
+	ATTR_PURE;
 
 void imap_bodystructure_write(const struct message_part *part,
 			      string_t *dest, bool extended);
--- a/src/lib-mail/message-header-parser.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-mail/message-header-parser.c	Fri Jun 20 10:41:44 2008 +0300
@@ -370,7 +370,7 @@
 	return 1;
 }
 
-bool message_parse_header_has_nuls(struct message_header_parser_ctx *ctx)
+bool message_parse_header_has_nuls(const struct message_header_parser_ctx *ctx)
 {
 	return ctx->has_nuls;
 }
--- a/src/lib-mail/message-header-parser.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-mail/message-header-parser.h	Fri Jun 20 10:41:44 2008 +0300
@@ -55,7 +55,8 @@
 			      struct message_header_line **hdr_r);
 
 /* Returns TRUE if the parser has seen NUL characters. */
-bool message_parse_header_has_nuls(struct message_header_parser_ctx *ctx);
+bool message_parse_header_has_nuls(const struct message_header_parser_ctx *ctx)
+	ATTR_PURE;
 
 /* Read and parse the header from the given stream. */
 void message_parse_header(struct istream *input, struct message_size *hdr_size,
--- a/src/lib-storage/mail-namespace.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mail-namespace.c	Fri Jun 20 10:41:44 2008 +0300
@@ -313,7 +313,7 @@
 	return str_c(dest);
 }
 
-char mail_namespace_get_root_sep(struct mail_namespace *namespaces)
+char mail_namespace_get_root_sep(const struct mail_namespace *namespaces)
 {
 	while ((namespaces->flags & NAMESPACE_FLAG_LIST) == 0)
 		namespaces = namespaces->next;
@@ -401,7 +401,7 @@
 	return namespaces;
 }
 
-bool mail_namespace_update_name(struct mail_namespace *ns,
+bool mail_namespace_update_name(const struct mail_namespace *ns,
 				const char **mailbox)
 {
 	struct mail_namespace tmp_ns = *ns;
--- a/src/lib-storage/mail-namespace.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mail-namespace.h	Fri Jun 20 10:41:44 2008 +0300
@@ -53,7 +53,8 @@
 				     const char *name);
 
 /* Returns the hierarchy separator for mailboxes that are listed at root. */
-char mail_namespace_get_root_sep(struct mail_namespace *namespaces);
+char mail_namespace_get_root_sep(const struct mail_namespace *namespaces)
+	ATTR_PURE;
 
 /* Returns namespace based on the mailbox name's prefix. Updates mailbox to
    be a valid name inside the namespace (prefix is skipped, hierarchy separator
@@ -73,7 +74,7 @@
 mail_namespace_find_inbox(struct mail_namespace *namespaces);
 /* Returns TRUE if the given namespace matches the mailbox's prefix.
    Updates mailbox name to be a valid name inside the namespace. */
-bool mail_namespace_update_name(struct mail_namespace *ns,
+bool mail_namespace_update_name(const struct mail_namespace *ns,
 				const char **mailbox);
 
 /* Find a namespace with given prefix. */
--- a/src/lib-storage/mail-storage.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mail-storage.c	Fri Jun 20 10:41:44 2008 +0300
@@ -328,12 +328,13 @@
 	return mailbox_list_get_hierarchy_sep(storage->list);
 }
 
-struct mailbox_list *mail_storage_get_list(struct mail_storage *storage)
+struct mailbox_list *mail_storage_get_list(const struct mail_storage *storage)
 {
 	return storage->list;
 }
 
-struct mail_namespace *mail_storage_get_namespace(struct mail_storage *storage)
+struct mail_namespace *
+mail_storage_get_namespace(const struct mail_storage *storage)
 {
 	return storage->ns;
 }
@@ -488,12 +489,12 @@
 	return box->v.close(box);
 }
 
-struct mail_storage *mailbox_get_storage(struct mailbox *box)
+struct mail_storage *mailbox_get_storage(const struct mailbox *box)
 {
 	return box->storage;
 }
 
-const char *mailbox_get_name(struct mailbox *box)
+const char *mailbox_get_name(const struct mailbox *box)
 {
 	return box->name;
 }
@@ -566,7 +567,6 @@
 
 void mailbox_notify_changes_stop(struct mailbox *box)
 {
-
 	mailbox_notify_changes(box, 0, NULL, NULL);
 }
 
@@ -755,13 +755,13 @@
 	t->box->v.transaction_rollback(t);
 }
 
-unsigned int mailbox_transaction_get_count(struct mailbox *box)
+unsigned int mailbox_transaction_get_count(const struct mailbox *box)
 {
 	return box->transaction_count;
 }
 
 struct mailbox *
-mailbox_transaction_get_mailbox(struct mailbox_transaction_context *t)
+mailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
 {
 	return t->box;
 }
--- a/src/lib-storage/mail-storage.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mail-storage.h	Fri Jun 20 10:41:44 2008 +0300
@@ -250,8 +250,10 @@
 void mail_storage_destroy(struct mail_storage **storage);
 
 char mail_storage_get_hierarchy_sep(struct mail_storage *storage);
-struct mailbox_list *mail_storage_get_list(struct mail_storage *storage);
-struct mail_namespace *mail_storage_get_namespace(struct mail_storage *storage);
+struct mailbox_list *
+mail_storage_get_list(const struct mail_storage *storage) ATTR_PURE;
+struct mail_namespace *
+mail_storage_get_namespace(const struct mail_storage *storage) ATTR_PURE;
 
 /* Set storage callback functions to use. */
 void mail_storage_set_callbacks(struct mail_storage *storage,
@@ -302,10 +304,10 @@
 enum mailbox_feature mailbox_get_enabled_features(struct mailbox *box);
 
 /* Returns storage of given mailbox */
-struct mail_storage *mailbox_get_storage(struct mailbox *box);
+struct mail_storage *mailbox_get_storage(const struct mailbox *box) ATTR_PURE;
 
 /* Returns name of given mailbox */
-const char *mailbox_get_name(struct mailbox *box);
+const char *mailbox_get_name(const struct mailbox *box) ATTR_PURE;
 
 /* Returns TRUE if mailbox is read-only. */
 bool mailbox_is_readonly(struct mailbox *box);
@@ -357,10 +359,11 @@
 					uint32_t *last_saved_uid_r);
 void mailbox_transaction_rollback(struct mailbox_transaction_context **t);
 /* Return the number of active transactions for the mailbox. */
-unsigned int mailbox_transaction_get_count(struct mailbox *box);
+unsigned int mailbox_transaction_get_count(const struct mailbox *box) ATTR_PURE;
 
 struct mailbox *
-mailbox_transaction_get_mailbox(struct mailbox_transaction_context *t);
+mailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
+	ATTR_PURE;
 
 /* Build mail_keywords from NULL-terminated keywords list.
    Returns 0 if successful, -1 if there are invalid keywords (error is set). */
--- a/src/lib-storage/mailbox-list.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mailbox-list.c	Fri Jun 20 10:41:44 2008 +0300
@@ -216,22 +216,23 @@
 	list->v.deinit(list);
 }
 
-const char *mailbox_list_get_driver_name(struct mailbox_list *list)
+const char *mailbox_list_get_driver_name(const struct mailbox_list *list)
 {
 	return list->name;
 }
 
-char mailbox_list_get_hierarchy_sep(struct mailbox_list *list)
+char mailbox_list_get_hierarchy_sep(const struct mailbox_list *list)
 {
 	return list->hierarchy_sep;
 }
 
-enum mailbox_list_flags mailbox_list_get_flags(struct mailbox_list *list)
+enum mailbox_list_flags mailbox_list_get_flags(const struct mailbox_list *list)
 {
 	return list->flags;
 }
 
-struct mail_namespace *mailbox_list_get_namespace(struct mailbox_list *list)
+struct mail_namespace *
+mailbox_list_get_namespace(const struct mailbox_list *list)
 {
 	return list->ns;
 }
--- a/src/lib-storage/mailbox-list.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib-storage/mailbox-list.h	Fri Jun 20 10:41:44 2008 +0300
@@ -128,10 +128,13 @@
 		       enum mailbox_list_flags flags);
 void mailbox_list_deinit(struct mailbox_list *list);
 
-const char *mailbox_list_get_driver_name(struct mailbox_list *list);
-char mailbox_list_get_hierarchy_sep(struct mailbox_list *list);
-enum mailbox_list_flags mailbox_list_get_flags(struct mailbox_list *list);
-struct mail_namespace *mailbox_list_get_namespace(struct mailbox_list *list);
+const char *
+mailbox_list_get_driver_name(const struct mailbox_list *list) ATTR_PURE;
+char mailbox_list_get_hierarchy_sep(const struct mailbox_list *list) ATTR_PURE;
+enum mailbox_list_flags
+mailbox_list_get_flags(const struct mailbox_list *list) ATTR_PURE;
+struct mail_namespace *
+mailbox_list_get_namespace(const struct mailbox_list *list) ATTR_PURE;
 
 /* Returns the mode and GID that should be used when creating new global files
    to the mailbox list root directories. (gid_t)-1 is returned if it's not
--- a/src/lib/aqueue.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/aqueue.h	Fri Jun 20 10:41:44 2008 +0300
@@ -29,10 +29,10 @@
 void aqueue_clear(struct aqueue *aqueue);
 
 /* Returns the number of items in aqueue. */
-unsigned int aqueue_count(const struct aqueue *aqueue);
+unsigned int aqueue_count(const struct aqueue *aqueue) ATTR_PURE;
 
 /* Returns array index of n'th element in aqueue. */
-static inline unsigned int
+static inline unsigned int ATTR_PURE
 aqueue_idx(const struct aqueue *aqueue, unsigned int n)
 {
 	return (aqueue->tail + n) % aqueue->area_size;
--- a/src/lib/array.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/array.c	Fri Jun 20 10:41:44 2008 +0300
@@ -66,7 +66,7 @@
 	return buffer_cmp(array1->buffer, array2->buffer);
 }
 
-void array_reverse_i(const struct array *array)
+void array_reverse_i(struct array *array)
 {
 	const unsigned int element_size = array->element_size;
 	unsigned int i, count = array_count_i(array);
--- a/src/lib/array.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/array.h	Fri Jun 20 10:41:44 2008 +0300
@@ -148,7 +148,7 @@
 #define array_get(array, count) \
 	ARRAY_TYPE_CAST_CONST(array)array_get_i(&(array)->arr, count)
 
-static inline const void *
+static inline const void * ATTR_PURE
 array_idx_i(const struct array *array, unsigned int idx)
 {
 	i_assert(idx * array->element_size < array->buffer->used);
@@ -209,7 +209,7 @@
 		    count * dest->element_size);
 }
 
-static inline unsigned int
+static inline unsigned int ATTR_PURE
 array_count_i(const struct array *array)
 {
 	return array->buffer->used / array->element_size;
@@ -217,11 +217,12 @@
 #define array_count(array) \
 	array_count_i(&(array)->arr)
 
-bool array_cmp_i(const struct array *array1, const struct array *array2);
+bool array_cmp_i(const struct array *array1,
+		 const struct array *array2) ATTR_PURE;
 #define array_cmp(array1, array2) \
 	array_cmp_i(&(array1)->arr, &(array2)->arr)
 
-void array_reverse_i(const struct array *array);
+void array_reverse_i(struct array *array);
 #define array_reverse(array) \
 	array_reverse_i(&(array)->arr)
 
--- a/src/lib/buffer.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/buffer.c	Fri Jun 20 10:41:44 2008 +0300
@@ -141,9 +141,9 @@
 	return data;
 }
 
-pool_t buffer_get_pool(buffer_t *_buf)
+pool_t buffer_get_pool(const buffer_t *_buf)
 {
-	struct real_buffer *buf = (struct real_buffer *)_buf;
+	const struct real_buffer *buf = (const struct real_buffer *)_buf;
 
 	return buf->pool;
 }
--- a/src/lib/buffer.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/buffer.h	Fri Jun 20 10:41:44 2008 +0300
@@ -33,7 +33,7 @@
 void *buffer_free_without_data(buffer_t **buf);
 
 /* Returns the pool buffer was created with. */
-pool_t buffer_get_pool(buffer_t *buf);
+pool_t buffer_get_pool(const buffer_t *buf) ATTR_PURE;
 
 /* Reset the buffer. used size and it's contents are zeroed. */
 void buffer_reset(buffer_t *buf);
@@ -85,7 +85,7 @@
 void buffer_set_used_size(buffer_t *buf, size_t used_size);
 
 /* Returns the current buffer size. */
-size_t buffer_get_size(const buffer_t *buf);
+size_t buffer_get_size(const buffer_t *buf) ATTR_PURE;
 
 /* Returns TRUE if buffer contents are identical. */
 bool buffer_cmp(const buffer_t *buf1, const buffer_t *buf2);
@@ -101,7 +101,8 @@
 }
 
 /* Returns the current used buffer size. */
-static inline size_t buffer_get_used_size(const buffer_t *buf)
+static inline size_t ATTR_PURE
+buffer_get_used_size(const buffer_t *buf)
 {
 	return buf->used;
 }
--- a/src/lib/crc32.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/crc32.h	Fri Jun 20 10:41:44 2008 +0300
@@ -1,7 +1,7 @@
 #ifndef CRC32_H
 #define CRC32_H
 
-uint32_t crc32_data(const void *data, size_t size);
-uint32_t crc32_str(const char *str);
+uint32_t crc32_data(const void *data, size_t size) ATTR_PURE;
+uint32_t crc32_str(const char *str) ATTR_PURE;
 
 #endif
--- a/src/lib/data-stack.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/data-stack.h	Fri Jun 20 10:41:44 2008 +0300
@@ -70,7 +70,7 @@
 
 /* Returns the number of bytes available in data stack without allocating
    more memory. */
-size_t t_get_bytes_available(void);
+size_t t_get_bytes_available(void) ATTR_PURE;
 
 #define t_new(type, count) \
 	((type *) t_malloc0(sizeof(type) * (count)))
--- a/src/lib/hash.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/hash.h	Fri Jun 20 10:41:44 2008 +0300
@@ -21,7 +21,7 @@
    alloconly pools. */
 void hash_clear(struct hash_table *table, bool free_collisions);
 
-void *hash_lookup(const struct hash_table *table, const void *key);
+void *hash_lookup(const struct hash_table *table, const void *key) ATTR_PURE;
 bool hash_lookup_full(const struct hash_table *table, const void *lookup_key,
 		      void **orig_key, void **value);
 
@@ -31,7 +31,7 @@
 void hash_update(struct hash_table *table, void *key, void *value);
 
 void hash_remove(struct hash_table *table, const void *key);
-unsigned int hash_count(const struct hash_table *table);
+unsigned int hash_count(const struct hash_table *table) ATTR_PURE;
 
 /* Iterates through all nodes in hash table. You may safely call hash_*()
    functions while iterating, but if you add any new nodes, they may or may
@@ -50,7 +50,7 @@
 void hash_copy(struct hash_table *dest, struct hash_table *src);
 
 /* hash function for strings */
-unsigned int str_hash(const void *p);
-unsigned int strcase_hash(const void *p);
+unsigned int str_hash(const void *p) ATTR_PURE;
+unsigned int strcase_hash(const void *p) ATTR_PURE;
 
 #endif
--- a/src/lib/hex-dec.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/hex-dec.h	Fri Jun 20 10:41:44 2008 +0300
@@ -7,6 +7,6 @@
 /* Decimal -> hex string translation. The result isn't NUL-terminated. */
 void dec2hex(unsigned char *hexstr, uintmax_t dec, unsigned int hexstr_size);
 /* Parses hex string and returns its decimal value, or 0 in case of errors */
-uintmax_t hex2dec(const unsigned char *data, unsigned int len);
+uintmax_t hex2dec(const unsigned char *data, unsigned int len) ATTR_PURE;
 
 #endif
--- a/src/lib/istream.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/istream.c	Fri Jun 20 10:41:44 2008 +0300
@@ -160,9 +160,9 @@
 	return _stream->stat(_stream, exact);
 }
 
-bool i_stream_have_bytes_left(struct istream *stream)
+bool i_stream_have_bytes_left(const struct istream *stream)
 {
-	struct istream_private *_stream = stream->real_stream;
+	const struct istream_private *_stream = stream->real_stream;
 
 	return !stream->eof || _stream->skip != _stream->pos;
 }
@@ -241,9 +241,10 @@
 	return line;
 }
 
-const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r)
+const unsigned char *
+i_stream_get_data(const struct istream *stream, size_t *size_r)
 {
-	struct istream_private *_stream = stream->real_stream;
+	const struct istream_private *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos) {
 		*size_r = 0;
@@ -254,10 +255,10 @@
         return _stream->buffer + _stream->skip;
 }
 
-unsigned char *i_stream_get_modifiable_data(struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(const struct istream *stream,
 					    size_t *size_r)
 {
-	struct istream_private *_stream = stream->real_stream;
+	const struct istream_private *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos || _stream->w_buffer == NULL) {
 		*size_r = 0;
--- a/src/lib/istream.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/istream.h	Fri Jun 20 10:41:44 2008 +0300
@@ -80,7 +80,7 @@
    compressed stream st_size could be compressed size) */
 const struct stat *i_stream_stat(struct istream *stream, bool exact);
 /* Returns TRUE if there are any bytes left to be read or in buffer. */
-bool i_stream_have_bytes_left(struct istream *stream);
+bool i_stream_have_bytes_left(const struct istream *stream) ATTR_PURE;
 
 /* Gets the next line from stream and returns it, or NULL if more data is
    needed to make a full line. Note that if the stream ends with LF not being
@@ -92,10 +92,11 @@
 
 /* Returns pointer to beginning of read data, or NULL if there's no data
    buffered. */
-const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r);
+const unsigned char *
+i_stream_get_data(const struct istream *stream, size_t *size_r);
 /* Like i_stream_get_data(), but returns non-const data. This only works with
    buffered streams (currently only file), others return NULL. */
-unsigned char *i_stream_get_modifiable_data(struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(const struct istream *stream,
 					    size_t *size_r);
 /* Like i_stream_get_data(), but read more when needed. Returns 1 if more
    than threshold bytes are available, 0 if less, -1 if error or EOF with no
--- a/src/lib/lib.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/lib.h	Fri Jun 20 10:41:44 2008 +0300
@@ -38,7 +38,7 @@
 #include "array-decl.h" /* ARRAY_DEFINE()s may exist in any header */
 #include "strfuncs.h"
 
-size_t nearest_power(size_t num);
+size_t nearest_power(size_t num) ATTR_CONST;
 
 void lib_init(void);
 void lib_deinit(void);
--- a/src/lib/network.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/network.h	Fri Jun 20 10:41:44 2008 +0300
@@ -82,10 +82,10 @@
 int net_gethostbyname(const char *addr, struct ip_addr **ips,
 		      unsigned int *ips_count);
 /* get error of net_gethostname() */
-const char *net_gethosterror(int error);
+const char *net_gethosterror(int error) ATTR_CONST;
 /* return TRUE if host lookup failed because it didn't exist (ie. not
    some error with name server) */
-int net_hosterror_notfound(int error);
+int net_hosterror_notfound(int error) ATTR_CONST;
 
 /* Get socket local address/port */
 int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port);
@@ -105,13 +105,13 @@
 int net_geterror(int fd);
 
 /* Get name of TCP service */
-const char *net_getservbyport(unsigned short port);
+const char *net_getservbyport(unsigned short port) ATTR_CONST;
 
-bool is_ipv4_address(const char *addr);
-bool is_ipv6_address(const char *addr);
+bool is_ipv4_address(const char *addr) ATTR_PURE;
+bool is_ipv6_address(const char *addr) ATTR_PURE;
 
 /* Returns TRUE if ip is in net_ip/bits network. */
-bool net_is_in_network(const struct ip_addr *ip,
-		       const struct ip_addr *net_ip, unsigned int bits);
+bool net_is_in_network(const struct ip_addr *ip, const struct ip_addr *net_ip,
+		       unsigned int bits) ATTR_PURE;
 
 #endif
--- a/src/lib/ostream-file.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/ostream-file.c	Fri Jun 20 10:41:44 2008 +0300
@@ -319,7 +319,7 @@
 	}
 }
 
-static size_t get_unused_space(struct file_ostream *fstream)
+static size_t get_unused_space(const struct file_ostream *fstream)
 {
 	if (fstream->head > fstream->tail) {
 		/* XXXT...HXXX */
@@ -333,9 +333,10 @@
 	}
 }
 
-static size_t o_stream_file_get_used_size(struct ostream_private *stream)
+static size_t o_stream_file_get_used_size(const struct ostream_private *stream)
 {
-	struct file_ostream *fstream = (struct file_ostream *)stream;
+	const struct file_ostream *fstream =
+		(const struct file_ostream *)stream;
 
 	return fstream->buffer_size - get_unused_space(fstream);
 }
--- a/src/lib/ostream-internal.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/ostream-internal.h	Fri Jun 20 10:41:44 2008 +0300
@@ -12,7 +12,7 @@
 	void (*cork)(struct ostream_private *stream, bool set);
 	int (*flush)(struct ostream_private *stream);
 	void (*flush_pending)(struct ostream_private *stream, bool set);
-	size_t (*get_used_size)(struct ostream_private *stream);
+	size_t (*get_used_size)(const struct ostream_private *stream);
 	int (*seek)(struct ostream_private *stream, uoff_t offset);
 	ssize_t (*sendv)(struct ostream_private *stream,
 			 const struct const_iovec *iov,
--- a/src/lib/ostream.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/ostream.c	Fri Jun 20 10:41:44 2008 +0300
@@ -97,9 +97,9 @@
 	_stream->flush_pending(_stream, set);
 }
 
-size_t o_stream_get_buffer_used_size(struct ostream *stream)
+size_t o_stream_get_buffer_used_size(const struct ostream *stream)
 {
-	struct ostream_private *_stream = stream->real_stream;
+	const struct ostream_private *_stream = stream->real_stream;
 
 	return _stream->get_used_size(_stream);
 }
--- a/src/lib/ostream.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/ostream.h	Fri Jun 20 10:41:44 2008 +0300
@@ -69,7 +69,7 @@
    when more data is allowed to be sent, even if the buffer itself is empty. */
 void o_stream_set_flush_pending(struct ostream *stream, bool set);
 /* Returns number of bytes currently in buffer. */
-size_t o_stream_get_buffer_used_size(struct ostream *stream);
+size_t o_stream_get_buffer_used_size(const struct ostream *stream) ATTR_PURE;
 
 /* Seek to specified position from beginning of file. This works only for
    files. Returns 1 if successful, -1 if error. */
--- a/src/lib/primes.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/primes.h	Fri Jun 20 10:41:44 2008 +0300
@@ -3,6 +3,6 @@
 
 /* Returns a prime close to specified number, or the number itself if it's
    a prime. Note that the returned value may be smaller than requested! */
-unsigned int primes_closest(unsigned int num);
+unsigned int primes_closest(unsigned int num) ATTR_CONST;
 
 #endif
--- a/src/lib/priorityq.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/priorityq.h	Fri Jun 20 10:41:44 2008 +0300
@@ -20,7 +20,7 @@
 void priorityq_deinit(struct priorityq **pq);
 
 /* Return number of items in the queue. */
-unsigned int priorityq_count(const struct priorityq *pq);
+unsigned int priorityq_count(const struct priorityq *pq) ATTR_PURE;
 
 /* Add a new item to the queue. */
 void priorityq_add(struct priorityq *pq, struct priorityq_item *item);
--- a/src/lib/seq-range-array.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/seq-range-array.h	Fri Jun 20 10:41:44 2008 +0300
@@ -32,12 +32,13 @@
 seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
 			  const ARRAY_TYPE(seq_range) *src);
 /* Returns TRUE if sequence exists in the range. */
-bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq);
+bool seq_range_exists(const ARRAY_TYPE(seq_range) *array,
+		      uint32_t seq) ATTR_PURE;
 /* Returns TRUE if arrays have common sequences. */
 bool seq_range_array_have_common(const ARRAY_TYPE(seq_range) *array1,
-				 const ARRAY_TYPE(seq_range) *array2);
+				 const ARRAY_TYPE(seq_range) *array2) ATTR_PURE;
 /* Return number of sequences in the range. */
-unsigned int seq_range_count(const ARRAY_TYPE(seq_range) *array);
+unsigned int seq_range_count(const ARRAY_TYPE(seq_range) *array) ATTR_PURE;
 
 /* Invert the sequence range. For example 5:6 -> min_seq:4,7:max_seq. */
 void seq_range_array_invert(ARRAY_TYPE(seq_range) *array,
--- a/src/lib/str.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/str.h	Fri Jun 20 10:41:44 2008 +0300
@@ -7,10 +7,10 @@
 char *str_free_without_data(string_t **str);
 
 const char *str_c(string_t *str);
-const unsigned char *str_data(const string_t *str);
+const unsigned char *str_data(const string_t *str) ATTR_PURE;
 char *str_c_modifiable(string_t *str);
-size_t str_len(const string_t *str);
-bool str_equals(const string_t *str1, const string_t *str2);
+size_t str_len(const string_t *str) ATTR_PURE;
+bool str_equals(const string_t *str1, const string_t *str2) ATTR_PURE;
 
 /* Append string/character */
 void str_append(string_t *str, const char *cstr);
--- a/src/lib/strfuncs.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/strfuncs.h	Fri Jun 20 10:41:44 2008 +0300
@@ -41,7 +41,7 @@
 
 /* Return TRUE if all characters in string are numbers.
    Stop when `end_char' is found from string. */
-bool is_numeric(const char *str, char end_char);
+bool is_numeric(const char *str, char end_char) ATTR_PURE;
 
 /* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */
 int i_strocpy(char *dest, const char *src, size_t dstsize);
@@ -51,12 +51,12 @@
 const char *t_str_lcase(const char *str);
 const char *t_str_ucase(const char *str);
 
-int null_strcmp(const char *s1, const char *s2);
-int bsearch_strcmp(const void *p1, const void *p2);
-int bsearch_strcasecmp(const void *p1, const void *p2);
-int i_memcasecmp(const void *p1, const void *p2, size_t size);
-int i_strcmp_p(const void *p1, const void *p2);
-int i_strcasecmp_p(const void *p1, const void *p2);
+int null_strcmp(const char *s1, const char *s2) ATTR_PURE;
+int bsearch_strcmp(const void *p1, const void *p2) ATTR_PURE;
+int bsearch_strcasecmp(const void *p1, const void *p2) ATTR_PURE;
+int i_memcasecmp(const void *p1, const void *p2, size_t size) ATTR_PURE;
+int i_strcmp_p(const void *p1, const void *p2) ATTR_PURE;
+int i_strcasecmp_p(const void *p1, const void *p2) ATTR_PURE;
 
 /* separators is an array of separator characters, not a separator string. */
 char **p_strsplit(pool_t pool, const char *data, const char *separators)
@@ -74,7 +74,7 @@
 const char *dec2str(uintmax_t number);
 
 /* Return length of NULL-terminated list string array */
-unsigned int str_array_length(const char *const *arr);
+unsigned int str_array_length(const char *const *arr) ATTR_PURE;
 /* Return all strings from array joined into one string. */
 const char *t_strarray_join(const char *const *arr, const char *separator)
 	ATTR_MALLOC;
--- a/src/lib/unichar.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/unichar.h	Fri Jun 20 10:41:44 2008 +0300
@@ -10,7 +10,7 @@
 extern const uint8_t *const uni_utf8_non1_bytes;
 
 /* Returns number of characters in a NUL-terminated unicode string */
-unsigned int uni_strlen(const unichar_t *str);
+unsigned int uni_strlen(const unichar_t *str) ATTR_PURE;
 /* Translates UTF-8 input to UCS-4 output. Returns 0 if ok, -1 if input was
    invalid */
 int uni_utf8_to_ucs4(const char *input, ARRAY_TYPE(unichars) *output);
@@ -23,11 +23,12 @@
 int uni_utf8_get_char(const char *input, unichar_t *chr_r);
 int uni_utf8_get_char_n(const void *input, size_t max_len, unichar_t *chr_r);
 /* Returns UTF-8 string length with maximum input size. */
-unsigned int uni_utf8_strlen_n(const void *input, size_t size);
+unsigned int uni_utf8_strlen_n(const void *input, size_t size) ATTR_PURE;
 
 /* Returns the number of bytes belonging to this partial UTF-8 character.
    Invalid input is returned with length 1. */
-static inline unsigned int uni_utf8_char_bytes(char chr)
+static inline unsigned int ATTR_CONST
+uni_utf8_char_bytes(char chr)
 {
 	/* 0x00 .. 0x7f are ASCII. 0x80 .. 0xC1 are invalid. */
 	if ((uint8_t)chr < (192 + 2))
@@ -36,7 +37,7 @@
 }
 
 /* Return given character in titlecase. */
-unichar_t uni_ucs4_to_titlecase(unichar_t chr);
+unichar_t uni_ucs4_to_titlecase(unichar_t chr) ATTR_CONST;
 
 /* Convert UTF-8 input to titlecase and decompose the titlecase characters to
    output buffer. Returns 0 if ok, -1 if input was invalid. This generates
--- a/src/lib/var-expand.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/lib/var-expand.h	Fri Jun 20 10:41:44 2008 +0300
@@ -13,7 +13,7 @@
 
 /* Returns the actual key character for given string, ie. skip any modifiers
    that are before it. The string should be the data after the '%' character. */
-char var_get_key(const char *str);
+char var_get_key(const char *str) ATTR_PURE;
 
 const struct var_expand_table *
 var_expand_table_build(char key, const char *value, char key2, ...);
--- a/src/login-common/client-common.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/client-common.h	Fri Jun 20 10:41:44 2008 +0300
@@ -39,7 +39,7 @@
 
 void client_link(struct client *client);
 void client_unlink(struct client *client);
-unsigned int clients_get_count(void);
+unsigned int clients_get_count(void) ATTR_PURE;
 
 void client_syslog(struct client *client, const char *msg);
 
--- a/src/login-common/login-proxy.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/login-proxy.c	Fri Jun 20 10:41:44 2008 +0300
@@ -224,7 +224,7 @@
 	main_listen_start();
 }
 
-bool login_proxy_is_ourself(struct client *client, const char *host,
+bool login_proxy_is_ourself(const struct client *client, const char *host,
 			    unsigned int port, const char *destuser)
 {
 	struct ip_addr ip;
@@ -240,12 +240,12 @@
 	return strcmp(client->virtual_user, destuser) == 0;
 }
 
-const char *login_proxy_get_host(struct login_proxy *proxy)
+const char *login_proxy_get_host(const struct login_proxy *proxy)
 {
 	return proxy->host;
 }
 
-unsigned int login_proxy_get_port(struct login_proxy *proxy)
+unsigned int login_proxy_get_port(const struct login_proxy *proxy)
 {
 	return proxy->port;
 }
--- a/src/login-common/login-proxy.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/login-proxy.h	Fri Jun 20 10:41:44 2008 +0300
@@ -28,7 +28,7 @@
 
 /* Return TRUE if host/port/destuser combination points to same as current
    connection. */
-bool login_proxy_is_ourself(struct client *client, const char *host,
+bool login_proxy_is_ourself(const struct client *client, const char *host,
 			    unsigned int port, const char *destuser);
 
 /* Detach proxy from client. This is done after the authentication is
@@ -36,11 +36,11 @@
 void login_proxy_detach(struct login_proxy *proxy, struct istream *client_input,
 			struct ostream *client_output);
 
-const char *login_proxy_get_host(struct login_proxy *proxy);
-unsigned int login_proxy_get_port(struct login_proxy *proxy);
+const char *login_proxy_get_host(const struct login_proxy *proxy) ATTR_PURE;
+unsigned int login_proxy_get_port(const struct login_proxy *proxy) ATTR_PURE;
 
 /* Return number of active detached login proxies */
-unsigned int login_proxy_get_count(void);
+unsigned int login_proxy_get_count(void) ATTR_PURE;
 
 void login_proxy_deinit(void);
 
--- a/src/login-common/ssl-proxy-openssl.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/ssl-proxy-openssl.c	Fri Jun 20 10:41:44 2008 +0300
@@ -512,7 +512,7 @@
 	return sfd[1];
 }
 
-bool ssl_proxy_has_valid_client_cert(struct ssl_proxy *proxy)
+bool ssl_proxy_has_valid_client_cert(const struct ssl_proxy *proxy)
 {
 	return proxy->cert_received && !proxy->cert_broken;
 }
@@ -540,12 +540,12 @@
 	return *name == '\0' ? NULL : name;
 }
 
-bool ssl_proxy_is_handshaked(struct ssl_proxy *proxy)
+bool ssl_proxy_is_handshaked(const struct ssl_proxy *proxy)
 {
 	return proxy->handshaked;
 }
 
-const char *ssl_proxy_get_last_error(struct ssl_proxy *proxy)
+const char *ssl_proxy_get_last_error(const struct ssl_proxy *proxy)
 {
 	return proxy->last_error;
 }
--- a/src/login-common/ssl-proxy.c	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/ssl-proxy.c	Fri Jun 20 10:41:44 2008 +0300
@@ -16,7 +16,7 @@
 	return -1;
 }
 
-bool ssl_proxy_has_valid_client_cert(struct ssl_proxy *proxy ATTR_UNUSED)
+bool ssl_proxy_has_valid_client_cert(const struct ssl_proxy *proxy ATTR_UNUSED)
 {
 	return FALSE;
 }
@@ -26,12 +26,12 @@
 	return NULL;
 }
 
-bool ssl_proxy_is_handshaked(struct ssl_proxy *proxy ATTR_UNUSED)
+bool ssl_proxy_is_handshaked(const struct ssl_proxy *proxy ATTR_UNUSED)
 {
 	return FALSE;
 }
 
-const char *ssl_proxy_get_last_error(struct ssl_proxy *proxy ATTR_UNUSED)
+const char *ssl_proxy_get_last_error(const struct ssl_proxy *proxy ATTR_UNUSED)
 {
 	return NULL;
 }
--- a/src/login-common/ssl-proxy.h	Fri Jun 20 10:41:27 2008 +0300
+++ b/src/login-common/ssl-proxy.h	Fri Jun 20 10:41:44 2008 +0300
@@ -10,14 +10,14 @@
    must use from now on, or -1 if error occurred. Unless -1 is returned,
    the given fd must be simply forgotten. */
 int ssl_proxy_new(int fd, struct ip_addr *ip, struct ssl_proxy **proxy_r);
-bool ssl_proxy_has_valid_client_cert(struct ssl_proxy *proxy);
+bool ssl_proxy_has_valid_client_cert(const struct ssl_proxy *proxy) ATTR_PURE;
 const char *ssl_proxy_get_peer_name(struct ssl_proxy *proxy);
-bool ssl_proxy_is_handshaked(struct ssl_proxy *proxy);
-const char *ssl_proxy_get_last_error(struct ssl_proxy *proxy);
+bool ssl_proxy_is_handshaked(const struct ssl_proxy *proxy) ATTR_PURE;
+const char *ssl_proxy_get_last_error(const struct ssl_proxy *proxy) ATTR_PURE;
 void ssl_proxy_free(struct ssl_proxy *proxy);
 
 /* Return number of active SSL proxies */
-unsigned int ssl_proxy_get_count(void);
+unsigned int ssl_proxy_get_count(void) ATTR_PURE;
 
 void ssl_proxy_init(void);
 void ssl_proxy_deinit(void);