update rest handler to support id parameter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -144,6 +144,31 @@ static const char *file_mime_lookup(const char *path)
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
static bool contain(const char *src, const char *dest, int len)
|
||||
{
|
||||
int len_src, len_dest;
|
||||
int i = 0;
|
||||
|
||||
len_src = strlen(src);
|
||||
if (len_src < len)
|
||||
return false;
|
||||
|
||||
len_dest = strlen(dest);
|
||||
if (len_dest < len)
|
||||
return false;
|
||||
|
||||
while (i < len)
|
||||
{
|
||||
if (src[i] != dest[i])
|
||||
return false;
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn restd_rest_handler
|
||||
*
|
||||
@@ -166,10 +191,6 @@ int restd_rest_handler(short event, restd_conn_t *conn, void *userdata)
|
||||
{
|
||||
// DEBUG("call_hooks: method: %s - %s \n", hook->method, conn->method);
|
||||
// DEBUG("call_hooks: path: %s - %s\n", hook->path, http->request.path);
|
||||
if ((hook->path == NULL) || (http->request.path == NULL) || (strcmp(hook->path, http->request.path) != 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// DEBUG("HOOK FOUND !!!!\n");
|
||||
if ((hook->method == NULL) || (conn->method == NULL) || (strcmp(hook->method, conn->method) != 0))
|
||||
{
|
||||
@@ -178,7 +199,26 @@ int restd_rest_handler(short event, restd_conn_t *conn, void *userdata)
|
||||
break;
|
||||
}
|
||||
|
||||
return hook->cb(event, conn, hook->userdata);
|
||||
if ((hook->path != NULL) && (http->request.path != NULL))
|
||||
{
|
||||
int i = 0;
|
||||
int pos = -1;
|
||||
while (hook->path[i])
|
||||
{
|
||||
if (hook->path[i] == ':')
|
||||
pos = i;
|
||||
i++;
|
||||
}
|
||||
if (pos != -1 && contain(hook->path, http->request.path, pos))
|
||||
{
|
||||
const char *buffer = &http->request.path[pos];
|
||||
// printf("buffer: <%s>\n", buffer);
|
||||
conn->id = atoi(buffer);
|
||||
return hook->cb(event, conn, hook->userdata);
|
||||
}
|
||||
else if (strcmp(hook->path, http->request.path) == 0)
|
||||
return hook->cb(event, conn, hook->userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
// No Hook Found check if it's a real file into document root.
|
||||
|
||||
Reference in New Issue
Block a user