[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35465 - in gnunet/src: identity rest
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35465 - in gnunet/src: identity rest |
Date: |
Thu, 26 Mar 2015 17:40:36 +0100 |
Author: schanzen
Date: 2015-03-26 17:40:36 +0100 (Thu, 26 Mar 2015)
New Revision: 35465
Modified:
gnunet/src/identity/plugin_rest_identity.c
gnunet/src/rest/rest.c
Log:
-add rename
Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c 2015-03-26 15:51:56 UTC (rev
35464)
+++ gnunet/src/identity/plugin_rest_identity.c 2015-03-26 16:40:36 UTC (rev
35465)
@@ -43,6 +43,8 @@
#define GNUNET_REST_JSONAPI_IDENTITY_KEY "key"
+#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname"
+
#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem"
/**
@@ -381,11 +383,11 @@
}
static void
-set_finished (void *cls, const char *emsg)
+edit_finished (void *cls, const char *emsg)
{
struct RequestHandle *handle = cls;
struct MHD_Response *resp;
-
+
handle->op = NULL;
if (NULL != emsg)
{
@@ -427,7 +429,6 @@
json_t *egoname_json;
char term_data[handle->data_size+1];
const char* egoname;
-
if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -441,19 +442,20 @@
term_data[handle->data_size] = '\0';
memcpy (term_data, handle->data, handle->data_size);
json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "2\n");
if (NULL == json_obj)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "2.1\n");
if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
{
GNUNET_REST_jsonapi_object_delete (json_obj);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "3\n");
json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res,
GNUNET_REST_JSONAPI_IDENTITY_EGO))
{
@@ -463,7 +465,7 @@
cleanup_handle (handle);
return;
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "4\n");
egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
GNUNET_REST_JSONAPI_KEY_ID);
if (!json_is_string (egoname_json))
{
@@ -496,7 +498,7 @@
}
void
-subsys_set_cont (struct RestConnectionDataHandle *con,
+ego_edit_cont (struct RestConnectionDataHandle *con,
const char *url,
void *cls)
{
@@ -504,12 +506,14 @@
struct JsonApiResource *json_res;
const char *egoname;
const char *subsys;
+ const char *newname;
struct RequestHandle *handle = cls;
char term_data[handle->data_size+1];
struct EgoEntry *ego_entry;
struct MHD_Response *resp;
int ego_exists = GNUNET_NO;
json_t *subsys_json;
+ json_t *name_json;
if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
{
@@ -557,39 +561,55 @@
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
-
- json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
- if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_id (json_res, egoname))
+ json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
+ if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res,
GNUNET_REST_JSONAPI_IDENTITY_EGO))
{
GNUNET_REST_jsonapi_object_delete (json_obj);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
-
- if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_id (json_res,
GNUNET_REST_JSONAPI_IDENTITY_EGO))
+ //This is a rename
+ name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
+ if (NULL != name_json)
{
- GNUNET_REST_jsonapi_object_delete (json_obj);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
+ newname = NULL;
+ if (json_is_string (name_json))
+ {
+ newname = json_string_value (name_json);
+ handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
+ egoname,
+ newname,
+ &edit_finished,
+ handle);
+ GNUNET_REST_jsonapi_object_delete (json_obj);
+ json_decref (name_json);
+ return;
+ }
+ json_decref (name_json);
}
subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
- if (!json_is_string (subsys_json))
+ if (NULL != subsys_json)
{
+ subsys = NULL;
+ if (json_is_string (subsys_json))
+ {
+ subsys = json_string_value (subsys_json);
+ GNUNET_asprintf (&handle->subsys, "%s", subsys);
+ GNUNET_REST_jsonapi_object_delete (json_obj);
+ handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
+ handle->subsys,
+ ego_entry->ego,
+ &edit_finished,
+ handle);
+ json_decref (subsys_json);
+ return;
+ }
json_decref (subsys_json);
- GNUNET_REST_jsonapi_object_delete (json_obj);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
}
- subsys = json_string_value (subsys_json);
- GNUNET_asprintf (&handle->subsys, "%s", subsys);
- json_decref (subsys_json);
GNUNET_REST_jsonapi_object_delete (json_obj);
- handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
- handle->subsys,
- ego_entry->ego,
- &set_finished,
- handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+
}
void
@@ -640,7 +660,7 @@
static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
- {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &subsys_set_cont},
+ {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont},
{MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
GNUNET_REST_HANDLER_END
};
Modified: gnunet/src/rest/rest.c
===================================================================
--- gnunet/src/rest/rest.c 2015-03-26 15:51:56 UTC (rev 35464)
+++ gnunet/src/rest/rest.c 2015-03-26 16:40:36 UTC (rev 35465)
@@ -188,7 +188,7 @@
GNUNET_REST_jsonapi_resource_check_id (const struct JsonApiResource *resource,
const char* id)
{
- return check_resource_attr_str (resource, id, GNUNET_REST_JSONAPI_KEY_ID);
+ return check_resource_attr_str (resource, GNUNET_REST_JSONAPI_KEY_ID, id);
}
@@ -203,7 +203,7 @@
GNUNET_REST_jsonapi_resource_check_type (const struct JsonApiResource
*resource,
const char* type)
{
- return check_resource_attr_str (resource, type,
GNUNET_REST_JSONAPI_KEY_TYPE);
+ return check_resource_attr_str (resource, GNUNET_REST_JSONAPI_KEY_TYPE,
type);
}
@@ -233,10 +233,8 @@
id_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_ID);
type_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_TYPE);
-
if (!json_is_string (id_json) || !json_is_string (type_json))
return;
-
res = GNUNET_new (struct JsonApiResource);
res->next = NULL;
res->prev = NULL;
@@ -259,7 +257,6 @@
json_error_t error;
int res_count = 0;
int i;
-
if (NULL == data)
return NULL;
root_json = json_loads (data, 0, &error);
@@ -287,7 +284,7 @@
add_json_resource (result, json_array_get (data_json, i));
}
json_decref (root_json);
- if (0 == res_count)
+ if (0 == result->res_count)
{
GNUNET_free (result);
result = NULL;
@@ -366,8 +363,8 @@
struct JsonApiResource *res;
int i;
- if ((0 < resp->res_count) &&
- (num < resp->res_count))
+ if ((0 == resp->res_count) ||
+ (num >= resp->res_count))
return NULL;
res = resp->res_list_head;
for (i = 0; i < num; i++)
@@ -505,11 +502,11 @@
for (i = 0; i < count; i++)
{
if (0 != strcasecmp (conn->method, handlers[i].method))
- break;
+ continue;
if (strlen (url) < strlen (handlers[i].namespace))
- break;
+ continue;
if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
- break;
+ continue;
//Match
handlers[i].proc (conn, (const char*)url, cls);
GNUNET_free (url);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35465 - in gnunet/src: identity rest,
gnunet <=