diff --git a/plugins/restful/group_config_handle.c b/plugins/restful/group_config_handle.c index 2b8a7ed7..4b0a9bb4 100644 --- a/plugins/restful/group_config_handle.c +++ b/plugins/restful/group_config_handle.c @@ -265,6 +265,47 @@ void handle_grp_unsubscribe(nng_aio *aio) }) } +static inline int send_subscribe_groups(nng_aio * aio, + neu_json_subscribe_groups_req_t *req) +{ + neu_plugin_t *plugin = neu_rest_get_plugin(); + + neu_reqresp_head_t header = { + .ctx = aio, + .type = NEU_REQ_SUBSCRIBE_GROUPS, + }; + + neu_req_subscribe_groups_t cmd = { + .app = req->app, + .n_group = req->n_group, + .groups = (neu_req_subscribe_group_info_t *) req->groups, + }; + + if (0 != neu_plugin_op(plugin, header, &cmd)) { + return NEU_ERR_IS_BUSY; + } + + // ownership moved + req->app = NULL; + req->n_group = 0; + req->groups = NULL; + + return 0; +} + +void handle_grp_subscribes(nng_aio *aio) +{ + NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( + aio, neu_json_subscribe_groups_req_t, + neu_json_decode_subscribe_groups_req, { + int ret = send_subscribe_groups(aio, req); + if (0 != ret) { + NEU_JSON_RESPONSE_ERROR( + ret, { neu_http_response(aio, ret, result_error); }); + } + }) +} + void handle_grp_get_subscribe(nng_aio *aio) { int ret = 0; diff --git a/plugins/restful/group_config_handle.h b/plugins/restful/group_config_handle.h index b9a62c68..040aba1f 100644 --- a/plugins/restful/group_config_handle.h +++ b/plugins/restful/group_config_handle.h @@ -34,6 +34,7 @@ void handle_get_driver_group_resp(nng_aio * aio, void handle_grp_subscribe(nng_aio *aio); void handle_grp_update_subscribe(nng_aio *aio); void handle_grp_unsubscribe(nng_aio *aio); +void handle_grp_subscribes(nng_aio *aio); void handle_grp_get_subscribe(nng_aio *aio); void handle_grp_get_subscribe_resp(nng_aio * aio, neu_resp_get_subscribe_group_t *groups); diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index 0c8a20a9..c538c4ec 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -80,6 +80,9 @@ static struct neu_http_handler cors_handler[] = { { .url = "/api/v2/subscribe", }, + { + .url = "/api/v2/subscribes", + }, { .url = "/api/v2/schema", }, @@ -304,6 +307,12 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/subscribe", .value.handler = handle_grp_get_subscribe, }, + { + .method = NEU_HTTP_METHOD_POST, + .type = NEU_HTTP_HANDLER_FUNCTION, + .url = "/api/v2/subscribes", + .value.handler = handle_grp_subscribes, + }, { .method = NEU_HTTP_METHOD_GET, .type = NEU_HTTP_HANDLER_FUNCTION,