This commit is contained in:
@@ -466,7 +466,10 @@ void restd_server_register_hook_on_path(restd_server_t *server, enum evhttp_cmd_
|
||||
{
|
||||
char *param;
|
||||
fragment = obj.data;
|
||||
|
||||
if (hook->has_parameter == true)
|
||||
{
|
||||
hook->action_name = strdup(fragment);
|
||||
}
|
||||
param = strchr(fragment, ':');
|
||||
if (param != NULL)
|
||||
{
|
||||
@@ -474,10 +477,6 @@ void restd_server_register_hook_on_path(restd_server_t *server, enum evhttp_cmd_
|
||||
hook->parameter_position = i;
|
||||
hook->parameter_name = strdup(param + 1);
|
||||
}
|
||||
if (hook->has_parameter == true)
|
||||
{
|
||||
hook->action_name = strdup(fragment);
|
||||
}
|
||||
|
||||
free(fragment);
|
||||
i++;
|
||||
@@ -590,11 +589,6 @@ void restd_resp_free(restd_resp_t *response)
|
||||
free(response->parameter_name);
|
||||
}
|
||||
|
||||
if (response->parameter_value)
|
||||
{
|
||||
free(response->parameter_value);
|
||||
}
|
||||
|
||||
if (response->action)
|
||||
{
|
||||
free(response->action);
|
||||
@@ -952,34 +946,54 @@ bool manage_hook(restd_hook_t *hook, restd_resp_t *response, const char *request
|
||||
else
|
||||
{
|
||||
int list_size;
|
||||
printf ("Avec param...\n");
|
||||
bool result = true;
|
||||
// printf("Avec param... %s\n", request_path);
|
||||
qlist_t *uri_fragments = qstrtokenizer(request_path, "/");
|
||||
list_size = qlist_size(hook->path_fragments);
|
||||
if (list_size == qlist_size(uri_fragments))
|
||||
{
|
||||
qlist_obj_t obj_hook;
|
||||
qlist_obj_t obj_uri;
|
||||
printf ("Les Listes ont le meme tailles...\n");
|
||||
|
||||
memset((void *)&obj_hook, 0, sizeof(obj_hook));
|
||||
memset((void *)&obj_uri, 0, sizeof(obj_uri));
|
||||
|
||||
for (int i= 0; i < list_size; i++)
|
||||
for (int i = 0; i < list_size; i++)
|
||||
{
|
||||
qlist_getnext(hook->path_fragments, &obj_hook, true);
|
||||
qlist_getnext(uri_fragments, &obj_uri, true);
|
||||
|
||||
printf ("%d] %s == %s\n", i, (char*)obj_hook.data, (char*)obj_uri.data);
|
||||
// printf("%d] %s == %s\n", i, (char *)obj_hook.data, (char *)obj_uri.data);
|
||||
if (hook->parameter_position != i)
|
||||
{
|
||||
if (strcmp(obj_hook.data, obj_uri.data) != 0)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response->parameter_value = atoi((char *)obj_uri.data);
|
||||
}
|
||||
|
||||
free(obj_hook.data);
|
||||
free(obj_uri.data);
|
||||
if (result == false)
|
||||
return false;
|
||||
}
|
||||
response->has_parameter = true;
|
||||
response->parameter_name = strdup(hook->parameter_name);
|
||||
if (hook->action_name != NULL)
|
||||
response->action = strdup(hook->action_name);
|
||||
hook->cb(response, hook->userdata);
|
||||
qlist_free(uri_fragments);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("rate: path fragment: %ld != uri_fragment: %ld\n", qlist_size(hook->path_fragments), qlist_size(uri_fragments));
|
||||
}
|
||||
|
||||
|
||||
qlist_free(uri_fragments);
|
||||
}
|
||||
#if 0
|
||||
|
||||
@@ -142,7 +142,7 @@ struct restd_resp_s
|
||||
struct evhttp_request *request;
|
||||
bool has_parameter;
|
||||
char *parameter_name;
|
||||
char *parameter_value;
|
||||
uint32_t parameter_value;
|
||||
char *action;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,9 +31,8 @@
|
||||
#define ksuccess_post_body "{\"status\":\"post\"}"
|
||||
#define kerror_body "{\"status\":\"error\"}"
|
||||
|
||||
#define ksuccess_put_param1 "{\"id\":\"1\"}"
|
||||
#define ksuccess_put_param2 "{\"id\":\"1977\",\"action\":\"todo\"}"
|
||||
|
||||
#define ksuccess_put_param1 "{ \"id\": 1 }"
|
||||
#define ksuccess_put_param2 "{ \"id\":\"1977\",\"action\":\"todo\" }"
|
||||
|
||||
#define kserver_port "7777"
|
||||
#define kapi_test_get "/api/v1/test_get"
|
||||
@@ -98,11 +97,11 @@ int my_success_rest_put_param_handler(restd_resp_t *response, void *arg)
|
||||
struct json_object *root_node;
|
||||
root_node = json_object_new_object();
|
||||
|
||||
if (response->has_parameter)
|
||||
if (response->has_parameter == true)
|
||||
{
|
||||
if ((response->parameter_value != NULL) && (response->parameter_name != NULL))
|
||||
if (response->parameter_name != NULL)
|
||||
{
|
||||
json_object_object_add(root_node, response->parameter_name, json_object_new_string(response->parameter_value));
|
||||
json_object_object_add(root_node, response->parameter_name, json_object_new_int(response->parameter_value));
|
||||
}
|
||||
if (response->action != NULL)
|
||||
{
|
||||
@@ -202,7 +201,7 @@ int exec_request(const char *request, const char *path, int expected_code, const
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 2);
|
||||
|
||||
// Debug Only
|
||||
//curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
|
||||
// curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
|
||||
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
|
||||
Reference in New Issue
Block a user