reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RestAdmin.hxx
Go to the documentation of this file.
1#if !defined(RESIP_RESTADMIN_HXX)
2#define RESIP_RESTADMIN_HXX
3
4#include "rutil/Data.hxx"
5
6#include <map>
7#include <vector>
8
9namespace resip
10{
11class DataStream;
12}
13
14namespace repro
15{
16class WebAdmin;
17
18// RestAdmin provides a simple JSON/REST interface to repro, living alongside
19// the existing HTML WebAdmin on the same HTTP listener. It does not inherit
20// from HttpBase; instead it is owned by WebAdmin, which intercepts URIs with
21// the /api/v1/ prefix and delegates to RestAdmin::dispatch.
22//
23// Authentication is performed by WebAdmin before dispatch is called; the
24// authenticated user (empty if challenges are disabled) is passed through.
25//
26// Because we do not parse HTTP request bodies, all mutating endpoints take
27// their parameters in the query string.
28//
29// Supported endpoints (see implementation for details):
30//
31// GET /api/v1/registrations
32// GET /api/v1/publications
33// GET /api/v1/domains
34// POST /api/v1/domains?uri=...&tlsPort=...
35// DELETE /api/v1/domains/{uri}
36// GET /api/v1/users
37// POST /api/v1/users?user=...&domain=...&password=...&name=...&email=...
38// GET /api/v1/users/{user@domain}
39// PUT /api/v1/users/{user@domain}?user=...&domain=...&password=...&name=...&email=...
40// (user and domain may be changed, but password is required if either changes)
41// DELETE /api/v1/users/{user@domain}
42// GET /api/v1/acls
43// POST /api/v1/acls?hostOrIp=...&port=...&transport=...
44// DELETE /api/v1/acls/{key}
45// GET /api/v1/routes
46// POST /api/v1/routes?uri=...&destination=...&method=...&event=...&order=...
47// PUT /api/v1/routes/{key}?uri=...&destination=...&method=...&event=...&order=...
48// DELETE /api/v1/routes/{key}
49// GET /api/v1/filters
50// GET /api/v1/settings
51// GET /api/v1/stackinfo
52// GET /api/v1/stats
53// POST /api/v1/stats/reset
54// GET /api/v1/congestion
55// GET /api/v1/loglevel
56// PUT /api/v1/loglevel?level=...
57// GET /api/v1/dnscache
58// DELETE /api/v1/dnscache
59// POST /api/v1/dnscache/reload
60// POST /api/v1/restart
61// POST /api/v1/certs/reload
63{
64public:
65 explicit RestAdmin(WebAdmin& webAdmin);
66 ~RestAdmin();
67
68 // Main entrypoint. Called by WebAdmin after authentication succeeds.
69 // method is the HTTP verb (e.g. "GET"); uri is the full request URI
70 // (path + optional query string). pageNumber identifies the pending
71 // HTTP connection to reply on. authenticatedUser is the username that
72 // authenticated, or empty if challenges were disabled.
73 void dispatch(const resip::Data& method,
74 const resip::Data& uri,
75 int pageNumber,
77
78private:
79 typedef std::map<resip::Data, resip::Data> ParamMap;
80
81 // Split the URI into its path segments (after /api/v1/) and a map of
82 // query parameters. Path segments are URL-decoded; query values are
83 // URL-decoded.
84 void parseRequest(const resip::Data& uri,
85 std::vector<resip::Data>& pathSegments,
86 ParamMap& queryParams) const;
87
88 // Response helpers
89 void sendJson(int pageNumber, int statusCode, const resip::Data& json);
90 void sendOk(int pageNumber);
91 void sendError(int pageNumber, int statusCode, const resip::Data& message);
92 void sendMethodNotAllowed(int pageNumber, const resip::Data& method);
93 void sendNotFound(int pageNumber);
94
95 // Resource handlers
96 void handleRegistrations(const resip::Data& method,
97 const std::vector<resip::Data>& path,
98 const ParamMap& query,
99 int pageNumber);
100 void handlePublications(const resip::Data& method,
101 const std::vector<resip::Data>& path,
102 const ParamMap& query,
103 int pageNumber);
104 void handleDomains(const resip::Data& method,
105 const std::vector<resip::Data>& path,
106 const ParamMap& query,
107 int pageNumber);
108 void handleUsers(const resip::Data& method,
109 const std::vector<resip::Data>& path,
110 const ParamMap& query,
111 int pageNumber);
112 void handleAcls(const resip::Data& method,
113 const std::vector<resip::Data>& path,
114 const ParamMap& query,
115 int pageNumber);
116 void handleRoutes(const resip::Data& method,
117 const std::vector<resip::Data>& path,
118 const ParamMap& query,
119 int pageNumber);
120 void handleFilters(const resip::Data& method,
121 const std::vector<resip::Data>& path,
122 const ParamMap& query,
123 int pageNumber);
124 void handleSettings(const resip::Data& method, int pageNumber);
125 void handleStackInfo(const resip::Data& method, int pageNumber);
126 void handleStats(const resip::Data& method,
127 const std::vector<resip::Data>& path,
128 int pageNumber);
129 void handleCongestion(const resip::Data& method, int pageNumber);
130 void handleLogLevel(const resip::Data& method,
131 const ParamMap& query,
132 int pageNumber);
133 void handleDnsCache(const resip::Data& method,
134 const std::vector<resip::Data>& path,
135 int pageNumber);
136 void handleRestart(const resip::Data& method, int pageNumber);
137 void handleCertsReload(const resip::Data& method, int pageNumber);
138
139 // Utility: look up a query param, return defaultValue if not present
140 static resip::Data param(const ParamMap& q,
141 const resip::Data& key,
143 static bool hasParam(const ParamMap& q, const resip::Data& key);
144
145 // Access to WebAdmin internals (registration/publication dbs, store, proxy,
146 // DNS cache machinery) via the friend relationship declared in WebAdmin.
147 WebAdmin& mWebAdmin;
148};
149
150}
151
152#endif
153
154
155/* ====================================================================
156
157 Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
158 All rights reserved.
159
160 Redistribution and use in source and binary forms, with or without
161 modification, are permitted provided that the following conditions are
162 met:
163
164 1. Redistributions of source code must retain the above copyright
165 notice, this list of conditions and the following disclaimer.
166
167 2. Redistributions in binary form must reproduce the above copyright
168 notice, this list of conditions and the following disclaimer in the
169 documentation and/or other materials provided with the distribution.
170
171 3. Neither the name of Plantronics nor the names of its contributors
172 may be used to endorse or promote products derived from this
173 software without specific prior written permission.
174
175 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
177 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
178 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
179 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
180 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
181 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
182 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
183 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
184 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
185 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186
187 ==================================================================== */
void dispatch(const resip::Data &method, const resip::Data &uri, int pageNumber, const resip::Data &authenticatedUser)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66