WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
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/>.
* REST Utilities
*/
- /**
- * Check if namespace is in URL.
- *
- * @param url URL to check
- * @param namespace namespace to check against
- * @retun GNUNET_YES if namespace matches
- */
+/**
+ * Check if namespace is in URL.
+ *
+ * @param url URL to check
+ * @param namespace namespace to check against
+ * @retun GNUNET_YES if namespace matches
+ */
int
-GNUNET_REST_namespace_match (const char *url, const char *namespace)
+GNUNET_REST_namespace_match(const char *url, const char *namespace)
{
- return 0 == strncmp (namespace, url, strlen (namespace));
+ return 0 == strncmp(namespace, url, strlen(namespace));
}
/**
* @retun MHD response
*/
struct MHD_Response*
-GNUNET_REST_create_response (const char *data)
+GNUNET_REST_create_response(const char *data)
{
struct MHD_Response *resp;
size_t len;
if (NULL == data)
- {
- len = 0;
- data = "";
- }
+ {
+ len = 0;
+ data = "";
+ }
else
- len = strlen (data);
- resp = MHD_create_response_from_buffer (len,
- (void*)data,
- MHD_RESPMEM_MUST_COPY);
+ len = strlen(data);
+ resp = MHD_create_response_from_buffer(len,
+ (void*)data,
+ MHD_RESPMEM_MUST_COPY);
return resp;
-
}
int
-GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
- const struct GNUNET_REST_RequestHandler *handlers,
- struct GNUNET_REST_RequestHandlerError *err,
- void *cls)
+GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn,
+ const struct GNUNET_REST_RequestHandler *handlers,
+ struct GNUNET_REST_RequestHandlerError *err,
+ void *cls)
{
int count;
int i;
while (NULL != handlers[count].method)
count++;
- GNUNET_asprintf (&url, "%s", conn->url);
- if (url[strlen (url)-1] == '/')
- url[strlen (url)-1] = '\0';
+ GNUNET_asprintf(&url, "%s", conn->url);
+ if (url[strlen(url) - 1] == '/')
+ url[strlen(url) - 1] = '\0';
for (i = 0; i < count; i++)
- {
- if (0 != strcasecmp (conn->method, handlers[i].method))
- continue;
- if (strlen (url) < strlen (handlers[i].namespace))
- continue;
- if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
- continue;
- //Match
- handlers[i].proc (conn, (const char*)url, cls);
- GNUNET_free (url);
- return GNUNET_YES;
- }
- GNUNET_free (url);
+ {
+ if (0 != strcasecmp(conn->method, handlers[i].method))
+ continue;
+ if (strlen(url) < strlen(handlers[i].namespace))
+ continue;
+ if (GNUNET_NO == GNUNET_REST_namespace_match(url, handlers[i].namespace))
+ continue;
+ //Match
+ handlers[i].proc(conn, (const char*)url, cls);
+ GNUNET_free(url);
+ return GNUNET_YES;
+ }
+ GNUNET_free(url);
err->error_code = MHD_HTTP_BAD_REQUEST;
return GNUNET_NO;
}