diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:44:43 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:44:43 +0200 |
commit | b30d24b831b88c5695550b52b1051c4d6d943ce8 (patch) | |
tree | 50650283392e2398e137a260a6e10ed73dfb08d2 | |
parent | 8db3019c49933a8d5c7c82095974f6fe30bdad4b (diff) | |
download | gnunet-b30d24b831b88c5695550b52b1051c4d6d943ce8.tar.gz gnunet-b30d24b831b88c5695550b52b1051c4d6d943ce8.zip |
indent
-rw-r--r-- | src/abd/delegate_misc.c | 8 | ||||
-rw-r--r-- | src/abd/plugin_gnsrecord_abd.c | 298 |
2 files changed, 153 insertions, 153 deletions
diff --git a/src/abd/delegate_misc.c b/src/abd/delegate_misc.c index ecc7f7669..fb5834274 100644 --- a/src/abd/delegate_misc.c +++ b/src/abd/delegate_misc.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -88,13 +88,13 @@ GNUNET_ABD_delegate_from_string (const char *s) | |||
88 | char iss_attr[253 + 1]; | 88 | char iss_attr[253 + 1]; |
89 | // Needs to be initialized, in case of Type 1 credential (A.a <- B) | 89 | // Needs to be initialized, in case of Type 1 credential (A.a <- B) |
90 | char sub_attr[253 + 1] = ""; | 90 | char sub_attr[253 + 1] = ""; |
91 | char signature[256]; //TODO max payload size | 91 | char signature[256]; // TODO max payload size |
92 | 92 | ||
93 | struct GNUNET_CRYPTO_EcdsaSignature *sig; | 93 | struct GNUNET_CRYPTO_EcdsaSignature *sig; |
94 | struct GNUNET_TIME_Absolute etime_abs; | 94 | struct GNUNET_TIME_Absolute etime_abs; |
95 | 95 | ||
96 | // If it's A.a <- B.b... | 96 | // If it's A.a <- B.b... |
97 | if (6 != SSCANF (s, | 97 | if (6 != sscanf (s, |
98 | "%52s.%253s -> %52s.%253s | %s | %" SCNu64, | 98 | "%52s.%253s -> %52s.%253s | %s | %" SCNu64, |
99 | issuer_pkey, | 99 | issuer_pkey, |
100 | iss_attr, | 100 | iss_attr, |
@@ -104,7 +104,7 @@ GNUNET_ABD_delegate_from_string (const char *s) | |||
104 | &etime_abs.abs_value_us)) | 104 | &etime_abs.abs_value_us)) |
105 | { | 105 | { |
106 | // Try if it's A.a <- B | 106 | // Try if it's A.a <- B |
107 | if (5 != SSCANF (s, | 107 | if (5 != sscanf (s, |
108 | "%52s.%253s -> %52s | %s | %" SCNu64, | 108 | "%52s.%253s -> %52s | %s | %" SCNu64, |
109 | issuer_pkey, | 109 | issuer_pkey, |
110 | iss_attr, | 110 | iss_attr, |
diff --git a/src/abd/plugin_gnsrecord_abd.c b/src/abd/plugin_gnsrecord_abd.c index 811878627..9d8f4a79b 100644 --- a/src/abd/plugin_gnsrecord_abd.c +++ b/src/abd/plugin_gnsrecord_abd.c | |||
@@ -44,88 +44,88 @@ | |||
44 | */ | 44 | */ |
45 | static char * | 45 | static char * |
46 | abd_value_to_string (void *cls, | 46 | abd_value_to_string (void *cls, |
47 | uint32_t type, | 47 | uint32_t type, |
48 | const void *data, | 48 | const void *data, |
49 | size_t data_size) | 49 | size_t data_size) |
50 | { | 50 | { |
51 | const char *cdata; | 51 | const char *cdata; |
52 | 52 | ||
53 | switch (type) | 53 | switch (type) |
54 | { | 54 | { |
55 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | 55 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: |
56 | { | ||
57 | struct GNUNET_ABD_DelegationRecord sets; | ||
58 | char *attr_str; | ||
59 | char *subject_pkey; | ||
60 | char *tmp_str; | ||
61 | int i; | ||
62 | if (data_size < sizeof (struct GNUNET_ABD_DelegationRecord)) | ||
63 | return NULL; /* malformed */ | ||
64 | |||
65 | GNUNET_memcpy (&sets, data, sizeof (sets)); | ||
66 | cdata = data; | ||
67 | |||
68 | struct GNUNET_ABD_DelegationSet set[ntohl (sets.set_count)]; | ||
69 | if (GNUNET_OK != | ||
70 | GNUNET_ABD_delegation_set_deserialize (GNUNET_ntohll ( | ||
71 | sets.data_size), | ||
72 | &cdata[sizeof (sets)], | ||
73 | ntohl (sets.set_count), | ||
74 | set)) | ||
75 | return NULL; | ||
76 | |||
77 | for (i = 0; i < ntohl (sets.set_count); i++) | ||
78 | { | 56 | { |
79 | subject_pkey = | 57 | struct GNUNET_ABD_DelegationRecord sets; |
80 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); | 58 | char *attr_str; |
81 | 59 | char *subject_pkey; | |
82 | if (0 == set[i].subject_attribute_len) | 60 | char *tmp_str; |
83 | { | 61 | int i; |
84 | if (0 == i) | 62 | if (data_size < sizeof (struct GNUNET_ABD_DelegationRecord)) |
85 | { | 63 | return NULL; /* malformed */ |
86 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); | 64 | |
87 | } | 65 | GNUNET_memcpy (&sets, data, sizeof (sets)); |
88 | else | 66 | cdata = data; |
89 | { | 67 | |
90 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); | 68 | struct GNUNET_ABD_DelegationSet set[ntohl (sets.set_count)]; |
91 | GNUNET_free (attr_str); | 69 | if (GNUNET_OK != |
92 | attr_str = tmp_str; | 70 | GNUNET_ABD_delegation_set_deserialize (GNUNET_ntohll ( |
93 | } | 71 | sets.data_size), |
94 | } | 72 | &cdata[sizeof (sets)], |
95 | else | 73 | ntohl (sets.set_count), |
74 | set)) | ||
75 | return NULL; | ||
76 | |||
77 | for (i = 0; i < ntohl (sets.set_count); i++) | ||
96 | { | 78 | { |
97 | if (0 == i) | 79 | subject_pkey = |
80 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); | ||
81 | |||
82 | if (0 == set[i].subject_attribute_len) | ||
98 | { | 83 | { |
99 | GNUNET_asprintf (&attr_str, | 84 | if (0 == i) |
100 | "%s %s", | 85 | { |
101 | subject_pkey, | 86 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); |
102 | set[i].subject_attribute); | 87 | } |
88 | else | ||
89 | { | ||
90 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); | ||
91 | GNUNET_free (attr_str); | ||
92 | attr_str = tmp_str; | ||
93 | } | ||
103 | } | 94 | } |
104 | else | 95 | else |
105 | { | 96 | { |
106 | GNUNET_asprintf (&tmp_str, | 97 | if (0 == i) |
107 | "%s,%s %s", | 98 | { |
108 | attr_str, | 99 | GNUNET_asprintf (&attr_str, |
109 | subject_pkey, | 100 | "%s %s", |
110 | set[i].subject_attribute); | 101 | subject_pkey, |
111 | GNUNET_free (attr_str); | 102 | set[i].subject_attribute); |
112 | attr_str = tmp_str; | 103 | } |
104 | else | ||
105 | { | ||
106 | GNUNET_asprintf (&tmp_str, | ||
107 | "%s,%s %s", | ||
108 | attr_str, | ||
109 | subject_pkey, | ||
110 | set[i].subject_attribute); | ||
111 | GNUNET_free (attr_str); | ||
112 | attr_str = tmp_str; | ||
113 | } | ||
113 | } | 114 | } |
115 | GNUNET_free (subject_pkey); | ||
114 | } | 116 | } |
115 | GNUNET_free (subject_pkey); | 117 | return attr_str; |
116 | } | 118 | } |
117 | return attr_str; | ||
118 | } | ||
119 | case GNUNET_GNSRECORD_TYPE_DELEGATE: | 119 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
120 | { | 120 | { |
121 | struct GNUNET_ABD_Delegate *cred; | 121 | struct GNUNET_ABD_Delegate *cred; |
122 | char *cred_str; | 122 | char *cred_str; |
123 | 123 | ||
124 | cred = GNUNET_ABD_delegate_deserialize (data, data_size); | 124 | cred = GNUNET_ABD_delegate_deserialize (data, data_size); |
125 | cred_str = GNUNET_ABD_delegate_to_string (cred); | 125 | cred_str = GNUNET_ABD_delegate_to_string (cred); |
126 | GNUNET_free (cred); | 126 | GNUNET_free (cred); |
127 | return cred_str; | 127 | return cred_str; |
128 | } | 128 | } |
129 | default: | 129 | default: |
130 | return NULL; | 130 | return NULL; |
131 | } | 131 | } |
@@ -145,114 +145,114 @@ abd_value_to_string (void *cls, | |||
145 | */ | 145 | */ |
146 | static int | 146 | static int |
147 | abd_string_to_value (void *cls, | 147 | abd_string_to_value (void *cls, |
148 | uint32_t type, | 148 | uint32_t type, |
149 | const char *s, | 149 | const char *s, |
150 | void **data, | 150 | void **data, |
151 | size_t *data_size) | 151 | size_t *data_size) |
152 | { | 152 | { |
153 | if (NULL == s) | 153 | if (NULL == s) |
154 | return GNUNET_SYSERR; | 154 | return GNUNET_SYSERR; |
155 | switch (type) | 155 | switch (type) |
156 | { | 156 | { |
157 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | 157 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: |
158 | { | ||
159 | struct GNUNET_ABD_DelegationRecord *sets; | ||
160 | char attr_str[253 + 1]; | ||
161 | char subject_pkey[52 + 1]; | ||
162 | char *token; | ||
163 | char *tmp_str; | ||
164 | int matches = 0; | ||
165 | int entries; | ||
166 | size_t tmp_data_size; | ||
167 | int i; | ||
168 | |||
169 | tmp_str = GNUNET_strdup (s); | ||
170 | token = strtok (tmp_str, ","); | ||
171 | entries = 0; | ||
172 | tmp_data_size = 0; | ||
173 | *data_size = sizeof (struct GNUNET_ABD_DelegationRecord); | ||
174 | while (NULL != token) | ||
175 | { | 158 | { |
176 | // also fills the variables subject_pley and attr_str if "regex"-like match | 159 | struct GNUNET_ABD_DelegationRecord *sets; |
177 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | 160 | char attr_str[253 + 1]; |
161 | char subject_pkey[52 + 1]; | ||
162 | char *token; | ||
163 | char *tmp_str; | ||
164 | int matches = 0; | ||
165 | int entries; | ||
166 | size_t tmp_data_size; | ||
167 | int i; | ||
168 | |||
169 | tmp_str = GNUNET_strdup (s); | ||
170 | token = strtok (tmp_str, ","); | ||
171 | entries = 0; | ||
172 | tmp_data_size = 0; | ||
173 | *data_size = sizeof (struct GNUNET_ABD_DelegationRecord); | ||
174 | while (NULL != token) | ||
175 | { | ||
176 | // also fills the variables subject_pley and attr_str if "regex"-like match | ||
177 | matches = sscanf (token, "%s %s", subject_pkey, attr_str); | ||
178 | |||
179 | if (0 == matches) | ||
180 | { | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
182 | _ ("Unable to parse ATTR record string `%s'\n"), | ||
183 | s); | ||
184 | GNUNET_free (tmp_str); | ||
185 | return GNUNET_SYSERR; | ||
186 | } | ||
187 | |||
188 | entries++; | ||
189 | token = strtok (NULL, ","); | ||
190 | } | ||
191 | GNUNET_free (tmp_str); | ||
178 | 192 | ||
179 | if (0 == matches) | 193 | tmp_str = GNUNET_strdup (s); |
194 | token = strtok (tmp_str, ","); | ||
195 | if (NULL == token) | ||
180 | { | 196 | { |
181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
182 | _ ("Unable to parse ATTR record string `%s'\n"), | ||
183 | s); | ||
184 | GNUNET_free (tmp_str); | 197 | GNUNET_free (tmp_str); |
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); | ||
185 | return GNUNET_SYSERR; | 199 | return GNUNET_SYSERR; |
186 | } | 200 | } |
187 | 201 | ||
188 | entries++; | 202 | struct GNUNET_ABD_DelegationSet set[entries]; |
189 | token = strtok (NULL, ","); | 203 | // sets memory to be 0, starting at *set for the size of struct * entries |
190 | } | 204 | memset (set, 0, sizeof (struct GNUNET_ABD_DelegationSet) * entries); |
191 | GNUNET_free (tmp_str); | 205 | for (i = 0; i < entries; i++) |
192 | 206 | { | |
193 | tmp_str = GNUNET_strdup (s); | 207 | matches = sscanf (token, "%s %s", subject_pkey, attr_str); |
194 | token = strtok (tmp_str, ","); | ||
195 | if (NULL == token) | ||
196 | { | ||
197 | GNUNET_free (tmp_str); | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); | ||
199 | return GNUNET_SYSERR; | ||
200 | } | ||
201 | 208 | ||
202 | struct GNUNET_ABD_DelegationSet set[entries]; | 209 | // sets the public key for the set entry |
203 | // sets memory to be 0, starting at *set for the size of struct * entries | 210 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
204 | memset (set, 0, sizeof (struct GNUNET_ABD_DelegationSet) * entries); | 211 | strlen (subject_pkey), |
205 | for (i = 0; i < entries; i++) | 212 | &set[i].subject_key); |
206 | { | ||
207 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | ||
208 | 213 | ||
209 | // sets the public key for the set entry | 214 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) |
210 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, | 215 | if (2 == matches) |
211 | strlen (subject_pkey), | 216 | { |
212 | &set[i].subject_key); | 217 | set[i].subject_attribute_len = strlen (attr_str) + 1; |
218 | set[i].subject_attribute = GNUNET_strdup (attr_str); | ||
219 | } | ||
220 | // If more entries, then token string can take the next entry (separated by ',') by calling strtok again | ||
221 | token = strtok (NULL, ","); | ||
222 | } | ||
223 | tmp_data_size = GNUNET_ABD_delegation_set_get_size (entries, set); | ||
213 | 224 | ||
214 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) | 225 | if (-1 == tmp_data_size) |
215 | if (2 == matches) | ||
216 | { | 226 | { |
217 | set[i].subject_attribute_len = strlen (attr_str) + 1; | 227 | GNUNET_free (tmp_str); |
218 | set[i].subject_attribute = GNUNET_strdup (attr_str); | 228 | return GNUNET_SYSERR; |
219 | } | 229 | } |
220 | // If more entries, then token string can take the next entry (separated by ',') by calling strtok again | 230 | *data_size += tmp_data_size; |
221 | token = strtok (NULL, ","); | 231 | *data = sets = GNUNET_malloc (*data_size); |
222 | } | 232 | GNUNET_ABD_delegation_set_serialize (entries, |
223 | tmp_data_size = GNUNET_ABD_delegation_set_get_size (entries, set); | 233 | set, |
234 | tmp_data_size, | ||
235 | (char *) &sets[1]); | ||
236 | for (i = 0; i < entries; i++) | ||
237 | { | ||
238 | if (0 != set[i].subject_attribute_len) | ||
239 | GNUNET_free ((char *) set[i].subject_attribute); | ||
240 | } | ||
241 | sets->set_count = htonl (entries); | ||
242 | sets->data_size = GNUNET_htonll (tmp_data_size); | ||
224 | 243 | ||
225 | if (-1 == tmp_data_size) | ||
226 | { | ||
227 | GNUNET_free (tmp_str); | 244 | GNUNET_free (tmp_str); |
228 | return GNUNET_SYSERR; | 245 | return GNUNET_OK; |
229 | } | 246 | } |
230 | *data_size += tmp_data_size; | ||
231 | *data = sets = GNUNET_malloc (*data_size); | ||
232 | GNUNET_ABD_delegation_set_serialize (entries, | ||
233 | set, | ||
234 | tmp_data_size, | ||
235 | (char *) &sets[1]); | ||
236 | for (i = 0; i < entries; i++) | ||
237 | { | ||
238 | if (0 != set[i].subject_attribute_len) | ||
239 | GNUNET_free ((char *) set[i].subject_attribute); | ||
240 | } | ||
241 | sets->set_count = htonl (entries); | ||
242 | sets->data_size = GNUNET_htonll (tmp_data_size); | ||
243 | |||
244 | GNUNET_free (tmp_str); | ||
245 | return GNUNET_OK; | ||
246 | } | ||
247 | case GNUNET_GNSRECORD_TYPE_DELEGATE: | 247 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
248 | { | 248 | { |
249 | struct GNUNET_ABD_Delegate *cred; | 249 | struct GNUNET_ABD_Delegate *cred; |
250 | cred = GNUNET_ABD_delegate_from_string (s); | 250 | cred = GNUNET_ABD_delegate_from_string (s); |
251 | 251 | ||
252 | *data_size = GNUNET_ABD_delegate_serialize (cred, (char **) data); | 252 | *data_size = GNUNET_ABD_delegate_serialize (cred, (char **) data); |
253 | 253 | ||
254 | return GNUNET_OK; | 254 | return GNUNET_OK; |
255 | } | 255 | } |
256 | default: | 256 | default: |
257 | return GNUNET_SYSERR; | 257 | return GNUNET_SYSERR; |
258 | } | 258 | } |