Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move REST API common code to rest_api.cpp/h (#7674)
- Loading branch information
Showing
14 changed files
with
199 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include <math.h> | ||
#include "de_web_plugin.h" | ||
#include "de_web_plugin_private.h" | ||
#include "device.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*/ | ||
|
||
#include <QString> | ||
#include <math.h> | ||
#include "de_web_plugin.h" | ||
#include "de_web_plugin_private.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024 dresden elektronik ingenieurtechnik gmbh. | ||
* All rights reserved. | ||
* | ||
* The software in this package is published under the terms of the BSD | ||
* style license a copy of which has been included with this distribution in | ||
* the LICENSE.txt file. | ||
* | ||
*/ | ||
|
||
#include <deconz/dbg_trace.h> | ||
#include "rest_api.h" | ||
|
||
const char *HttpStatusOk = "200 OK"; // OK | ||
const char *HttpStatusAccepted = "202 Accepted"; // Accepted but not complete | ||
const char *HttpStatusNotModified = "304 Not Modified"; // For ETag / If-None-Match | ||
const char *HttpStatusBadRequest = "400 Bad Request"; // Malformed request | ||
const char *HttpStatusUnauthorized = "401 Unauthorized"; // Unauthorized | ||
const char *HttpStatusForbidden = "403 Forbidden"; // Understand request but no permission | ||
const char *HttpStatusNotFound = "404 Not Found"; // Requested uri not found | ||
const char *HttpStatusServiceUnavailable = "503 Service Unavailable"; | ||
const char *HttpStatusNotImplemented = "501 Not Implemented"; | ||
const char *HttpContentHtml = "text/html; charset=utf-8"; | ||
const char *HttpContentCss = "text/css"; | ||
const char *HttpContentJson = "application/json; charset=utf-8"; | ||
const char *HttpContentJS = "text/javascript"; | ||
const char *HttpContentPNG = "image/png"; | ||
const char *HttpContentJPG = "image/jpg"; | ||
const char *HttpContentSVG = "image/svg+xml"; | ||
|
||
/*! Creates a error map used in JSON response. | ||
\param id - error id | ||
\param ressource example: "/lights/2" | ||
\param description example: "resource, /lights/2, not available" | ||
\return the map | ||
*/ | ||
QVariantMap errorToMap(int id, const QString &ressource, const QString &description) | ||
{ | ||
QVariantMap map; | ||
QVariantMap error; | ||
error["type"] = (double)id; | ||
error["address"] = ressource.toHtmlEscaped(); | ||
error["description"] = description.toHtmlEscaped(); | ||
map["error"] = error; | ||
|
||
DBG_Printf(DBG_INFO_L2, "API error %d, %s, %s\n", id, qPrintable(ressource), qPrintable(description)); | ||
|
||
return map; | ||
} |
Oops, something went wrong.