diff options
Diffstat (limited to 'src/namecache/gnunet-namecache.c')
-rw-r--r-- | src/namecache/gnunet-namecache.c | 126 |
1 files changed, 55 insertions, 71 deletions
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c index d1927934d..509f86fc0 100644 --- a/src/namecache/gnunet-namecache.c +++ b/src/namecache/gnunet-namecache.c | |||
@@ -94,8 +94,8 @@ do_shutdown (void *cls) | |||
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; |
@@ -103,33 +103,27 @@ display_records_from_block (void *cls, | |||
103 | 103 | ||
104 | if (0 == rd_len) | 104 | if (0 == rd_len) |
105 | { | 105 | { |
106 | FPRINTF (stdout, | 106 | fprintf (stdout, _ ("No records found for `%s'"), name); |
107 | _("No records found for `%s'"), | ||
108 | name); | ||
109 | return; | 107 | return; |
110 | } | 108 | } |
111 | FPRINTF (stdout, | 109 | fprintf (stdout, "%s:\n", name); |
112 | "%s:\n", | 110 | for (i = 0; i < rd_len; i++) |
113 | name); | ||
114 | for (i=0;i<rd_len;i++) | ||
115 | { | 111 | { |
116 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | 112 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
117 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | 113 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
118 | rd[i].data, | 114 | rd[i].data, |
119 | rd[i].data_size); | 115 | rd[i].data_size); |
120 | if (NULL == s) | 116 | if (NULL == s) |
121 | { | 117 | { |
122 | FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), | 118 | fprintf (stdout, |
123 | (unsigned int) rd[i].record_type); | 119 | _ ("\tCorrupt or unsupported record of type %u\n"), |
120 | (unsigned int) rd[i].record_type); | ||
124 | continue; | 121 | continue; |
125 | } | 122 | } |
126 | FPRINTF (stdout, | 123 | fprintf (stdout, "\t%s: %s\n", typestring, s); |
127 | "\t%s: %s\n", | ||
128 | typestring, | ||
129 | s); | ||
130 | GNUNET_free (s); | 124 | GNUNET_free (s); |
131 | } | 125 | } |
132 | FPRINTF (stdout, "%s", "\n"); | 126 | fprintf (stdout, "%s", "\n"); |
133 | } | 127 | } |
134 | 128 | ||
135 | 129 | ||
@@ -140,24 +134,21 @@ display_records_from_block (void *cls, | |||
140 | * @param block NULL if not found | 134 | * @param block NULL if not found |
141 | */ | 135 | */ |
142 | static void | 136 | static void |
143 | handle_block (void *cls, | 137 | handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block) |
144 | const struct GNUNET_GNSRECORD_Block *block) | ||
145 | { | 138 | { |
146 | qe = NULL; | 139 | qe = NULL; |
147 | if (NULL == block) | 140 | if (NULL == block) |
148 | { | 141 | { |
149 | fprintf (stderr, | 142 | fprintf (stderr, "No matching block found\n"); |
150 | "No matching block found\n"); | ||
151 | } | 143 | } |
152 | else if (GNUNET_OK != | 144 | else if (GNUNET_OK != |
153 | GNUNET_GNSRECORD_block_decrypt (block, | 145 | GNUNET_GNSRECORD_block_decrypt (block, |
154 | &pubkey, | 146 | &pubkey, |
155 | name, | 147 | name, |
156 | &display_records_from_block, | 148 | &display_records_from_block, |
157 | NULL)) | 149 | NULL)) |
158 | { | 150 | { |
159 | fprintf (stderr, | 151 | fprintf (stderr, "Failed to decrypt block!\n"); |
160 | "Failed to decrypt block!\n"); | ||
161 | } | 152 | } |
162 | GNUNET_SCHEDULER_shutdown (); | 153 | GNUNET_SCHEDULER_shutdown (); |
163 | } | 154 | } |
@@ -172,46 +163,36 @@ handle_block (void *cls, | |||
172 | * @param cfg configuration | 163 | * @param cfg configuration |
173 | */ | 164 | */ |
174 | static void | 165 | static void |
175 | run (void *cls, char *const *args, const char *cfgfile, | 166 | run (void *cls, |
167 | char *const *args, | ||
168 | const char *cfgfile, | ||
176 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 169 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
177 | { | 170 | { |
178 | struct GNUNET_HashCode dhash; | 171 | struct GNUNET_HashCode dhash; |
179 | 172 | ||
180 | if (NULL == pkey) | 173 | if (NULL == pkey) |
181 | { | 174 | { |
182 | fprintf (stderr, | 175 | fprintf (stderr, _ ("You must specify which zone should be accessed\n")); |
183 | _("You must specify which zone should be accessed\n")); | ||
184 | return; | 176 | return; |
185 | } | 177 | } |
186 | 178 | ||
187 | if (GNUNET_OK != | 179 | if (GNUNET_OK != |
188 | GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, | 180 | GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey)) |
189 | strlen (pkey), | ||
190 | &pubkey)) | ||
191 | { | 181 | { |
192 | fprintf (stderr, | 182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); |
193 | _("Invalid public key for zone `%s'\n"), | ||
194 | pkey); | ||
195 | GNUNET_SCHEDULER_shutdown (); | 183 | GNUNET_SCHEDULER_shutdown (); |
196 | return; | 184 | return; |
197 | } | 185 | } |
198 | if (NULL == name) | 186 | if (NULL == name) |
199 | { | 187 | { |
200 | fprintf (stderr, | 188 | fprintf (stderr, _ ("You must specify a name\n")); |
201 | _("You must specify a name\n")); | ||
202 | return; | 189 | return; |
203 | } | 190 | } |
204 | 191 | ||
205 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 192 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
206 | NULL); | ||
207 | ns = GNUNET_NAMECACHE_connect (cfg); | 193 | ns = GNUNET_NAMECACHE_connect (cfg); |
208 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | 194 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &dhash); |
209 | name, | 195 | qe = GNUNET_NAMECACHE_lookup_block (ns, &dhash, &handle_block, NULL); |
210 | &dhash); | ||
211 | qe = GNUNET_NAMECACHE_lookup_block (ns, | ||
212 | &dhash, | ||
213 | &handle_block, | ||
214 | NULL); | ||
215 | } | 196 | } |
216 | 197 | ||
217 | 198 | ||
@@ -225,36 +206,39 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
225 | int | 206 | int |
226 | main (int argc, char *const *argv) | 207 | main (int argc, char *const *argv) |
227 | { | 208 | { |
228 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 209 | struct GNUNET_GETOPT_CommandLineOption options[] = |
229 | GNUNET_GETOPT_option_string ('n', | 210 | {GNUNET_GETOPT_option_string ('n', |
230 | "name", | 211 | "name", |
231 | "NAME", | 212 | "NAME", |
232 | gettext_noop ("name of the record to add/delete/display"), | 213 | gettext_noop ( |
233 | &name), | 214 | "name of the record to add/delete/display"), |
234 | 215 | &name), | |
235 | GNUNET_GETOPT_option_string ('z', | 216 | |
236 | "zone", | 217 | GNUNET_GETOPT_option_string ( |
237 | "PKEY", | 218 | 'z', |
238 | gettext_noop ("specifies the public key of the zone to look in"), | 219 | "zone", |
239 | &pkey), | 220 | "PKEY", |
240 | 221 | gettext_noop ("specifies the public key of the zone to look in"), | |
241 | GNUNET_GETOPT_OPTION_END | 222 | &pkey), |
242 | }; | 223 | |
224 | GNUNET_GETOPT_OPTION_END}; | ||
243 | 225 | ||
244 | 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)) |
245 | return 2; | 227 | return 2; |
246 | 228 | ||
247 | GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL); | 229 | GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL); |
248 | if (GNUNET_OK != | 230 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, |
249 | GNUNET_PROGRAM_run (argc, argv, "gnunet-namecache", | 231 | argv, |
250 | _("GNUnet zone manipulation tool"), | 232 | "gnunet-namecache", |
251 | options, | 233 | _ ("GNUnet zone manipulation tool"), |
252 | &run, NULL)) | 234 | options, |
235 | &run, | ||
236 | NULL)) | ||
253 | { | 237 | { |
254 | GNUNET_free ((void*) argv); | 238 | GNUNET_free ((void *) argv); |
255 | return 1; | 239 | return 1; |
256 | } | 240 | } |
257 | GNUNET_free ((void*) argv); | 241 | GNUNET_free ((void *) argv); |
258 | return ret; | 242 | return ret; |
259 | } | 243 | } |
260 | 244 | ||