mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-08 22:27:07 +00:00
res_ari: Add http prefix to generated docs
updated the uri handler to include the url prefix of the http server
this enables res_ari to add it to the uris when generating docs
Change-Id: I279335a2625261a8492206c37219698f42591c2e
(cherry picked from commit 6f448f32fe
)
This commit is contained in:
committed by
Joshua Colp
parent
2b057d6215
commit
c1b6a79686
@@ -146,10 +146,11 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
|
|||||||
* for unit testing.
|
* for unit testing.
|
||||||
*
|
*
|
||||||
* \param uri Requested URI, relative to the docs path.
|
* \param uri Requested URI, relative to the docs path.
|
||||||
|
* \param prefix prefix that prefixes all http requests
|
||||||
* \param headers HTTP headers.
|
* \param headers HTTP headers.
|
||||||
* \param[out] response RESTful HTTP response.
|
* \param[out] response RESTful HTTP response.
|
||||||
*/
|
*/
|
||||||
void ast_ari_get_docs(const char *uri, struct ast_variable *headers, struct ast_ari_response *response);
|
void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers, struct ast_ari_response *response);
|
||||||
|
|
||||||
/*! \brief Abstraction for reading/writing JSON to a WebSocket */
|
/*! \brief Abstraction for reading/writing JSON to a WebSocket */
|
||||||
struct ast_ari_websocket_session;
|
struct ast_ari_websocket_session;
|
||||||
|
@@ -101,6 +101,7 @@ struct ast_http_uri {
|
|||||||
AST_LIST_ENTRY(ast_http_uri) entry;
|
AST_LIST_ENTRY(ast_http_uri) entry;
|
||||||
const char *description;
|
const char *description;
|
||||||
const char *uri;
|
const char *uri;
|
||||||
|
const char *prefix;
|
||||||
ast_http_callback callback;
|
ast_http_callback callback;
|
||||||
unsigned int has_subtree:1;
|
unsigned int has_subtree:1;
|
||||||
/*! Structure is malloc'd */
|
/*! Structure is malloc'd */
|
||||||
|
@@ -671,6 +671,8 @@ int ast_http_uri_link(struct ast_http_uri *urih)
|
|||||||
|
|
||||||
AST_RWLIST_WRLOCK(&uris);
|
AST_RWLIST_WRLOCK(&uris);
|
||||||
|
|
||||||
|
urih->prefix = prefix;
|
||||||
|
|
||||||
if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
|
if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
|
||||||
AST_RWLIST_INSERT_HEAD(&uris, urih, entry);
|
AST_RWLIST_INSERT_HEAD(&uris, urih, entry);
|
||||||
AST_RWLIST_UNLOCK(&uris);
|
AST_RWLIST_UNLOCK(&uris);
|
||||||
|
@@ -579,7 +579,7 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_ari_get_docs(const char *uri, struct ast_variable *headers,
|
void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers,
|
||||||
struct ast_ari_response *response)
|
struct ast_ari_response *response)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ast_str *, absolute_path_builder, NULL, ast_free);
|
RAII_VAR(struct ast_str *, absolute_path_builder, NULL, ast_free);
|
||||||
@@ -685,9 +685,15 @@ void ast_ari_get_docs(const char *uri, struct ast_variable *headers,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (host != NULL) {
|
if (host != NULL) {
|
||||||
ast_json_object_set(
|
if (prefix != NULL && strlen(prefix) > 0) {
|
||||||
obj, "basePath",
|
ast_json_object_set(
|
||||||
ast_json_stringf("http://%s/ari", host->value));
|
obj, "basePath",
|
||||||
|
ast_json_stringf("http://%s%s/ari", host->value,prefix));
|
||||||
|
} else {
|
||||||
|
ast_json_object_set(
|
||||||
|
obj, "basePath",
|
||||||
|
ast_json_stringf("http://%s/ari", host->value));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Without the host, we don't have the basePath */
|
/* Without the host, we don't have the basePath */
|
||||||
ast_json_object_del(obj, "basePath");
|
ast_json_object_del(obj, "basePath");
|
||||||
@@ -969,7 +975,7 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
|
|||||||
ast_ari_response_error(&response, 405, "Method Not Allowed", "Unsupported method");
|
ast_ari_response_error(&response, 405, "Method Not Allowed", "Unsupported method");
|
||||||
} else {
|
} else {
|
||||||
/* Skip the api-docs prefix */
|
/* Skip the api-docs prefix */
|
||||||
ast_ari_get_docs(strchr(uri, '/') + 1, headers, &response);
|
ast_ari_get_docs(strchr(uri, '/') + 1, urih->prefix, headers, &response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Other RESTful resources */
|
/* Other RESTful resources */
|
||||||
|
@@ -218,7 +218,7 @@ AST_TEST_DEFINE(get_docs)
|
|||||||
|
|
||||||
response = response_alloc();
|
response = response_alloc();
|
||||||
headers = ast_variable_new("Host", "stasis.asterisk.org", __FILE__);
|
headers = ast_variable_new("Host", "stasis.asterisk.org", __FILE__);
|
||||||
ast_ari_get_docs("resources.json", headers, response);
|
ast_ari_get_docs("resources.json", "", headers, response);
|
||||||
ast_test_validate(test, 200 == response->response_code);
|
ast_test_validate(test, 200 == response->response_code);
|
||||||
|
|
||||||
/* basePath should be relative to the Host header */
|
/* basePath should be relative to the Host header */
|
||||||
@@ -248,7 +248,7 @@ AST_TEST_DEFINE(get_docs_nohost)
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = response_alloc();
|
response = response_alloc();
|
||||||
ast_ari_get_docs("resources.json", headers, response);
|
ast_ari_get_docs("resources.json", "", headers, response);
|
||||||
ast_test_validate(test, 200 == response->response_code);
|
ast_test_validate(test, 200 == response->response_code);
|
||||||
|
|
||||||
/* basePath should be relative to the Host header */
|
/* basePath should be relative to the Host header */
|
||||||
@@ -275,7 +275,7 @@ AST_TEST_DEFINE(get_docs_notfound)
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = response_alloc();
|
response = response_alloc();
|
||||||
ast_ari_get_docs("i-am-not-a-resource.json", headers, response);
|
ast_ari_get_docs("i-am-not-a-resource.json", "", headers, response);
|
||||||
ast_test_validate(test, 404 == response->response_code);
|
ast_test_validate(test, 404 == response->response_code);
|
||||||
|
|
||||||
return AST_TEST_PASS;
|
return AST_TEST_PASS;
|
||||||
@@ -298,7 +298,7 @@ AST_TEST_DEFINE(get_docs_hackerz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = response_alloc();
|
response = response_alloc();
|
||||||
ast_ari_get_docs("../../../../sbin/asterisk", headers, response);
|
ast_ari_get_docs("../../../../sbin/asterisk", "", headers, response);
|
||||||
ast_test_validate(test, 404 == response->response_code);
|
ast_test_validate(test, 404 == response->response_code);
|
||||||
|
|
||||||
return AST_TEST_PASS;
|
return AST_TEST_PASS;
|
||||||
|
Reference in New Issue
Block a user