diff --git a/bsp/buildroot_external/package/uhttpd-rest-api-plugin/Config.in b/bsp/buildroot_external/package/uhttpd-rest-api-plugin/Config.in new file mode 100644 index 00000000..ff9523a3 --- /dev/null +++ b/bsp/buildroot_external/package/uhttpd-rest-api-plugin/Config.in @@ -0,0 +1,10 @@ +menuconfig BR2_PACKAGE_UHTTPD_REST_API_PLUGIN + bool "uhttpd rest api plugin" + select BR2_PACKAGE_UHTTPD_3P + select BR2_PACKAGE_UBUS + select BR2_PACKAGE_JSON_C + select BR2_PACKAGE_LIBFMT + select BR2_PACKAGE_LIBUBUS_CPP + default n + help + Enable the rest api uhttpd plugin. diff --git a/bsp/buildroot_external/package/uhttpd-rest-api-plugin/uhttpd-rest-api-plugin.mk b/bsp/buildroot_external/package/uhttpd-rest-api-plugin/uhttpd-rest-api-plugin.mk new file mode 100644 index 00000000..8437aabb --- /dev/null +++ b/bsp/buildroot_external/package/uhttpd-rest-api-plugin/uhttpd-rest-api-plugin.mk @@ -0,0 +1,19 @@ +################################################################################ +# +# UHTTPD REST API PLUGIN +# +################################################################################ + +UHTTPD_REST_API_PLUGIN_VERSION:= 1.0.0 + +UHTTPD_REST_API_PLUGIN_SITE = $(TOPDIR)/../../src/plugins/uhttpd/uhttpd-rest-api/builders/cmake + +UHTTPD_REST_API_PLUGIN_SITE_METHOD = local +UHTTPD_REST_API_PLUGIN_INSTALL_TARGET = YES +UHTTPD_REST_API_PLUGIN_INSTALL_STAGING = YES + +UHTTPD_REST_API_PLUGIN_DEPENDENCIES = uhttpd-3p ubus json-c libfmt libubus-cpp + +UHTTPD_REST_API_PLUGIN_CONF_OPTS += -DworkspaceRoot=$(TOPDIR)/../.. -DMODULE_PATH=$(TOPDIR)/../../bsp/cmake-modules -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) + +$(eval $(cmake-package)) diff --git a/src/plugins/uhttpd/uhttpd-rest-api/builders/cmake/CMakeLists.txt b/src/plugins/uhttpd/uhttpd-rest-api/builders/cmake/CMakeLists.txt index 728e2055..3740da4a 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/builders/cmake/CMakeLists.txt +++ b/src/plugins/uhttpd/uhttpd-rest-api/builders/cmake/CMakeLists.txt @@ -1,85 +1,56 @@ cmake_minimum_required (VERSION 3.0) -project (uhttpd-awox-api-plugin) +project (uhttpd-rest-api-plugin) set (CMAKE_MODULE_PATH "${MODULE_PATH}") set (CMAKE_CXX_STANDARD 11) -include (aw) +include (br) -include_directories ($ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/) +include_directories (${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/) file ( GLOB_RECURSE source_files - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/plugin.c - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/uhttp-server.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/plugin.c + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp # core - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-reason.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-parameter.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-header.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/uri-transform.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/web-controller.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/web-connection.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/ubus-connection.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/ubus-reason.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-reason.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-parameter.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-header.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/uri-transform.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-connection.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp # rest - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/rest/rest-controller.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/rest/rest-connection.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp #etag-rest - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/etag-rest/etag-rest-controller.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/etag-rest/etag-rest-connection.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-controller.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp # notification - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/notification/notification-controller.cpp - $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/notification/notification-connection.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-controller.cpp + ${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp ) -add_library (awox-api-plugin SHARED ${source_files}) +add_library (rest-api-plugin SHARED ${source_files}) -target_link_libraries (awox-api-plugin +target_link_libraries (rest-api-plugin LINK_PUBLIC ubus ubox blobmsg_json json-c fmt - aw-ubus + ubus-cpp ) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") -set_target_properties (awox-api-plugin PROPERTIES PREFIX "uhttpd_") +set_target_properties (rest-api-plugin PROPERTIES PREFIX "uhttpd_") -target_include_directories (awox-api-plugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -install (TARGETS awox-api-plugin LIBRARY DESTINATION local/bin/Plugins/) - -if (INSTALL_CORE) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/core.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_SPOTIFY) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/spotify.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_DEAP) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/deap.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_LIGHT) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_LIGHT_COLOR) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light-color.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_LIGHT_WHITE) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light-white.json DESTINATION local/configs/restd/) -endif () - -if (INSTALL_VOICE_CONTROL) - install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/voice-control.json DESTINATION local/configs/restd/) -endif () +target_include_directories (rest-api-plugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +install (TARGETS rest-api-plugin LIBRARY DESTINATION local/bin/plugins/) diff --git a/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp b/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp index 400b5ca2..2140a312 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp @@ -22,7 +22,11 @@ /*------------------------------- INCLUDES ----------------------------------*/ -#include +extern "C" { +#include +} + +#include #include "ubus-reason.h" diff --git a/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.h b/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.h index ec04aee9..fd4bb6b5 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.h @@ -33,6 +33,13 @@ struct client; struct uhttpd_ops; struct ubus_context; +/*----------------------------- Dependencies --------------------------------*/ + +#define kEvent_status_entry "status" +#define kEvent_version_entry "version" +#define kEvent_content_entry "content" + + /*--------------------------------- CLASS ----------------------------------*/ class WebConnection { diff --git a/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp b/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp index 8996275a..b2abe9c6 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp @@ -26,9 +26,9 @@ #include -#include +#include -#include +//#include #include "etag-rest/etag-rest-controller.h" @@ -90,7 +90,7 @@ EtagRestConnection::~EtagRestConnection (void) void EtagRestConnection::invoke (struct ubus_context *a_ctx) { uint32_t the_id = 0; - awUBusCall the_cmd; + UBusCall the_cmd; std::string the_method; m_ctx = a_ctx; @@ -103,7 +103,7 @@ void EtagRestConnection::invoke (struct ubus_context *a_ctx) if (!ubus_lookup_id(a_ctx, m_controller->get_path().c_str(), &the_id)) { // printf ("%s launch async call (%s)(%s)....\n", __PRETTY_FUNCTION__, the_method.c_str(), m_parameters.c_str()); - the_cmd.ExecAsync(a_ctx, the_id, the_method, m_parameters, this); + the_cmd.exec_async(a_ctx, the_id, the_method, m_parameters, this); } if (m_client->request.method == UH_HTTP_MSG_GET) { @@ -186,7 +186,7 @@ int EtagRestConnection::parse_parameter (void) the_content_node = json_tokener_parse(m_connection_data.c_str()); if (the_content_node != NULL) { - json_object_object_add(the_root_node, kEvent_Message_content_entry, the_content_node); + json_object_object_add(the_root_node, kEvent_content_entry, the_content_node); } m_parameters = json_object_to_json_string(the_root_node); @@ -223,13 +223,13 @@ void EtagRestConnection::manage_response (std::string a_response_data) } // get status - if (json_object_object_get_ex(the_root_node, kEvent_Message_status_entry, &the_status_node)) { + if (json_object_object_get_ex(the_root_node, kEvent_status_entry, &the_status_node)) { the_result_code = json_object_get_int(the_status_node); } // get etag. - if (json_object_object_get_ex(the_root_node, kEvent_Message_version_entry, &the_etag_node)) { + if (json_object_object_get_ex(the_root_node, kEvent_version_entry, &the_etag_node)) { enum json_type the_json_type; @@ -249,7 +249,7 @@ void EtagRestConnection::manage_response (std::string a_response_data) // get contents the_content_node = NULL; - if (!json_object_object_get_ex(the_root_node, kEvent_Message_content_entry, &the_content_node)) { + if (!json_object_object_get_ex(the_root_node, kEvent_content_entry, &the_content_node)) { the_content_node = the_root_node; } diff --git a/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.h b/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.h index 07ef87d0..a706e875 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.h @@ -27,23 +27,22 @@ #include -#include -#include -#include "aw-ubus/UBusEventReceiver.h" -#include +#include +#include +#include "ubus-cpp/ubus-event-receiver.h" +#include #include "core/http-header.h" #include "core/web-connection.h" -/*----------------------------- Dependencies --------------------------------*/ class EtagRestController; struct ubus_context; /*--------------------------------- CLASS ----------------------------------*/ -class EtagRestConnection : public WebConnection, public awUBusExecReceiver, public awUBusEventReceiver, public ULoopTimer { +class EtagRestConnection : public WebConnection, public UBusExecReceiver, public UBusEventReceiver, public ULoopTimer { public: EtagRestConnection (struct uhttpd_ops *an_ops, struct client *a_client, EtagRestController *a_controller, const std::string &a_parameters); diff --git a/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp b/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp index 97316703..454134cd 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp @@ -29,8 +29,6 @@ extern "C" { #include #include -#include - #include "core/http-reason.h" #include "notification/notification-controller.h" diff --git a/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.h b/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.h index 4cbbb5bb..62a5a7b1 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.h @@ -25,8 +25,9 @@ /*------------------------------- INCLUDES ----------------------------------*/ -#include -#include "aw-ubus/UBusEventReceiver.h" +#include +#include + #include "core/web-connection.h" /*----------------------------- Dependencies --------------------------------*/ @@ -36,7 +37,7 @@ struct ubus_context; /*--------------------------------- CLASS ----------------------------------*/ -class NotificationConnection : public WebConnection, public awUBusEventReceiver, public ULoopTimer { +class NotificationConnection : public WebConnection, public UBusEventReceiver, public ULoopTimer { public: NotificationConnection (struct uhttpd_ops *an_ops, struct client *a_client, NotificationController *a_controller); @@ -45,7 +46,7 @@ public: // WebConnection void invoke (struct ubus_context *a_ctx); - // awUBusEventReceiver + // UBusEventReceiver void handle_event (const char *a_type, const char *a_json_msg); // Timer. diff --git a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp index 833389a2..43689cd0 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp @@ -24,14 +24,14 @@ #include -#include +//#include extern "C" { #include #include } -#include +#include #include "core/http-reason.h" #include "core/http-parameter.h" @@ -97,7 +97,7 @@ void RestConnection::complete (void) void RestConnection::invoke (struct ubus_context *a_ctx) { uint32_t the_id = 0; - awUBusCall the_cmd; + UBusCall the_cmd; std::string the_method; m_ctx = a_ctx; @@ -114,7 +114,7 @@ void RestConnection::invoke (struct ubus_context *a_ctx) the_parameter_doc = parse_form_encoded_data(); // printf("RestConnection::invoke launch async call (%d)....\n", the_id); - the_cmd.ExecAsync(a_ctx, the_id, the_method, json_object_to_json_string(the_parameter_doc), this); + the_cmd.exec_async(a_ctx, the_id, the_method, json_object_to_json_string(the_parameter_doc), this); json_object_put(the_parameter_doc); } @@ -190,7 +190,7 @@ void RestConnection::send_response(int a_result_code, std::string a_content_docu } json_object_object_add(the_root_node, "id", json_object_new_string(m_controller->get_name().c_str())); - json_object_object_add(the_root_node, kEvent_Message_status_entry, json_object_new_string(the_status.c_str())); + json_object_object_add(the_root_node, kEvent_status_entry, json_object_new_string(the_status.c_str())); json_object_object_add(the_root_node, "response_code", json_object_new_int(a_result_code)); the_http_header.send(m_ops, m_client, a_result_code); diff --git a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.h b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.h index ee9991c7..7d4b7aad 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.h @@ -30,7 +30,7 @@ #include "core/web-connection.h" -#include +#include /*----------------------------- Dependencies --------------------------------*/ @@ -39,7 +39,7 @@ struct json_object; /*--------------------------------- CLASS ----------------------------------*/ -class RestConnection : public WebConnection, public awUBusExecReceiver { +class RestConnection : public WebConnection, public UBusExecReceiver { public: RestConnection (struct uhttpd_ops *an_ops, struct client *a_client, RestController *a_controller, const std::string &a_parameters);