summaryrefslogtreecommitdiff
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-04-22 14:58:53 +0000
committerDavid M. Lee <dlee@digium.com>2013-04-22 14:58:53 +0000
commit1c21b8575bfd70b98b1102fd3dd09fc0bc335e14 (patch)
tree9a6ef6074e545ad2768bc1994e1a233fc1443729 /include/asterisk/strings.h
parent1871017cc6bd2e2ce7c638eeb6813e982377a521 (diff)
This patch adds a RESTful HTTP interface to Asterisk.
The API itself is documented using Swagger, a lightweight mechanism for documenting RESTful API's using JSON. This allows us to use swagger-ui to provide executable documentation for the API, generate client bindings in different languages, and generate a lot of the boilerplate code for implementing the RESTful bindings. The API docs live in the rest-api/ directory. The RESTful bindings are generated from the Swagger API docs using a set of Mustache templates. The code generator is written in Python, and uses Pystache. Pystache has no dependencies, and be installed easily using pip. Code generation code lives in rest-api-templates/. The generated code reduces a lot of boilerplate when it comes to handling HTTP requests. It also helps us have greater consistency in the REST API. (closes issue ASTERISK-20891) Review: https://reviewboard.asterisk.org/r/2376/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386232 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index d16e9f7bd..967eb82a0 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -82,6 +82,48 @@ static force_inline int attribute_pure ast_strlen_zero(const char *s)
*/
#define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
+/*
+ \brief Checks whether a string begins with another.
+ \since 12.0.0
+ \param str String to check.
+ \param prefix Prefix to look for.
+ \param 1 if \a str begins with \a prefix, 0 otherwise.
+ */
+static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
+{
+ ast_assert(str != NULL);
+ ast_assert(prefix != NULL);
+ while (*str == *prefix && *prefix != '\0') {
+ ++str;
+ ++prefix;
+ }
+ return *prefix == '\0';
+}
+
+/*
+ \brief Checks whether a string ends with another.
+ \since 12.0.0
+ \param str String to check.
+ \param suffix Suffix to look for.
+ \param 1 if \a str ends with \a suffix, 0 otherwise.
+ */
+static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
+{
+ size_t str_len;
+ size_t suffix_len;
+
+ ast_assert(str != NULL);
+ ast_assert(suffix != NULL);
+ str_len = strlen(str);
+ suffix_len = strlen(suffix);
+
+ if (suffix_len > str_len) {
+ return 0;
+ }
+
+ return strcmp(str + str_len - suffix_len, suffix) == 0;
+}
+
/*!
* \brief return Yes or No depending on the argument.
*