]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added more consts, ATTR_CONSTs and ATTR_PUREs.
authorTimo Sirainen <tss@iki.fi>
Fri, 20 Jun 2008 07:41:44 +0000 (10:41 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 20 Jun 2008 07:41:44 +0000 (10:41 +0300)
--HG--
branch : HEAD

43 files changed:
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

index 0643b34da1e4fad38ae461b983dbb71e971ba2dd..adc73adc508101541794f2e92a4093a99d88e43a 100644 (file)
@@ -321,8 +321,8 @@ client_get_keyword_names(struct client *client, ARRAY_TYPE(keywords) *dest,
        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;
index 2e204fd43bfa7718dd4c6c2d12b926b327d298bc..f29ddbd3fe9d1f5253a77df03481d98fc556608c 100644 (file)
@@ -61,8 +61,9 @@ const char *const *
 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);
index a72c3c5e24573e8f231620e4ce16762aa88f45ba..3ab42edf08b98a3ff34e2a69f3f69723086195f9 100644 (file)
@@ -21,7 +21,7 @@ void charset_to_utf8_end(struct charset_translation **t);
 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. */
index 0c0640fa38ed2151f8b6291138c5ffa6f0bf0a78..edfad42a9cd77119420820b26929bd3a8369de1f 100644 (file)
@@ -446,9 +446,9 @@ static void part_write_body(const struct message_part *part,
        }
 }
 
-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);
 
index 7fb65b1234d2a1d1637955bbf7bbd1ee34239413..90862522fb13626b487f4729f942b0740f7a4ee1 100644 (file)
@@ -10,7 +10,8 @@ void imap_bodystructure_parse_header(pool_t pool, struct message_part *part,
 
 /* 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);
index 00de547986db47927d9c9b1ea3791a46d6a780a0..d4af80c0879e31771e0bb1d522204ca61319c163 100644 (file)
@@ -370,7 +370,7 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
        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;
 }
index e9491cacb698a890600aab9c44fdefb05d12ab56..d4919ea83ae263edb5c404c62fd46d1abd13d158 100644 (file)
@@ -55,7 +55,8 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
                              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,
index 0d490266aef6e620cb89a4899235073d9cc1ce10..4f71fd0a8bf91e6ad708637617638e1b463e6ec1 100644 (file)
@@ -313,7 +313,7 @@ const char *mail_namespace_get_vname(struct mail_namespace *ns, string_t *dest,
        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 @@ mail_namespace_find_inbox(struct mail_namespace *namespaces)
        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;
index 6ed906b9388659596d5fff0b177a93fe260642eb..f9c737f15b618311bff739d5546ccd57150a35e8 100644 (file)
@@ -53,7 +53,8 @@ const char *mail_namespace_get_vname(struct mail_namespace *ns, string_t *dest,
                                     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 @@ struct mail_namespace *
 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. */
index d0587927ecefea45f8dc0ed464371997eb9df6db..dfa2a774f59d3f143c6c2193465b04b6659c0990 100644 (file)
@@ -328,12 +328,13 @@ char mail_storage_get_hierarchy_sep(struct mail_storage *storage)
        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 @@ int mailbox_close(struct mailbox **_box)
        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(struct mailbox *box, unsigned int min_interval,
 
 void mailbox_notify_changes_stop(struct mailbox *box)
 {
-
        mailbox_notify_changes(box, 0, NULL, NULL);
 }
 
@@ -755,13 +755,13 @@ void mailbox_transaction_rollback(struct mailbox_transaction_context **_t)
        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;
 }
index de5386997d025657a0d3526718b5424050b5d1ee..bf238902a723cc263df3605a5bb23fe7af7a4501 100644 (file)
@@ -250,8 +250,10 @@ int mail_storage_create(struct mail_namespace *ns, const char *driver,
 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 @@ int mailbox_enable(struct mailbox *box, enum mailbox_feature features);
 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 @@ int mailbox_transaction_commit_get_uids(struct mailbox_transaction_context **t,
                                        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). */
index 860f9e60288d44ce4a8696177c530a01318db6fc..c10ee7bc9caf41a14b634827982360957fa0f529 100644 (file)
@@ -216,22 +216,23 @@ void mailbox_list_deinit(struct mailbox_list *list)
        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;
 }
index 5925d1271e479e6aeeb78b4184bcad48ea16a7ec..9bdf9fdc3cfbb059e7a14afa495a6bd0a1bfa576 100644 (file)
@@ -128,10 +128,13 @@ void mailbox_list_init(struct mailbox_list *list, struct mail_namespace *ns,
                       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
index 9fb6c51eb622eb4e092e6d30d612214c72a74fa1..fffe3106280728089d04e5aca7010d28c8413f22 100644 (file)
@@ -29,10 +29,10 @@ void aqueue_delete(struct aqueue *aqueue, unsigned int n);
 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;
index 08004a0cf9d2f9d8e10d7a1338a8840e2b906a85..c0196568229d1eddf4abd192c4527be605fa221b 100644 (file)
@@ -66,7 +66,7 @@ bool array_cmp_i(const struct array *array1, const struct array *array2)
        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);
index d384c2725da6cec6b4c8d9ae74683f0fd42cdff1..6ac50c460ce4e2029f6aab31138ab4a58baef8ce 100644 (file)
@@ -148,7 +148,7 @@ array_get_i(const struct array *array, unsigned int *count_r)
 #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 @@ array_copy(struct array *dest, unsigned int dest_idx,
                    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 @@ array_count_i(const struct array *array)
 #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)
 
index ff872e29caa04dfa0a0ab1a8a4869b54a9318171..5aaa3158ff3b9a9f4e8419dfa8e8a99e696798f3 100644 (file)
@@ -141,9 +141,9 @@ void *buffer_free_without_data(buffer_t **_buf)
        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;
 }
