diff options
Diffstat (limited to 'main/http.c')
-rw-r--r-- | main/http.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/main/http.c b/main/http.c index 1c4a9ca60..cc32b9422 100644 --- a/main/http.c +++ b/main/http.c @@ -57,12 +57,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define MAX_PREFIX 80 #define DEFAULT_PORT 8088 #define DEFAULT_TLS_PORT 8089 +#define DEFAULT_SESSION_LIMIT 100 /* See http.h for more information about the SSL implementation */ #if defined(HAVE_OPENSSL) && (defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE)) #define DO_SSL /* comment in/out if you want to support ssl */ #endif +static int session_limit = DEFAULT_SESSION_LIMIT; +static int session_count = 0; + static struct ast_tls_config http_tls_cfg; static void *httpd_helper_thread(void *arg); @@ -829,6 +833,10 @@ static void *httpd_helper_thread(void *data) char *uri, *method; enum ast_http_method http_method = AST_HTTP_UNKNOWN; + if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) { + goto done; + } + if (!fgets(buf, sizeof(buf), ser->f)) { goto done; } @@ -894,17 +902,19 @@ static void *httpd_helper_thread(void *data) if (!*uri) { ast_http_error(ser, 400, "Bad Request", "Invalid Request"); - return NULL; + goto done; } handle_uri(ser, uri, http_method, headers); - /* Clean up all the header information pulled as well */ +done: + ast_atomic_fetchadd_int(&session_count, -1); + + /* clean up all the header information */ if (headers) { ast_variables_destroy(headers); } -done: if (ser->f) { fclose(ser->f); } @@ -1044,6 +1054,12 @@ static int __ast_http_load(int reload) } } else if (!strcasecmp(v->name, "redirect")) { add_redirect(v->value); + } else if (!strcasecmp(v->name, "sessionlimit")) { + if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE, + &session_limit, DEFAULT_SESSION_LIMIT, 1, INT_MAX)) { + ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of http.conf\n", + v->name, v->value, v->lineno); + } } else { ast_log(LOG_WARNING, "Ignoring unknown option '%s' in http.conf\n", v->name); } |