diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-19 17:19:49 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-19 17:20:02 +0200 |
commit | cac1c211ba0247b978961630b7ee147956b29e0a (patch) | |
tree | 50e7dfda4003199085c07b243d106363917393d7 /src | |
parent | 97164b43a8b69cc1bf07c3384586f58c99873ce8 (diff) | |
download | gnunet-cac1c211ba0247b978961630b7ee147956b29e0a.tar.gz gnunet-cac1c211ba0247b978961630b7ee147956b29e0a.zip |
indenting
Diffstat (limited to 'src')
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 205 |
1 files changed, 104 insertions, 101 deletions
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 159f078ee..5061f8493 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include "gnunet_tun_lib.h" | 35 | #include "gnunet_tun_lib.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from(kind, "gnsrecord", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Convert a UTF-8 string to UTF-8 lowercase | 41 | * Convert a UTF-8 string to UTF-8 lowercase |
@@ -43,12 +43,12 @@ | |||
43 | * @return converted result | 43 | * @return converted result |
44 | */ | 44 | */ |
45 | char * | 45 | char * |
46 | GNUNET_GNSRECORD_string_to_lowercase(const char *src) | 46 | GNUNET_GNSRECORD_string_to_lowercase (const char *src) |
47 | { | 47 | { |
48 | char *res; | 48 | char *res; |
49 | 49 | ||
50 | res = GNUNET_strdup(src); | 50 | res = GNUNET_strdup (src); |
51 | GNUNET_STRINGS_utf8_tolower(src, res); | 51 | GNUNET_STRINGS_utf8_tolower (src, res); |
52 | return res; | 52 | return res; |
53 | } | 53 | } |
54 | 54 | ||
@@ -62,19 +62,20 @@ GNUNET_GNSRECORD_string_to_lowercase(const char *src) | |||
62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s | 62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s |
63 | */ | 63 | */ |
64 | const char * | 64 | const char * |
65 | GNUNET_GNSRECORD_z2s(const struct GNUNET_CRYPTO_EcdsaPublicKey *z) | 65 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) |
66 | { | 66 | { |
67 | static char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) * 8]; | 67 | static char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) * 8]; |
68 | char *end; | 68 | char *end; |
69 | 69 | ||
70 | end = GNUNET_STRINGS_data_to_string((const unsigned char *)z, | 70 | end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z, |
71 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 71 | sizeof(struct |
72 | buf, sizeof(buf)); | 72 | GNUNET_CRYPTO_EcdsaPublicKey), |
73 | buf, sizeof(buf)); | ||
73 | if (NULL == end) | 74 | if (NULL == end) |
74 | { | 75 | { |
75 | GNUNET_break(0); | 76 | GNUNET_break (0); |
76 | return NULL; | 77 | return NULL; |
77 | } | 78 | } |
78 | *end = '\0'; | 79 | *end = '\0'; |
79 | return buf; | 80 | return buf; |
80 | } | 81 | } |
@@ -90,51 +91,51 @@ GNUNET_GNSRECORD_z2s(const struct GNUNET_CRYPTO_EcdsaPublicKey *z) | |||
90 | * @return #GNUNET_YES if the records are equal or #GNUNET_NO if they are not | 91 | * @return #GNUNET_YES if the records are equal or #GNUNET_NO if they are not |
91 | */ | 92 | */ |
92 | int | 93 | int |
93 | GNUNET_GNSRECORD_records_cmp(const struct GNUNET_GNSRECORD_Data *a, | 94 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, |
94 | const struct GNUNET_GNSRECORD_Data *b) | 95 | const struct GNUNET_GNSRECORD_Data *b) |
95 | { | 96 | { |
96 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 97 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
97 | "Comparing records\n"); | 98 | "Comparing records\n"); |
98 | if (a->record_type != b->record_type) | 99 | if (a->record_type != b->record_type) |
99 | { | 100 | { |
100 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 101 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
101 | "Record type %lu != %lu\n", a->record_type, b->record_type); | 102 | "Record type %lu != %lu\n", a->record_type, b->record_type); |
102 | return GNUNET_NO; | 103 | return GNUNET_NO; |
103 | } | 104 | } |
104 | if ((a->expiration_time != b->expiration_time) && | 105 | if ((a->expiration_time != b->expiration_time) && |
105 | ((a->expiration_time != 0) && (b->expiration_time != 0))) | 106 | ((a->expiration_time != 0) && (b->expiration_time != 0))) |
106 | { | 107 | { |
107 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 108 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
108 | "Expiration time %llu != %llu\n", | 109 | "Expiration time %llu != %llu\n", |
109 | a->expiration_time, | 110 | a->expiration_time, |
110 | b->expiration_time); | 111 | b->expiration_time); |
111 | return GNUNET_NO; | 112 | return GNUNET_NO; |
112 | } | 113 | } |
113 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) | 114 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) |
114 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) | 115 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) |
115 | { | 116 | { |
116 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
117 | "Flags %lu (%lu) != %lu (%lu)\n", a->flags, | 118 | "Flags %lu (%lu) != %lu (%lu)\n", a->flags, |
118 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, | 119 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, |
119 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); | 120 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); |
120 | return GNUNET_NO; | 121 | return GNUNET_NO; |
121 | } | 122 | } |
122 | if (a->data_size != b->data_size) | 123 | if (a->data_size != b->data_size) |
123 | { | 124 | { |
124 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 125 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
125 | "Data size %lu != %lu\n", | 126 | "Data size %lu != %lu\n", |
126 | a->data_size, | 127 | a->data_size, |
127 | b->data_size); | 128 | b->data_size); |
128 | return GNUNET_NO; | 129 | return GNUNET_NO; |
129 | } | 130 | } |
130 | if (0 != memcmp(a->data, b->data, a->data_size)) | 131 | if (0 != memcmp (a->data, b->data, a->data_size)) |
131 | { | 132 | { |
132 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 133 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
133 | "Data contents do not match\n"); | 134 | "Data contents do not match\n"); |
134 | return GNUNET_NO; | 135 | return GNUNET_NO; |
135 | } | 136 | } |
136 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 137 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Records are equal\n"); | 138 | "Records are equal\n"); |
138 | return GNUNET_YES; | 139 | return GNUNET_YES; |
139 | } | 140 | } |
140 | 141 | ||
@@ -149,8 +150,9 @@ GNUNET_GNSRECORD_records_cmp(const struct GNUNET_GNSRECORD_Data *a, | |||
149 | * @return absolute expiration time | 150 | * @return absolute expiration time |
150 | */ | 151 | */ |
151 | struct GNUNET_TIME_Absolute | 152 | struct GNUNET_TIME_Absolute |
152 | GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, | 153 | GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, |
153 | const struct GNUNET_GNSRECORD_Data *rd) | 154 | const struct |
155 | GNUNET_GNSRECORD_Data *rd) | ||
154 | { | 156 | { |
155 | struct GNUNET_TIME_Absolute expire; | 157 | struct GNUNET_TIME_Absolute expire; |
156 | struct GNUNET_TIME_Absolute at; | 158 | struct GNUNET_TIME_Absolute at; |
@@ -162,44 +164,44 @@ GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, | |||
162 | return GNUNET_TIME_UNIT_ZERO_ABS; | 164 | return GNUNET_TIME_UNIT_ZERO_ABS; |
163 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; | 165 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; |
164 | for (unsigned int c = 0; c < rd_count; c++) | 166 | for (unsigned int c = 0; c < rd_count; c++) |
167 | { | ||
168 | if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
165 | { | 169 | { |
166 | if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 170 | rt.rel_value_us = rd[c].expiration_time; |
167 | { | 171 | at = GNUNET_TIME_relative_to_absolute (rt); |
168 | rt.rel_value_us = rd[c].expiration_time; | 172 | } |
169 | at = GNUNET_TIME_relative_to_absolute(rt); | 173 | else |
170 | } | 174 | { |
171 | else | 175 | at.abs_value_us = rd[c].expiration_time; |
172 | { | 176 | } |
173 | at.abs_value_us = rd[c].expiration_time; | ||
174 | } | ||
175 | 177 | ||
176 | for (unsigned int c2 = 0; c2 < rd_count; c2++) | 178 | for (unsigned int c2 = 0; c2 < rd_count; c2++) |
177 | { | 179 | { |
178 | /* Check for shadow record */ | 180 | /* Check for shadow record */ |
179 | if ((c == c2) || | 181 | if ((c == c2) || |
180 | (rd[c].record_type != rd[c2].record_type) || | 182 | (rd[c].record_type != rd[c2].record_type) || |
181 | (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))) | 183 | (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))) |
182 | continue; | 184 | continue; |
183 | /* We have a shadow record */ | 185 | /* We have a shadow record */ |
184 | if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 186 | if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
185 | { | 187 | { |
186 | rt_shadow.rel_value_us = rd[c2].expiration_time; | 188 | rt_shadow.rel_value_us = rd[c2].expiration_time; |
187 | at_shadow = GNUNET_TIME_relative_to_absolute(rt_shadow); | 189 | at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow); |
188 | } | 190 | } |
189 | else | 191 | else |
190 | { | 192 | { |
191 | at_shadow.abs_value_us = rd[c2].expiration_time; | 193 | at_shadow.abs_value_us = rd[c2].expiration_time; |
192 | } | 194 | } |
193 | at = GNUNET_TIME_absolute_max(at, | 195 | at = GNUNET_TIME_absolute_max (at, |
194 | at_shadow); | 196 | at_shadow); |
195 | } | ||
196 | expire = GNUNET_TIME_absolute_min(at, | ||
197 | expire); | ||
198 | } | 197 | } |
199 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 198 | expire = GNUNET_TIME_absolute_min (at, |
200 | "Determined expiration time for block with %u records to be %s\n", | 199 | expire); |
201 | rd_count, | 200 | } |
202 | GNUNET_STRINGS_absolute_time_to_string(expire)); | 201 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
202 | "Determined expiration time for block with %u records to be %s\n", | ||
203 | rd_count, | ||
204 | GNUNET_STRINGS_absolute_time_to_string (expire)); | ||
203 | return expire; | 205 | return expire; |
204 | } | 206 | } |
205 | 207 | ||
@@ -211,14 +213,15 @@ GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, | |||
211 | * #GNUNET_NO if not | 213 | * #GNUNET_NO if not |
212 | */ | 214 | */ |
213 | int | 215 | int |
214 | GNUNET_GNSRECORD_is_expired(const struct GNUNET_GNSRECORD_Data *rd) | 216 | GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd) |
215 | { | 217 | { |
216 | struct GNUNET_TIME_Absolute at; | 218 | struct GNUNET_TIME_Absolute at; |
217 | 219 | ||
218 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 220 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
219 | return GNUNET_NO; | 221 | return GNUNET_NO; |
220 | at.abs_value_us = rd->expiration_time; | 222 | at.abs_value_us = rd->expiration_time; |
221 | return (0 == GNUNET_TIME_absolute_get_remaining(at).rel_value_us) ? GNUNET_YES : GNUNET_NO; | 223 | return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ? |
224 | GNUNET_YES : GNUNET_NO; | ||
222 | } | 225 | } |
223 | 226 | ||
224 | 227 | ||
@@ -233,17 +236,17 @@ GNUNET_GNSRECORD_is_expired(const struct GNUNET_GNSRECORD_Data *rd) | |||
233 | * key in an encoding suitable for DNS labels. | 236 | * key in an encoding suitable for DNS labels. |
234 | */ | 237 | */ |
235 | const char * | 238 | const char * |
236 | GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 239 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
237 | { | 240 | { |
238 | static char ret[128]; | 241 | static char ret[128]; |
239 | char *pkeys; | 242 | char *pkeys; |
240 | 243 | ||
241 | pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string(pkey); | 244 | pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey); |
242 | GNUNET_snprintf(ret, | 245 | GNUNET_snprintf (ret, |
243 | sizeof(ret), | 246 | sizeof(ret), |
244 | "%s", | 247 | "%s", |
245 | pkeys); | 248 | pkeys); |
246 | GNUNET_free(pkeys); | 249 | GNUNET_free (pkeys); |
247 | return ret; | 250 | return ret; |
248 | } | 251 | } |
249 | 252 | ||
@@ -258,13 +261,13 @@ GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | |||
258 | * @return #GNUNET_SYSERR if @a zkey has the wrong syntax | 261 | * @return #GNUNET_SYSERR if @a zkey has the wrong syntax |
259 | */ | 262 | */ |
260 | int | 263 | int |
261 | GNUNET_GNSRECORD_zkey_to_pkey(const char *zkey, | 264 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
262 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 265 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
263 | { | 266 | { |
264 | if (GNUNET_OK != | 267 | if (GNUNET_OK != |
265 | GNUNET_CRYPTO_ecdsa_public_key_from_string(zkey, | 268 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zkey, |
266 | strlen(zkey), | 269 | strlen (zkey), |
267 | pkey)) | 270 | pkey)) |
268 | return GNUNET_SYSERR; | 271 | return GNUNET_SYSERR; |
269 | return GNUNET_OK; | 272 | return GNUNET_OK; |
270 | } | 273 | } |