index 37f64cb09eca4a9922e58ef5a1eeb5446b9399b2..b9e181501cd8b5442399f376638ba9102994370f 100644 (file)
@@ -33,7 +33,7 @@ void buffer_free(buffer_t **buf);
 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_get_modifiable_data(const buffer_t *buf, size_t *used_size_r);
 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 @@ buffer_get_data(const buffer_t *buf, size_t *used_size_r)
 }
 
 /* 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;
 }
index ebcaf7082ef56d7933e8dd69df4180adfc6507c7..5bcfe01c62b319a742ad30fcb0fc14a11c804755 100644 (file)
@@ -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
index 2d38770e0809d46be74c62f3232c534d1077f3ae..6ae0060c611e4a293ffe6de323d393ba26b435b7 100644 (file)
@@ -70,7 +70,7 @@ bool t_try_realloc(void *mem, size_t size);
 
 /* 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)))
index 8f92a37ae726c90af249eb99cacb81f02d6f7bfd..d118f2a41c6885c5795273159821db18718dc176 100644 (file)
@@ -21,7 +21,7 @@ void hash_destroy(struct hash_table **table);
    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_insert(struct hash_table *table, void *key, void *value);
 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_thaw(struct hash_table *table);
 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
index dbd62428c4ded1c11a8a1ef4aade30547a4cbe05..33e87bb7cc23810d8a671932896108c2f2f6a308 100644 (file)
@@ -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
index cd2c19e7f56179fb957ed059472ed2203897b50d..7a0245dc57a46a97c0086585cbcbd1d3248b88b9 100644 (file)
@@ -160,9 +160,9 @@ const struct stat *i_stream_stat(struct istream *stream, bool exact)
        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 @@ char *i_stream_read_next_line(struct istream *stream)
        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 @@ const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r)
         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;
index 637fa143ce6efe3b880c513b349981ba6f89e680..4834dccd67564616b2c9e42dab4971ac8d785819 100644 (file)
@@ -80,7 +80,7 @@ void i_stream_seek_mark(struct istream *stream, uoff_t v_offset);
    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 @@ char *i_stream_read_next_line(struct istream *stream);
 
 /* 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
index ca9e9adf7b764e1b7211f1831dbd064a55cdfbd2..f33d35af85d4bc0259661362ca016209546b53be 100644 (file)
@@ -38,7 +38,7 @@ struct ostream;
 #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);
index df415b6d841d349c10fc140f9c9b5b14abf0aa5f..5011443be7bca6f6adf6ed10abd20359196ad1d9 100644 (file)
@@ -82,10 +82,10 @@ ssize_t net_transmit(int fd, const void *data, size_t len);
 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_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
 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
index 58e197b93757f790acba315d9dbfee8efd09e507..7ac7fc600b59354bf24b7efc2489f33275bf22c7 100644 (file)
@@ -319,7 +319,7 @@ o_stream_file_flush_pending(struct ostream_private *stream, bool set)
        }
 }
 
-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 get_unused_space(struct file_ostream *fstream)
        }
 }
 
-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);
 }
index 935ecb83eea3ee4310f88316a0a76fb55000d6eb..a2144b1a7b11454640aa58d0a9320d1891164f41 100644 (file)
@@ -12,7 +12,7 @@ struct ostream_private {
        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,
index b3e86e8eca0e4e1ce373b3536681798f8da3d56c..28fb06bacf5928d05934a4304f2bf2368ab9a707 100644 (file)
@@ -97,9 +97,9 @@ void o_stream_set_flush_pending(struct ostream *stream, bool set)
        _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);
 }
index 53efe8f74c69f511d909256c5113256e2761e001..e9ab1a7dae7d28e9d519aa86d0cd1aa2b4279c72 100644 (file)
@@ -69,7 +69,7 @@ int o_stream_flush(struct ostream *stream);
    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. */
