diff options
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 290 |
1 files changed, 127 insertions, 163 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 02e42d03f..6859396d6 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -127,6 +127,26 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
127 | static char *allow_methods; | 127 | static char *allow_methods; |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Ego list | ||
131 | */ | ||
132 | static struct EgoEntry *ego_head; | ||
133 | |||
134 | /** | ||
135 | * Ego list | ||
136 | */ | ||
137 | static struct EgoEntry *ego_tail; | ||
138 | |||
139 | /** | ||
140 | * The processing state | ||
141 | */ | ||
142 | static int state; | ||
143 | |||
144 | /** | ||
145 | * Handle to Identity service. | ||
146 | */ | ||
147 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
148 | |||
149 | /** | ||
130 | * @brief struct returned by the initialization function of the plugin | 150 | * @brief struct returned by the initialization function of the plugin |
131 | */ | 151 | */ |
132 | struct Plugin | 152 | struct Plugin |
@@ -185,27 +205,6 @@ struct RequestHandle | |||
185 | */ | 205 | */ |
186 | size_t data_size; | 206 | size_t data_size; |
187 | 207 | ||
188 | |||
189 | /** | ||
190 | * Ego list | ||
191 | */ | ||
192 | struct EgoEntry *ego_head; | ||
193 | |||
194 | /** | ||
195 | * Ego list | ||
196 | */ | ||
197 | struct EgoEntry *ego_tail; | ||
198 | |||
199 | /** | ||
200 | * The processing state | ||
201 | */ | ||
202 | int state; | ||
203 | |||
204 | /** | ||
205 | * Handle to Identity service. | ||
206 | */ | ||
207 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
208 | |||
209 | /** | 208 | /** |
210 | * IDENTITY Operation | 209 | * IDENTITY Operation |
211 | */ | 210 | */ |
@@ -260,8 +259,6 @@ static void | |||
260 | cleanup_handle (void *cls) | 259 | cleanup_handle (void *cls) |
261 | { | 260 | { |
262 | struct RequestHandle *handle = cls; | 261 | struct RequestHandle *handle = cls; |
263 | struct EgoEntry *ego_entry; | ||
264 | struct EgoEntry *ego_tmp; | ||
265 | 262 | ||
266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
267 | if (NULL != handle->timeout_task) | 264 | if (NULL != handle->timeout_task) |
@@ -276,17 +273,6 @@ cleanup_handle (void *cls) | |||
276 | GNUNET_free (handle->emsg); | 273 | GNUNET_free (handle->emsg); |
277 | if (NULL != handle->name) | 274 | if (NULL != handle->name) |
278 | GNUNET_free (handle->name); | 275 | GNUNET_free (handle->name); |
279 | if (NULL != handle->identity_handle) | ||
280 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
281 | |||
282 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | ||
283 | { | ||
284 | ego_tmp = ego_entry; | ||
285 | ego_entry = ego_entry->next; | ||
286 | GNUNET_free (ego_tmp->identifier); | ||
287 | GNUNET_free (ego_tmp->keystring); | ||
288 | GNUNET_free (ego_tmp); | ||
289 | } | ||
290 | 276 | ||
291 | GNUNET_free (handle); | 277 | GNUNET_free (handle); |
292 | } | 278 | } |
@@ -338,7 +324,7 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
338 | 324 | ||
339 | if (NULL != pubkey) | 325 | if (NULL != pubkey) |
340 | { | 326 | { |
341 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 327 | for (ego_entry = ego_head; NULL != ego_entry; |
342 | ego_entry = ego_entry->next) | 328 | ego_entry = ego_entry->next) |
343 | { | 329 | { |
344 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) | 330 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) |
@@ -348,7 +334,7 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
348 | } | 334 | } |
349 | if (NULL != name) | 335 | if (NULL != name) |
350 | { | 336 | { |
351 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 337 | for (ego_entry = ego_head; NULL != ego_entry; |
352 | ego_entry = ego_entry->next) | 338 | ego_entry = ego_entry->next) |
353 | { | 339 | { |
354 | if (0 != strcasecmp (name, ego_entry->identifier)) | 340 | if (0 != strcasecmp (name, ego_entry->identifier)) |
@@ -438,7 +424,7 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
438 | // requested default identity of subsystem | 424 | // requested default identity of subsystem |
439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); |
440 | 426 | ||
441 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 427 | handle->op = GNUNET_IDENTITY_get (identity_handle, |
442 | subsystem, | 428 | subsystem, |
443 | &ego_get_for_subsystem, | 429 | &ego_get_for_subsystem, |
444 | handle); | 430 | handle); |
@@ -476,7 +462,7 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
476 | 462 | ||
477 | json_root = json_array (); | 463 | json_root = json_array (); |
478 | // Return ego/egos | 464 | // Return ego/egos |
479 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 465 | for (ego_entry = ego_head; NULL != ego_entry; |
480 | ego_entry = ego_entry->next) | 466 | ego_entry = ego_entry->next) |
481 | { | 467 | { |
482 | json_ego = json_object (); | 468 | json_ego = json_object (); |
@@ -766,7 +752,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
766 | json_decref (data_js); | 752 | json_decref (data_js); |
767 | return; | 753 | return; |
768 | } | 754 | } |
769 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | 755 | handle->op = GNUNET_IDENTITY_rename (identity_handle, |
770 | ego_entry->identifier, | 756 | ego_entry->identifier, |
771 | newname, | 757 | newname, |
772 | &do_finished, | 758 | &do_finished, |
@@ -956,7 +942,7 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
956 | } | 942 | } |
957 | 943 | ||
958 | handle->response_code = MHD_HTTP_NO_CONTENT; | 944 | handle->response_code = MHD_HTTP_NO_CONTENT; |
959 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 945 | handle->op = GNUNET_IDENTITY_set (identity_handle, |
960 | newsubsys, | 946 | newsubsys, |
961 | ego_entry->ego, | 947 | ego_entry->ego, |
962 | &do_finished, | 948 | &do_finished, |
@@ -1047,7 +1033,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1047 | return; | 1033 | return; |
1048 | } | 1034 | } |
1049 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); | 1035 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); |
1050 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1036 | for (ego_entry = ego_head; NULL != ego_entry; |
1051 | ego_entry = ego_entry->next) | 1037 | ego_entry = ego_entry->next) |
1052 | { | 1038 | { |
1053 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | 1039 | if (0 == strcasecmp (egoname, ego_entry->identifier)) |
@@ -1073,7 +1059,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1073 | pk_ptr = NULL; | 1059 | pk_ptr = NULL; |
1074 | json_decref (data_js); | 1060 | json_decref (data_js); |
1075 | handle->response_code = MHD_HTTP_CREATED; | 1061 | handle->response_code = MHD_HTTP_CREATED; |
1076 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1062 | handle->op = GNUNET_IDENTITY_create (identity_handle, |
1077 | handle->name, | 1063 | handle->name, |
1078 | pk_ptr, | 1064 | pk_ptr, |
1079 | &do_finished_create, | 1065 | &do_finished_create, |
@@ -1118,7 +1104,7 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1118 | } | 1104 | } |
1119 | 1105 | ||
1120 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1106 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1121 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1107 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1122 | ego_entry->identifier, | 1108 | ego_entry->identifier, |
1123 | &do_finished, | 1109 | &do_finished, |
1124 | handle); | 1110 | handle); |
@@ -1162,7 +1148,7 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1162 | } | 1148 | } |
1163 | 1149 | ||
1164 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1150 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1165 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1151 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1166 | ego_entry->identifier, | 1152 | ego_entry->identifier, |
1167 | &do_finished, | 1153 | &do_finished, |
1168 | handle); | 1154 | handle); |
@@ -1193,144 +1179,78 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1193 | } | 1179 | } |
1194 | 1180 | ||
1195 | 1181 | ||
1196 | /** | ||
1197 | * Handle rest request | ||
1198 | * | ||
1199 | * @param handle the request handle | ||
1200 | */ | ||
1201 | static void | ||
1202 | init_cont (struct RequestHandle *handle) | ||
1203 | { | ||
1204 | struct GNUNET_REST_RequestHandlerError err; | ||
1205 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1206 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | ||
1207 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1208 | &ego_get_pubkey }, | ||
1209 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | ||
1210 | { MHD_HTTP_METHOD_GET, | ||
1211 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1212 | &ego_get_subsystem }, | ||
1213 | { MHD_HTTP_METHOD_PUT, | ||
1214 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1215 | &ego_edit_pubkey }, | ||
1216 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | ||
1217 | { MHD_HTTP_METHOD_PUT, | ||
1218 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1219 | &ego_edit_subsystem }, | ||
1220 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | ||
1221 | { MHD_HTTP_METHOD_DELETE, | ||
1222 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1223 | &ego_delete_pubkey }, | ||
1224 | { MHD_HTTP_METHOD_DELETE, | ||
1225 | GNUNET_REST_API_NS_IDENTITY_NAME, | ||
1226 | &ego_delete_name }, | ||
1227 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, | ||
1228 | GNUNET_REST_HANDLER_END }; | ||
1229 | |||
1230 | if (GNUNET_NO == | ||
1231 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
1232 | { | ||
1233 | handle->response_code = err.error_code; | ||
1234 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
1235 | } | ||
1236 | } | ||
1237 | |||
1238 | |||
1239 | /** | ||
1240 | * If listing is enabled, prints information about the egos. | ||
1241 | * | ||
1242 | * This function is initially called for all egos and then again | ||
1243 | * whenever a ego's identifier changes or if it is deleted. At the | ||
1244 | * end of the initial pass over all egos, the function is once called | ||
1245 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
1246 | * be invoked in the future or that there was an error. | ||
1247 | * | ||
1248 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
1249 | * this function is only called ONCE, and 'NULL' being passed in | ||
1250 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
1251 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
1252 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
1253 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
1254 | * that one was not NULL). | ||
1255 | * | ||
1256 | * When an identity is renamed, this function is called with the | ||
1257 | * (known) ego but the NEW identifier. | ||
1258 | * | ||
1259 | * When an identity is deleted, this function is called with the | ||
1260 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
1261 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
1262 | * cleaned up). | ||
1263 | * | ||
1264 | * @param cls closure | ||
1265 | * @param ego ego handle | ||
1266 | * @param ctx context for application to store data for this ego | ||
1267 | * (during the lifetime of this process, initially NULL) | ||
1268 | * @param identifier identifier assigned by the user for this ego, | ||
1269 | * NULL if the user just deleted the ego and it | ||
1270 | * must thus no longer be used | ||
1271 | */ | ||
1272 | static void | 1182 | static void |
1273 | init_egos (void *cls, | 1183 | list_ego (void *cls, |
1274 | struct GNUNET_IDENTITY_Ego *ego, | 1184 | struct GNUNET_IDENTITY_Ego *ego, |
1275 | void **ctx, | 1185 | void **ctx, |
1276 | const char *identifier) | 1186 | const char *identifier) |
1277 | { | 1187 | { |
1278 | struct RequestHandle *handle = cls; | ||
1279 | struct EgoEntry *ego_entry; | 1188 | struct EgoEntry *ego_entry; |
1280 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1189 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1281 | 1190 | ||
1282 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1191 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1283 | { | 1192 | { |
1284 | handle->state = ID_REST_STATE_POST_INIT; | 1193 | state = ID_REST_STATE_POST_INIT; |
1285 | init_cont (handle); | ||
1286 | return; | 1194 | return; |
1287 | } | 1195 | } |
1288 | if (ID_REST_STATE_INIT == handle->state) | 1196 | if (ID_REST_STATE_INIT == state) |
1289 | { | 1197 | { |
1290 | ego_entry = GNUNET_new (struct EgoEntry); | 1198 | ego_entry = GNUNET_new (struct EgoEntry); |
1291 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1199 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1292 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1200 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
1293 | ego_entry->ego = ego; | 1201 | ego_entry->ego = ego; |
1294 | ego_entry->identifier = GNUNET_strdup (identifier); | 1202 | ego_entry->identifier = GNUNET_strdup (identifier); |
1295 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 1203 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
1296 | handle->ego_tail, | 1204 | ego_tail, |
1297 | ego_entry); | 1205 | ego_entry); |
1298 | return; | ||
1299 | } | 1206 | } |
1300 | // Check if ego exists | 1207 | /* Ego renamed or added */ |
1301 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 1208 | if (identifier != NULL) |
1302 | { | 1209 | { |
1303 | struct EgoEntry *tmp = ego_entry; | 1210 | for (ego_entry = ego_head; NULL != ego_entry; |
1304 | ego_entry = ego_entry->next; | 1211 | ego_entry = ego_entry->next) |
1305 | if (ego != tmp->ego) | ||
1306 | continue; | ||
1307 | // Deleted | ||
1308 | if (NULL == identifier) | ||
1309 | { | 1212 | { |
1310 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | 1213 | if (ego_entry->ego == ego) |
1311 | handle->ego_tail, | 1214 | { |
1312 | tmp); | 1215 | /* Rename */ |
1313 | GNUNET_free (tmp->keystring); | 1216 | GNUNET_free (ego_entry->identifier); |
1314 | GNUNET_free (tmp->identifier); | 1217 | ego_entry->identifier = GNUNET_strdup (identifier); |
1315 | GNUNET_free (tmp); | 1218 | break; |
1219 | } | ||
1316 | } | 1220 | } |
1317 | else | 1221 | if (NULL == ego_entry) |
1318 | { | 1222 | { |
1319 | // Renamed | 1223 | /* Add */ |
1320 | GNUNET_free (tmp->identifier); | 1224 | ego_entry = GNUNET_new (struct EgoEntry); |
1321 | tmp->identifier = GNUNET_strdup (identifier); | 1225 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1226 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
1227 | ego_entry->ego = ego; | ||
1228 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
1229 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
1230 | ego_tail, | ||
1231 | ego_entry); | ||
1322 | } | 1232 | } |
1233 | } | ||
1234 | else | ||
1235 | { | ||
1236 | /* Delete */ | ||
1237 | for (ego_entry = ego_head; NULL != ego_entry; | ||
1238 | ego_entry = ego_entry->next) | ||
1239 | { | ||
1240 | if (ego_entry->ego == ego) | ||
1241 | break; | ||
1242 | } | ||
1243 | if (NULL == ego_entry) | ||
1244 | return; /* Not found */ | ||
1245 | |||
1246 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
1247 | ego_tail, | ||
1248 | ego_entry); | ||
1249 | GNUNET_free (ego_entry->identifier); | ||
1250 | GNUNET_free (ego_entry->keystring); | ||
1251 | GNUNET_free (ego_entry); | ||
1323 | return; | 1252 | return; |
1324 | } | 1253 | } |
1325 | // New ego | ||
1326 | ego_entry = GNUNET_new (struct EgoEntry); | ||
1327 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
1328 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
1329 | ego_entry->ego = ego; | ||
1330 | GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); | ||
1331 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | ||
1332 | handle->ego_tail, | ||
1333 | ego_entry); | ||
1334 | 1254 | ||
1335 | } | 1255 | } |
1336 | 1256 | ||
@@ -1346,12 +1266,38 @@ init_egos (void *cls, | |||
1346 | * @param proc_cls closure for callback function | 1266 | * @param proc_cls closure for callback function |
1347 | * @return GNUNET_OK if request accepted | 1267 | * @return GNUNET_OK if request accepted |
1348 | */ | 1268 | */ |
1349 | static void | 1269 | static enum GNUNET_GenericReturnValue |
1350 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1270 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
1351 | GNUNET_REST_ResultProcessor proc, | 1271 | GNUNET_REST_ResultProcessor proc, |
1352 | void *proc_cls) | 1272 | void *proc_cls) |
1353 | { | 1273 | { |
1354 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1274 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1275 | struct GNUNET_REST_RequestHandlerError err; | ||
1276 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1277 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | ||
1278 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1279 | &ego_get_pubkey }, | ||
1280 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | ||
1281 | { MHD_HTTP_METHOD_GET, | ||
1282 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1283 | &ego_get_subsystem }, | ||
1284 | { MHD_HTTP_METHOD_PUT, | ||
1285 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1286 | &ego_edit_pubkey }, | ||
1287 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | ||
1288 | { MHD_HTTP_METHOD_PUT, | ||
1289 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1290 | &ego_edit_subsystem }, | ||
1291 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | ||
1292 | { MHD_HTTP_METHOD_DELETE, | ||
1293 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1294 | &ego_delete_pubkey }, | ||
1295 | { MHD_HTTP_METHOD_DELETE, | ||
1296 | GNUNET_REST_API_NS_IDENTITY_NAME, | ||
1297 | &ego_delete_name }, | ||
1298 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, | ||
1299 | GNUNET_REST_HANDLER_END }; | ||
1300 | |||
1355 | 1301 | ||
1356 | handle->response_code = 0; | 1302 | handle->response_code = 0; |
1357 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1303 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1365,13 +1311,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1365 | if (handle->url[strlen (handle->url) - 1] == '/') | 1311 | if (handle->url[strlen (handle->url) - 1] == '/') |
1366 | handle->url[strlen (handle->url) - 1] = '\0'; | 1312 | handle->url[strlen (handle->url) - 1] = '\0'; |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1368 | 1314 | if (GNUNET_NO == | |
1369 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &init_egos, handle); | 1315 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
1316 | { | ||
1317 | cleanup_handle (handle); | ||
1318 | return GNUNET_NO; | ||
1319 | } | ||
1370 | 1320 | ||
1371 | handle->timeout_task = | 1321 | handle->timeout_task = |
1372 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | 1322 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); |
1373 | |||
1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1324 | return GNUNET_YES; | ||
1375 | } | 1325 | } |
1376 | 1326 | ||
1377 | 1327 | ||
@@ -1403,6 +1353,7 @@ libgnunet_plugin_rest_identity_init (void *cls) | |||
1403 | MHD_HTTP_METHOD_PUT, | 1353 | MHD_HTTP_METHOD_PUT, |
1404 | MHD_HTTP_METHOD_DELETE, | 1354 | MHD_HTTP_METHOD_DELETE, |
1405 | MHD_HTTP_METHOD_OPTIONS); | 1355 | MHD_HTTP_METHOD_OPTIONS); |
1356 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | ||
1406 | 1357 | ||
1407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); | 1358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); |
1408 | return api; | 1359 | return api; |
@@ -1420,8 +1371,21 @@ libgnunet_plugin_rest_identity_done (void *cls) | |||
1420 | { | 1371 | { |
1421 | struct GNUNET_REST_Plugin *api = cls; | 1372 | struct GNUNET_REST_Plugin *api = cls; |
1422 | struct Plugin *plugin = api->cls; | 1373 | struct Plugin *plugin = api->cls; |
1374 | struct EgoEntry *ego_entry; | ||
1375 | struct EgoEntry *ego_tmp; | ||
1423 | 1376 | ||
1424 | plugin->cfg = NULL; | 1377 | plugin->cfg = NULL; |
1378 | if (NULL != identity_handle) | ||
1379 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
1380 | |||
1381 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
1382 | { | ||
1383 | ego_tmp = ego_entry; | ||
1384 | ego_entry = ego_entry->next; | ||
1385 | GNUNET_free (ego_tmp->identifier); | ||
1386 | GNUNET_free (ego_tmp->keystring); | ||
1387 | GNUNET_free (ego_tmp); | ||
1388 | } | ||
1425 | 1389 | ||
1426 | GNUNET_free (allow_methods); | 1390 | GNUNET_free (allow_methods); |
1427 | GNUNET_free (api); | 1391 | GNUNET_free (api); |