diff options
Diffstat (limited to 'src/namecache/gnunet-namecache.c')
-rw-r--r-- | src/namecache/gnunet-namecache.c | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c index 509f86fc0..2d387b543 100644 --- a/src/namecache/gnunet-namecache.c +++ b/src/namecache/gnunet-namecache.c | |||
@@ -16,7 +16,7 @@ | |||
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-namecache.c | 21 | * @file gnunet-namecache.c |
22 | * @brief command line tool to inspect the name cache | 22 | * @brief command line tool to inspect the name cache |
@@ -70,18 +70,18 @@ static int ret; | |||
70 | * @param cls unused | 70 | * @param cls unused |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | do_shutdown (void *cls) | 73 | do_shutdown(void *cls) |
74 | { | 74 | { |
75 | if (NULL != qe) | 75 | if (NULL != qe) |
76 | { | 76 | { |
77 | GNUNET_NAMECACHE_cancel (qe); | 77 | GNUNET_NAMECACHE_cancel(qe); |
78 | qe = NULL; | 78 | qe = NULL; |
79 | } | 79 | } |
80 | if (NULL != ns) | 80 | if (NULL != ns) |
81 | { | 81 | { |
82 | GNUNET_NAMECACHE_disconnect (ns); | 82 | GNUNET_NAMECACHE_disconnect(ns); |
83 | ns = NULL; | 83 | ns = NULL; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
@@ -93,37 +93,37 @@ do_shutdown (void *cls) | |||
93 | * @param rd array of records with data to store | 93 | * @param rd array of records with data to store |
94 | */ | 94 | */ |
95 | static void | 95 | static void |
96 | display_records_from_block (void *cls, | 96 | display_records_from_block(void *cls, |
97 | unsigned int rd_len, | 97 | unsigned int rd_len, |
98 | const struct GNUNET_GNSRECORD_Data *rd) | 98 | const struct GNUNET_GNSRECORD_Data *rd) |
99 | { | 99 | { |
100 | const char *typestring; | 100 | const char *typestring; |
101 | char *s; | 101 | char *s; |
102 | unsigned int i; | 102 | unsigned int i; |
103 | 103 | ||
104 | if (0 == rd_len) | 104 | if (0 == rd_len) |
105 | { | 105 | { |
106 | fprintf (stdout, _ ("No records found for `%s'"), name); | 106 | fprintf(stdout, _("No records found for `%s'"), name); |
107 | return; | 107 | return; |
108 | } | 108 | } |
109 | fprintf (stdout, "%s:\n", name); | 109 | fprintf(stdout, "%s:\n", name); |
110 | for (i = 0; i < rd_len; i++) | 110 | for (i = 0; i < rd_len; i++) |
111 | { | ||
112 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
113 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
114 | rd[i].data, | ||
115 | rd[i].data_size); | ||
116 | if (NULL == s) | ||
117 | { | 111 | { |
118 | fprintf (stdout, | 112 | typestring = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type); |
119 | _ ("\tCorrupt or unsupported record of type %u\n"), | 113 | s = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, |
120 | (unsigned int) rd[i].record_type); | 114 | rd[i].data, |
121 | continue; | 115 | rd[i].data_size); |
116 | if (NULL == s) | ||
117 | { | ||
118 | fprintf(stdout, | ||
119 | _("\tCorrupt or unsupported record of type %u\n"), | ||
120 | (unsigned int)rd[i].record_type); | ||
121 | continue; | ||
122 | } | ||
123 | fprintf(stdout, "\t%s: %s\n", typestring, s); | ||
124 | GNUNET_free(s); | ||
122 | } | 125 | } |
123 | fprintf (stdout, "\t%s: %s\n", typestring, s); | 126 | fprintf(stdout, "%s", "\n"); |
124 | GNUNET_free (s); | ||
125 | } | ||
126 | fprintf (stdout, "%s", "\n"); | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
@@ -134,23 +134,23 @@ display_records_from_block (void *cls, | |||
134 | * @param block NULL if not found | 134 | * @param block NULL if not found |
135 | */ | 135 | */ |
136 | static void | 136 | static void |
137 | handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block) | 137 | handle_block(void *cls, const struct GNUNET_GNSRECORD_Block *block) |
138 | { | 138 | { |
139 | qe = NULL; | 139 | qe = NULL; |
140 | if (NULL == block) | 140 | if (NULL == block) |
141 | { | 141 | { |
142 | fprintf (stderr, "No matching block found\n"); | 142 | fprintf(stderr, "No matching block found\n"); |
143 | } | 143 | } |
144 | else if (GNUNET_OK != | 144 | else if (GNUNET_OK != |
145 | GNUNET_GNSRECORD_block_decrypt (block, | 145 | GNUNET_GNSRECORD_block_decrypt(block, |
146 | &pubkey, | 146 | &pubkey, |
147 | name, | 147 | name, |
148 | &display_records_from_block, | 148 | &display_records_from_block, |
149 | NULL)) | 149 | NULL)) |
150 | { | 150 | { |
151 | fprintf (stderr, "Failed to decrypt block!\n"); | 151 | fprintf(stderr, "Failed to decrypt block!\n"); |
152 | } | 152 | } |
153 | GNUNET_SCHEDULER_shutdown (); | 153 | GNUNET_SCHEDULER_shutdown(); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
@@ -163,36 +163,36 @@ handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block) | |||
163 | * @param cfg configuration | 163 | * @param cfg configuration |
164 | */ | 164 | */ |
165 | static void | 165 | static void |
166 | run (void *cls, | 166 | run(void *cls, |
167 | char *const *args, | 167 | char *const *args, |
168 | const char *cfgfile, | 168 | const char *cfgfile, |
169 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 169 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
170 | { | 170 | { |
171 | struct GNUNET_HashCode dhash; | 171 | struct GNUNET_HashCode dhash; |
172 | 172 | ||
173 | if (NULL == pkey) | 173 | if (NULL == pkey) |
174 | { | 174 | { |
175 | fprintf (stderr, _ ("You must specify which zone should be accessed\n")); | 175 | fprintf(stderr, _("You must specify which zone should be accessed\n")); |
176 | return; | 176 | return; |
177 | } | 177 | } |
178 | 178 | ||
179 | if (GNUNET_OK != | 179 | if (GNUNET_OK != |
180 | GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey)) | 180 | GNUNET_CRYPTO_ecdsa_public_key_from_string(pkey, strlen(pkey), &pubkey)) |
181 | { | 181 | { |
182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); | 182 | fprintf(stderr, _("Invalid public key for zone `%s'\n"), pkey); |
183 | GNUNET_SCHEDULER_shutdown (); | 183 | GNUNET_SCHEDULER_shutdown(); |
184 | return; | 184 | return; |
185 | } | 185 | } |
186 | if (NULL == name) | 186 | if (NULL == name) |
187 | { | 187 | { |
188 | fprintf (stderr, _ ("You must specify a name\n")); | 188 | fprintf(stderr, _("You must specify a name\n")); |
189 | return; | 189 | return; |
190 | } | 190 | } |
191 | 191 | ||
192 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 192 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
193 | ns = GNUNET_NAMECACHE_connect (cfg); | 193 | ns = GNUNET_NAMECACHE_connect(cfg); |
194 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &dhash); | 194 | GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &dhash); |
195 | qe = GNUNET_NAMECACHE_lookup_block (ns, &dhash, &handle_block, NULL); | 195 | qe = GNUNET_NAMECACHE_lookup_block(ns, &dhash, &handle_block, NULL); |
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
@@ -204,41 +204,41 @@ run (void *cls, | |||
204 | * @return 0 ok, 1 on error | 204 | * @return 0 ok, 1 on error |
205 | */ | 205 | */ |
206 | int | 206 | int |
207 | main (int argc, char *const *argv) | 207 | main(int argc, char *const *argv) |
208 | { | 208 | { |
209 | struct GNUNET_GETOPT_CommandLineOption options[] = | 209 | struct GNUNET_GETOPT_CommandLineOption options[] = |
210 | {GNUNET_GETOPT_option_string ('n', | 210 | { GNUNET_GETOPT_option_string('n', |
211 | "name", | 211 | "name", |
212 | "NAME", | 212 | "NAME", |
213 | gettext_noop ( | 213 | gettext_noop( |
214 | "name of the record to add/delete/display"), | 214 | "name of the record to add/delete/display"), |
215 | &name), | 215 | &name), |
216 | 216 | ||
217 | GNUNET_GETOPT_option_string ( | 217 | GNUNET_GETOPT_option_string( |
218 | 'z', | 218 | 'z', |
219 | "zone", | 219 | "zone", |
220 | "PKEY", | 220 | "PKEY", |
221 | gettext_noop ("specifies the public key of the zone to look in"), | 221 | gettext_noop("specifies the public key of the zone to look in"), |
222 | &pkey), | 222 | &pkey), |
223 | 223 | ||
224 | GNUNET_GETOPT_OPTION_END}; | 224 | GNUNET_GETOPT_OPTION_END }; |
225 | 225 | ||
226 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 226 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
227 | return 2; | 227 | return 2; |
228 | 228 | ||
229 | GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL); | 229 | GNUNET_log_setup("gnunet-namecache", "WARNING", NULL); |
230 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 230 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, |
231 | argv, | 231 | argv, |
232 | "gnunet-namecache", | 232 | "gnunet-namecache", |
233 | _ ("GNUnet zone manipulation tool"), | 233 | _("GNUnet zone manipulation tool"), |
234 | options, | 234 | options, |
235 | &run, | 235 | &run, |
236 | NULL)) | 236 | NULL)) |
237 | { | 237 | { |
238 | GNUNET_free ((void *) argv); | 238 | GNUNET_free((void *)argv); |
239 | return 1; | 239 | return 1; |
240 | } | 240 | } |
241 | GNUNET_free ((void *) argv); | 241 | GNUNET_free((void *)argv); |
242 | return ret; | 242 | return ret; |
243 | } | 243 | } |
244 | 244 | ||