index 4330bdbdf1840db30f17e2a379bce5c10b0f1d9e..8153d6d8d63b0299fbdd1c05dfa587e71808d5ac 100644 (file)
@@ -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
index bd725892542fe09fb8487b7f031da4200e9ae4a6..7e80107fd43bf26c08721626145b9ed97be1ee16 100644 (file)
@@ -20,7 +20,7 @@ priorityq_init(priorityq_cmp_callback_t *cmp_callback, unsigned int init_size);
 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);
index 6d1846b08c61dbed7e771d073400380092c1a220..005121978c7d4ab19ec903e3c2e8a1fd5bc717fd 100644 (file)
@@ -32,12 +32,13 @@ unsigned int
 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,
index 979690af856fd41dcdab373f856d9548b109e51b..1ca51b5a97b71f777377eb308c84e67e3ff5504b 100644 (file)
@@ -7,10 +7,10 @@ void str_free(string_t **str);
 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);
index 95e72f42cfb9460a4ff07afc5a8bbb7b266c933c..eb0b59e0f3bca7541cd388a0fba1b1c261734126 100644 (file)
@@ -41,7 +41,7 @@ const char *t_strcut(const char *str, char cutchar);
 
 /* 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 @@ char *str_lcase(char *str);
 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 @@ void p_strsplit_free(pool_t pool, char **arr);
 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;
index 870bd9db940ffe2fe57091e4ba58679c03e14b2c..3039c391b16badad21081ff9a4c6025d4e4ff666 100644 (file)
@@ -10,7 +10,7 @@ ARRAY_DEFINE_TYPE(unichars, unichar_t);
 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 @@ void uni_ucs4_to_utf8_c(unichar_t chr, buffer_t *output);
 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 @@ static inline unsigned int uni_utf8_char_bytes(char chr)
 }
 
 /* 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
index 3452fafaeeb9c8235062f9e492e85fdf43b08e5c..d528fb12c7bd67d4df54cdd9a8c9f49d5aa10f3c 100644 (file)
@@ -13,7 +13,7 @@ void var_expand(string_t *dest, const char *str,
 
 /* 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, ...);
index 271ddc64a7103b694d266ab3f4c113b22fcd3861..850412bd66ce771ea3e9e7871b3fd8f0dc85426f 100644 (file)
@@ -39,7 +39,7 @@ struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
 
 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);
 
index 3e64c1e1994270d7d9b41cdf1ab31acb10007265..1130a8b9534d68ebf331b35a926485e73ba86163 100644 (file)
@@ -224,7 +224,7 @@ void login_proxy_free(struct login_proxy *proxy)
        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 @@ bool login_proxy_is_ourself(struct client *client, const char *host,
        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;
 }
index fddebe45cbe6167b47a95b5f9a2f1ecd30a04c8d..3517b0bcc4ba24ba1dc5a481c1a39f9a0897c4e2 100644 (file)
@@ -28,7 +28,7 @@ void login_proxy_free(struct login_proxy *proxy);
 
 /* 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 @@ bool login_proxy_is_ourself(struct client *client, const char *host,
 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);
 
index 089a2f64989478d8c5bc462577ceda5aa682447d..9c97031d788590fe260a5ef5190a9f3ea6c4f438 100644 (file)
@@ -512,7 +512,7 @@ int ssl_proxy_new(int fd, struct ip_addr *ip, struct ssl_proxy **proxy_r)
        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 @@ const char *ssl_proxy_get_peer_name(struct ssl_proxy *proxy)
        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;
 }
index efa50456754d5e86c0f19e65762116c3c684689b..8b5acbda18a0f93cb2e2751c1926b3b60e7241ed 100644 (file)
@@ -16,7 +16,7 @@ int ssl_proxy_new(int fd ATTR_UNUSED, struct ip_addr *ip ATTR_UNUSED,
        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 @@ const char *ssl_proxy_get_peer_name(struct ssl_proxy *proxy ATTR_UNUSED)
        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;
 }
index a20ba3f12469f155fa4e946fa00aed0b987bf569..aa7d442316223c85fabb609aef26f19ab1990f85 100644 (file)
@@ -10,14 +10,14 @@ extern bool ssl_initialized;
    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);