diff options
author | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-12-16 09:33:31 +0000 |
---|---|---|
committer | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-12-16 09:33:31 +0000 |
commit | 9ad774382a855bfefee91202a227abf3c5794ab1 (patch) | |
tree | 27d106a85ab51a1a3fce3af1cf043e890d86ca07 /include/asterisk | |
parent | 79a60fb12410e12dc9bb3cd78972cc47149f197d (diff) |
replace ast_build_string() with ast_str_*() functions.
This makes the code easier to follow and saves some
copies to intermediate buffers.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@48515 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/http.h | 8 | ||||
-rw-r--r-- | include/asterisk/strings.h | 21 |
2 files changed, 24 insertions, 5 deletions
diff --git a/include/asterisk/http.h b/include/asterisk/http.h index bfd39c039..c3e2ba0fa 100644 --- a/include/asterisk/http.h +++ b/include/asterisk/http.h @@ -144,7 +144,7 @@ int ssl_setup(struct tls_config *cfg); The return value may include additional headers at the front and MUST include a blank line with \r\n to provide separation between user headers and content (even if no content is specified) */ -typedef char *(*ast_http_callback)(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength); +typedef struct ast_str *(*ast_http_callback)(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength); struct ast_http_uri { struct ast_http_uri *next; @@ -157,14 +157,12 @@ struct ast_http_uri { /*! \brief Link into the Asterisk HTTP server */ int ast_http_uri_link(struct ast_http_uri *urihandler); -/*! \brief Return a malloc()'d string containing an HTTP error message */ -char *ast_http_error(int status, const char *title, const char *extra_header, const char *text); +/*! \brief Return an ast_str malloc()'d string containing an HTTP error message */ +struct ast_str *ast_http_error(int status, const char *title, const char *extra_header, const char *text); /*! \brief Destroy an HTTP server */ void ast_http_uri_unlink(struct ast_http_uri *urihandler); -char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, size_t buflen); - int ast_http_init(void); int ast_http_reload(void); diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 7bfd385a4..832a964ca 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -336,6 +336,27 @@ struct ast_str * attribute_malloc ast_str_create(size_t init_len), } ) +/*! + * Make space in a new string (e.g. to read in data from a file) + */ +AST_INLINE_API( +int ast_str_make_space(struct ast_str **buf, size_t new_len), +{ + if (new_len <= (*buf)->len) + return 0; /* success */ + if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) + return -1; /* cannot extend */ + *buf = ast_realloc(*buf, new_len + sizeof(struct ast_str)); + if (*buf == NULL) /* XXX watch out, we leak memory here */ + return -1; + if ((*buf)->ts != DS_MALLOC) + pthread_setspecific((*buf)->ts->key, *buf); + + (*buf)->len = new_len; + return 0; +} +) + #define ast_str_alloca(init_len) \ ({ \ struct ast_str *buf; \ |