diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-11 20:43:26 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-11 20:43:26 +0000 |
commit | c51d54af0173038397fd4281d08f8f62ee6e5ddd (patch) | |
tree | 97554b9c8f3364e6ddfec17ee7df026255d21862 /src/gns/gnunet-gns.c | |
parent | 829ea8a6c2ee8ac83dcd9874973a9895013837da (diff) | |
download | gnunet-c51d54af0173038397fd4281d08f8f62ee6e5ddd.tar.gz gnunet-c51d54af0173038397fd4281d08f8f62ee6e5ddd.zip |
-more new api
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index fe2bde1d1..d1ef66331 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -64,6 +64,18 @@ static int raw = 0; | |||
64 | 64 | ||
65 | static enum GNUNET_GNS_RecordType rtype; | 65 | static enum GNUNET_GNS_RecordType rtype; |
66 | 66 | ||
67 | /* Handle to lookup request */ | ||
68 | static struct GNUNET_GNS_LookupRequest *lookup_request; | ||
69 | |||
70 | /* Handle to shorten request */ | ||
71 | static struct GNUNET_GNS_ShortenRequest *shorten_request; | ||
72 | |||
73 | /* Handle to get authority request */ | ||
74 | static struct GNUNET_GNS_GetAuthRequest *getauth_request; | ||
75 | |||
76 | /* shutdown task */ | ||
77 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | ||
78 | |||
67 | /** | 79 | /** |
68 | * Task run on shutdown. Cleans up everything. | 80 | * Task run on shutdown. Cleans up everything. |
69 | * | 81 | * |
@@ -74,21 +86,29 @@ static void | |||
74 | do_shutdown (void *cls, | 86 | do_shutdown (void *cls, |
75 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 87 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
76 | { | 88 | { |
89 | if (NULL != lookup_request) | ||
90 | GNUNET_GNS_cancel_lookup_request (lookup_request); | ||
91 | |||
92 | if (NULL != shorten_request) | ||
93 | GNUNET_GNS_cancel_shorten_request (shorten_request); | ||
94 | |||
95 | if (NULL != getauth_request) | ||
96 | GNUNET_GNS_cancel_get_auth_request (getauth_request); | ||
97 | |||
77 | if (NULL != gns) | 98 | if (NULL != gns) |
78 | { | ||
79 | GNUNET_GNS_disconnect (gns); | 99 | GNUNET_GNS_disconnect (gns); |
80 | gns = NULL; | ||
81 | } | ||
82 | } | 100 | } |
83 | 101 | ||
84 | 102 | ||
85 | static void | 103 | static void |
86 | process_shorten_result(void* cls, const char* nshort) | 104 | process_shorten_result(void* cls, const char* nshort) |
87 | { | 105 | { |
106 | shorten_request = NULL; | ||
88 | if (raw) | 107 | if (raw) |
89 | printf("%s", nshort); | 108 | printf("%s", nshort); |
90 | else | 109 | else |
91 | printf("%s shortened to %s\n", (char*) cls, nshort); | 110 | printf("%s shortened to %s\n", (char*) cls, nshort); |
111 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
92 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 112 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
93 | } | 113 | } |
94 | 114 | ||
@@ -100,6 +120,7 @@ process_lookup_result(void* cls, uint32_t rd_count, | |||
100 | char* name = (char*) cls; | 120 | char* name = (char*) cls; |
101 | const char* typename; | 121 | const char* typename; |
102 | char* string_val; | 122 | char* string_val; |
123 | lookup_request = NULL; | ||
103 | 124 | ||
104 | if (!raw) { | 125 | if (!raw) { |
105 | if (rd_count == 0) | 126 | if (rd_count == 0) |
@@ -122,14 +143,16 @@ process_lookup_result(void* cls, uint32_t rd_count, | |||
122 | printf("Got %s record: %s\n", typename, string_val); | 143 | printf("Got %s record: %s\n", typename, string_val); |
123 | 144 | ||
124 | } | 145 | } |
125 | 146 | GNUNET_SCHEDULER_cancel (shutdown_task); | |
126 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 147 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
127 | } | 148 | } |
128 | 149 | ||
129 | static void | 150 | static void |
130 | process_auth_result(void* cls, const char* auth) | 151 | process_auth_result(void* cls, const char* auth) |
131 | { | 152 | { |
153 | getauth_request = NULL; | ||
132 | printf ("%s\n", auth); | 154 | printf ("%s\n", auth); |
155 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
133 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 156 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
134 | } | 157 | } |
135 | 158 | ||
@@ -156,6 +179,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
156 | struct GNUNET_CRYPTO_ShortHashCode private_zone; | 179 | struct GNUNET_CRYPTO_ShortHashCode private_zone; |
157 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; | 180 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; |
158 | 181 | ||
182 | shorten_request = NULL; | ||
183 | lookup_request = NULL; | ||
184 | getauth_request = NULL; | ||
185 | |||
159 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | 186 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", |
160 | "ZONEKEY", &keyfile)) | 187 | "ZONEKEY", &keyfile)) |
161 | { | 188 | { |
@@ -265,7 +292,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
265 | 292 | ||
266 | if (NULL != shorten_name) | 293 | if (NULL != shorten_name) |
267 | { | 294 | { |
268 | GNUNET_GNS_shorten_zone (gns, shorten_name, | 295 | shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name, |
269 | &private_zone, | 296 | &private_zone, |
270 | &shorten_zone, | 297 | &shorten_zone, |
271 | zone, | 298 | zone, |
@@ -277,7 +304,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
277 | { | 304 | { |
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
279 | "Lookup\n"); | 306 | "Lookup\n"); |
280 | GNUNET_GNS_lookup_zone (gns, lookup_name, | 307 | lookup_request = GNUNET_GNS_lookup_zone (gns, lookup_name, |
281 | zone, | 308 | zone, |
282 | rtype, | 309 | rtype, |
283 | GNUNET_NO, //Use DHT | 310 | GNUNET_NO, //Use DHT |
@@ -287,14 +314,15 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
287 | 314 | ||
288 | if (NULL != auth_name) | 315 | if (NULL != auth_name) |
289 | { | 316 | { |
290 | GNUNET_GNS_get_authority(gns, auth_name, &process_auth_result, auth_name); | 317 | getauth_request = GNUNET_GNS_get_authority(gns, auth_name, |
318 | &process_auth_result, auth_name); | ||
291 | } | 319 | } |
292 | 320 | ||
293 | if (NULL != shorten_key) | 321 | if (NULL != shorten_key) |
294 | GNUNET_CRYPTO_rsa_key_free (shorten_key); | 322 | GNUNET_CRYPTO_rsa_key_free (shorten_key); |
295 | 323 | ||
296 | // FIXME: do work here... | 324 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
297 | //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 325 | &do_shutdown, NULL); |
298 | } | 326 | } |
299 | 327 | ||
300 | 328 | ||