You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
* @author Martin Schanzenbach
* Rest connection
*/
struct GNUNET_REST_RequestHandle *rest_handle;
-
+
/**
* Desired timeout for the lookup (default is no timeout).
*/
handle->list_it = NULL;
if (NULL == handle->resp_object)
- {
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
- }
+ handle->resp_object = json_array();
result_str = json_dumps (handle->resp_object, 0);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
(0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)) )
continue;
- record_obj = GNUNET_JSON_from_gns_record(rname,rd);
+ record_obj = GNUNET_JSON_from_gns_record (rname, &rd[i]);
if(NULL == record_obj)
continue;
GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
}
+/**
+ * @param cls closure
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ * (during the lifetime of this process, initially NULL)
+ * @param identifier identifier assigned by the user for this ego,
+ * NULL if the user just deleted the ego and it
+ * must thus no longer be used
+ */
+static void
+default_ego_get (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *identifier)
+{
+ struct RequestHandle *handle = cls;
+ handle->op = NULL;
+
+ if (ego == NULL)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+ handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
+
+ handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
+ handle->zone_pkey,
+ &namestore_iteration_error,
+ handle,
+ &namestore_list_iteration,
+ handle,
+ &namestore_list_finished,
+ handle);
+ if (NULL == handle->list_it)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+}
+
/**
* Handle namestore GET request
{
handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
}
+
if (NULL == handle->zone_pkey)
{
- handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
+ "namestore",
+ &default_ego_get,
+ handle);
return;
}
handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
}
+/**
+ * @param cls closure
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ * (during the lifetime of this process, initially NULL)
+ * @param identifier identifier assigned by the user for this ego,
+ * NULL if the user just deleted the ego and it
+ * must thus no longer be used
+ */
+static void
+default_ego_post (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *identifier)
+{
+ struct RequestHandle *handle = cls;
+ handle->op = NULL;
+
+ if (ego == NULL)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+ handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
+
+ handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+ handle->zone_pkey,
+ handle->record_name,
+ 1,
+ handle->rd,
+ &create_finished,
+ handle);
+ if (NULL == handle->add_qe)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+}
+
+
/**
* Handle namestore POST request
*
handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
}
if (NULL == handle->zone_pkey)
+ {
+ handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
+ "namestore",
+ &default_ego_post,
+ handle);
+ return;
+ }
+ handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+ handle->zone_pkey,
+ handle->record_name,
+ 1,
+ handle->rd,
+ &create_finished,
+ handle);
+ if (NULL == handle->add_qe)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+}
+
+
+/**
+ * @param cls closure
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ * (during the lifetime of this process, initially NULL)
+ * @param identifier identifier assigned by the user for this ego,
+ * NULL if the user just deleted the ego and it
+ * must thus no longer be used
+ */
+static void
+default_ego_delete (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *identifier)
+{
+ struct RequestHandle *handle = cls;
+ handle->op = NULL;
+
+ if (ego == NULL)
{
handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
+ handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
+
handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
- handle->zone_pkey,
- handle->record_name,
- 1,
- handle->rd,
- &create_finished,
- handle);
+ handle->zone_pkey,
+ handle->record_name,
+ 0,
+ NULL,
+ &del_finished,
+ handle);
if (NULL == handle->add_qe)
{
handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
if (NULL == handle->zone_pkey)
{
- handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
+ "namestore",
+ &default_ego_delete,
+ handle);
return;
}
}
}
-/**
- * @param cls closure
- * @param ego ego handle
- * @param ctx context for application to store data for this ego
- * (during the lifetime of this process, initially NULL)
- * @param identifier identifier assigned by the user for this ego,
- * NULL if the user just deleted the ego and it
- * must thus no longer be used
- */
-static void
-default_ego_cb (void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *identifier)
-{
- struct RequestHandle *handle = cls;
- handle->op = NULL;
-
- if (ego != NULL)
- {
- handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
- }
-}
-
/**
* This function is initially called for all egos and then again
struct EgoEntry *ego_entry;
struct GNUNET_CRYPTO_EcdsaPublicKey pk;
- if ((NULL == ego) && (NULL == handle->zone_pkey))
- {
- handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
- "namestore",
- &default_ego_cb,
- handle);
- }
if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
{
handle->state = ID_REST_STATE_POST_INIT;
- init_cont (handle);
+ init_cont(handle);
return;
}
if (ID_REST_STATE_INIT == handle->state)
void *proc_cls)
{
struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
-
+
handle->response_code = 0;
handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
handle->proc_cls = proc_cls;
handle->proc = proc;
handle->rest_handle = rest_handle;
handle->zone_pkey = NULL;
-
+
handle->url = GNUNET_strdup (rest_handle->url);
if (handle->url[strlen (handle->url)-1] == '/')
handle->url[strlen (handle->url)-1] = '\0';
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
- handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
+ handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
handle->timeout_task =
GNUNET_SCHEDULER_add_delayed (handle->timeout,
&do_error,
handle);
-
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
}