diff options
author | Andreas Ebner <pansy007@googlemail.com> | 2019-07-24 16:29:32 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:15:32 +0200 |
commit | 40624873cbd2eaf3a94185995b14899ea6ab36bf (patch) | |
tree | 0bcc45fc8ba74c7b218ed2b32fc8b7482a42a37c /src/credential/plugin_gnsrecord_credential.c | |
parent | 5091edcec16455febee99afec20e0ffe6cc59c21 (diff) | |
download | gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.tar.gz gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.zip |
Run clang format over some files, experimental implementation of forward algorithm
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r-- | src/credential/plugin_gnsrecord_credential.c | 129 |
1 files changed, 86 insertions, 43 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c index f2fb0b1a6..90cd2f46a 100644 --- a/src/credential/plugin_gnsrecord_credential.c +++ b/src/credential/plugin_gnsrecord_credential.c | |||
@@ -44,13 +44,17 @@ | |||
44 | * @return NULL on error, otherwise human-readable representation of the value | 44 | * @return NULL on error, otherwise human-readable representation of the value |
45 | */ | 45 | */ |
46 | static char * | 46 | static char * |
47 | credential_value_to_string (void *cls, uint32_t type, const void *data, | 47 | credential_value_to_string (void *cls, |
48 | uint32_t type, | ||
49 | const void *data, | ||
48 | size_t data_size) | 50 | size_t data_size) |
49 | { | 51 | { |
50 | const char *cdata; | 52 | const char *cdata; |
51 | 53 | ||
52 | switch (type) { | 54 | switch (type) |
53 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { | 55 | { |
56 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | ||
57 | { | ||
54 | struct GNUNET_CREDENTIAL_DelegationRecord sets; | 58 | struct GNUNET_CREDENTIAL_DelegationRecord sets; |
55 | char *attr_str; | 59 | char *attr_str; |
56 | char *subject_pkey; | 60 | char *subject_pkey; |
@@ -63,30 +67,49 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
63 | cdata = data; | 67 | cdata = data; |
64 | 68 | ||
65 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; | 69 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; |
66 | if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( | 70 | if (GNUNET_OK != |
67 | GNUNET_ntohll (sets.data_size), &cdata[sizeof (sets)], | 71 | GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll ( |
68 | ntohl (sets.set_count), set)) | 72 | sets.data_size), |
73 | &cdata[sizeof (sets)], | ||
74 | ntohl (sets.set_count), | ||
75 | set)) | ||
69 | return NULL; | 76 | return NULL; |
70 | 77 | ||
71 | for (i = 0; i < ntohl (sets.set_count); i++) { | 78 | for (i = 0; i < ntohl (sets.set_count); i++) |
79 | { | ||
72 | subject_pkey = | 80 | subject_pkey = |
73 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); | 81 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n", | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
83 | "%d len attr\n", | ||
75 | set[i].subject_attribute_len); | 84 | set[i].subject_attribute_len); |
76 | if (0 == set[i].subject_attribute_len) { | 85 | if (0 == set[i].subject_attribute_len) |
77 | if (0 == i) { | 86 | { |
87 | if (0 == i) | ||
88 | { | ||
78 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); | 89 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); |
79 | } else { | 90 | } |
91 | else | ||
92 | { | ||
80 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); | 93 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); |
81 | GNUNET_free (attr_str); | 94 | GNUNET_free (attr_str); |
82 | attr_str = tmp_str; | 95 | attr_str = tmp_str; |
83 | } | 96 | } |
84 | } else { | 97 | } |
85 | if (0 == i) { | 98 | else |
86 | GNUNET_asprintf (&attr_str, "%s %s", subject_pkey, | 99 | { |
100 | if (0 == i) | ||
101 | { | ||
102 | GNUNET_asprintf (&attr_str, | ||
103 | "%s %s", | ||
104 | subject_pkey, | ||
87 | set[i].subject_attribute); | 105 | set[i].subject_attribute); |
88 | } else { | 106 | } |
89 | GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey, | 107 | else |
108 | { | ||
109 | GNUNET_asprintf (&tmp_str, | ||
110 | "%s,%s %s", | ||
111 | attr_str, | ||
112 | subject_pkey, | ||
90 | set[i].subject_attribute); | 113 | set[i].subject_attribute); |
91 | GNUNET_free (attr_str); | 114 | GNUNET_free (attr_str); |
92 | attr_str = tmp_str; | 115 | attr_str = tmp_str; |
@@ -96,7 +119,8 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
96 | } | 119 | } |
97 | return attr_str; | 120 | return attr_str; |
98 | } | 121 | } |
99 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { | 122 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: |
123 | { | ||
100 | struct GNUNET_CREDENTIAL_Credential *cred; | 124 | struct GNUNET_CREDENTIAL_Credential *cred; |
101 | char *cred_str; | 125 | char *cred_str; |
102 | 126 | ||
@@ -105,10 +129,11 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
105 | GNUNET_free (cred); | 129 | GNUNET_free (cred); |
106 | return cred_str; | 130 | return cred_str; |
107 | } | 131 | } |
108 | case GNUNET_GNSRECORD_TYPE_DELEGATE: { | 132 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
133 | { | ||
109 | struct GNUNET_CREDENTIAL_Delegate *cred; | 134 | struct GNUNET_CREDENTIAL_Delegate *cred; |
110 | char *cred_str; | 135 | char *cred_str; |
111 | 136 | ||
112 | cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size); | 137 | cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size); |
113 | cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred); | 138 | cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred); |
114 | GNUNET_free (cred); | 139 | GNUNET_free (cred); |
@@ -132,13 +157,18 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
132 | * @return #GNUNET_OK on success | 157 | * @return #GNUNET_OK on success |
133 | */ | 158 | */ |
134 | static int | 159 | static int |
135 | credential_string_to_value (void *cls, uint32_t type, const char *s, | 160 | credential_string_to_value (void *cls, |
136 | void **data, size_t *data_size) | 161 | uint32_t type, |
162 | const char *s, | ||
163 | void **data, | ||
164 | size_t *data_size) | ||
137 | { | 165 | { |
138 | if (NULL == s) | 166 | if (NULL == s) |
139 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
140 | switch (type) { | 168 | switch (type) |
141 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { | 169 | { |
170 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | ||
171 | { | ||
142 | struct GNUNET_CREDENTIAL_DelegationRecord *sets; | 172 | struct GNUNET_CREDENTIAL_DelegationRecord *sets; |
143 | char attr_str[253 + 1]; | 173 | char attr_str[253 + 1]; |
144 | char subject_pkey[52 + 1]; | 174 | char subject_pkey[52 + 1]; |
@@ -154,17 +184,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
154 | entries = 0; | 184 | entries = 0; |
155 | tmp_data_size = 0; | 185 | tmp_data_size = 0; |
156 | *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); | 186 | *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); |
157 | while (NULL != token) { | 187 | while (NULL != token) |
188 | { | ||
158 | // also fills the variables subject_pley and attr_str if "regex"-like match | 189 | // also fills the variables subject_pley and attr_str if "regex"-like match |
159 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | 190 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); |
160 | 191 | ||
161 | if (0 == matches) { | 192 | if (0 == matches) |
193 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
163 | _ ("Unable to parse ATTR record string `%s'\n"), s); | 195 | _ ("Unable to parse ATTR record string `%s'\n"), |
196 | s); | ||
164 | GNUNET_free (tmp_str); | 197 | GNUNET_free (tmp_str); |
165 | return GNUNET_SYSERR; | 198 | return GNUNET_SYSERR; |
166 | } | 199 | } |
167 | 200 | ||
168 | entries++; | 201 | entries++; |
169 | token = strtok (NULL, ","); | 202 | token = strtok (NULL, ","); |
170 | } | 203 | } |
@@ -172,7 +205,8 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
172 | 205 | ||
173 | tmp_str = GNUNET_strdup (s); | 206 | tmp_str = GNUNET_strdup (s); |
174 | token = strtok (tmp_str, ","); | 207 | token = strtok (tmp_str, ","); |
175 | if (NULL == token) { | 208 | if (NULL == token) |
209 | { | ||
176 | GNUNET_free (tmp_str); | 210 | GNUNET_free (tmp_str); |
177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); | 211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); |
178 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
@@ -181,15 +215,18 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
181 | struct GNUNET_CREDENTIAL_DelegationSet set[entries]; | 215 | struct GNUNET_CREDENTIAL_DelegationSet set[entries]; |
182 | // sets memory to be 0, starting at *set for the size of struct * entries | 216 | // sets memory to be 0, starting at *set for the size of struct * entries |
183 | memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); | 217 | memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); |
184 | for (i = 0; i < entries; i++) { | 218 | for (i = 0; i < entries; i++) |
219 | { | ||
185 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | 220 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); |
186 | 221 | ||
187 | // sets the public key for the set entry | 222 | // sets the public key for the set entry |
188 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( | 223 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
189 | subject_pkey, strlen (subject_pkey), &set[i].subject_key); | 224 | strlen (subject_pkey), |
225 | &set[i].subject_key); | ||
190 | 226 | ||
191 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) | 227 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) |
192 | if (2 == matches) { | 228 | if (2 == matches) |
229 | { | ||
193 | set[i].subject_attribute_len = strlen (attr_str) + 1; | 230 | set[i].subject_attribute_len = strlen (attr_str) + 1; |
194 | set[i].subject_attribute = GNUNET_strdup (attr_str); | 231 | set[i].subject_attribute = GNUNET_strdup (attr_str); |
195 | } | 232 | } |
@@ -198,17 +235,21 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
198 | } | 235 | } |
199 | tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set); | 236 | tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set); |
200 | 237 | ||
201 | if (-1 == tmp_data_size) { | 238 | if (-1 == tmp_data_size) |
239 | { | ||
202 | GNUNET_free (tmp_str); | 240 | GNUNET_free (tmp_str); |
203 | return GNUNET_SYSERR; | 241 | return GNUNET_SYSERR; |
204 | } | 242 | } |
205 | *data_size += tmp_data_size; | 243 | *data_size += tmp_data_size; |
206 | *data = sets = GNUNET_malloc (*data_size); | 244 | *data = sets = GNUNET_malloc (*data_size); |
207 | GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size, | 245 | GNUNET_CREDENTIAL_delegation_set_serialize (entries, |
208 | (char *)&sets[1]); | 246 | set, |
209 | for (i = 0; i < entries; i++) { | 247 | tmp_data_size, |
248 | (char *) &sets[1]); | ||
249 | for (i = 0; i < entries; i++) | ||
250 | { | ||
210 | if (0 != set[i].subject_attribute_len) | 251 | if (0 != set[i].subject_attribute_len) |
211 | GNUNET_free ((char *)set[i].subject_attribute); | 252 | GNUNET_free ((char *) set[i].subject_attribute); |
212 | } | 253 | } |
213 | sets->set_count = htonl (entries); | 254 | sets->set_count = htonl (entries); |
214 | sets->data_size = GNUNET_htonll (tmp_data_size); | 255 | sets->data_size = GNUNET_htonll (tmp_data_size); |
@@ -216,18 +257,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
216 | GNUNET_free (tmp_str); | 257 | GNUNET_free (tmp_str); |
217 | return GNUNET_OK; | 258 | return GNUNET_OK; |
218 | } | 259 | } |
219 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { | 260 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: |
261 | { | ||
220 | struct GNUNET_CREDENTIAL_Credential *cred; | 262 | struct GNUNET_CREDENTIAL_Credential *cred; |
221 | cred = GNUNET_CREDENTIAL_credential_from_string (s); | 263 | cred = GNUNET_CREDENTIAL_credential_from_string (s); |
222 | 264 | ||
223 | *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **)data); | 265 | *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **) data); |
224 | return GNUNET_OK; | 266 | return GNUNET_OK; |
225 | } | 267 | } |
226 | case GNUNET_GNSRECORD_TYPE_DELEGATE: { | 268 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
269 | { | ||
227 | struct GNUNET_CREDENTIAL_Delegate *cred; | 270 | struct GNUNET_CREDENTIAL_Delegate *cred; |
228 | cred = GNUNET_CREDENTIAL_delegate_from_string (s); | 271 | cred = GNUNET_CREDENTIAL_delegate_from_string (s); |
229 | 272 | ||
230 | *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)data); | 273 | *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **) data); |
231 | 274 | ||
232 | return GNUNET_OK; | 275 | return GNUNET_OK; |
233 | } | 276 | } |