]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Add ssl_iostream_settings_equals()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 5 Nov 2017 16:29:13 +0000 (18:29 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 6 Nov 2017 23:09:00 +0000 (01:09 +0200)
src/lib-ssl-iostream/iostream-ssl-private.h
src/lib-ssl-iostream/iostream-ssl.c

index 2972b38ac8f366a296c10a8300ac826d6f7d6c21..1858a66472ef3d0836437efdadbd91c4254ed544 100644 (file)
@@ -40,4 +40,9 @@ struct iostream_ssl_vfuncs {
 
 void iostream_ssl_module_init(const struct iostream_ssl_vfuncs *vfuncs);
 
+/* Returns TRUE if both settings are equal. Note that NULL and "" aren't
+   treated equal. */
+bool ssl_iostream_settings_equals(const struct ssl_iostream_settings *set1,
+                                 const struct ssl_iostream_settings *set2);
+
 #endif
index 343f1daa9f061e97ca9cd0ec7ec1a4be74b2cba7..a7ea39efeba8b965c54e855f4ef06b3c7e022f36 100644 (file)
@@ -262,3 +262,28 @@ void ssl_iostream_settings_init_from(pool_t pool,
                *dest_str = p_strdup(pool, *src_str);
        }
 }
+
+bool ssl_iostream_settings_equals(const struct ssl_iostream_settings *set1,
+                                 const struct ssl_iostream_settings *set2)
+{
+       struct ssl_iostream_settings set1_nonstr, set2_nonstr;
+       unsigned int i;
+
+       set1_nonstr = *set1;
+       set2_nonstr = *set2;
+       for (i = 0; i < N_ELEMENTS(ssl_iostream_settings_string_offsets); i++) {
+               const size_t offset = ssl_iostream_settings_string_offsets[i];
+               const char *const *str1 = CONST_PTR_OFFSET(set1, offset);
+               const char *const *str2 = CONST_PTR_OFFSET(set2, offset);
+
+               if (null_strcmp(*str1, *str2) != 0)
+                       return FALSE;
+
+               /* clear away the string pointer from the settings struct */
+               memset(PTR_OFFSET(&set1_nonstr, offset), 0, sizeof(*str1));
+               memset(PTR_OFFSET(&set2_nonstr, offset), 0, sizeof(*str2));
+       }
+       /* The set*_nonstr no longer have any pointers, so we can compare them
+          directly. */
+       return memcmp(&set1_nonstr, &set2_nonstr, sizeof(set1_nonstr)) == 0;
+}