X-Git-Url: http://git.asterisk.org/gitweb/?p=asterisk%2Fasterisk.git;a=blobdiff_plain;f=http.c;h=cdcde76a882b0089bca6830ecc918b47ef208d74;hp=c840464f654dd655e6295c27f5c6ee2c2f4f2694;hb=e85d63aa1166efddf1681434086f665cb31b3a1d;hpb=eaeb8abc59db5f87f5866b87833cfc6260303f3a diff --git a/http.c b/http.c index c840464..cdcde76 100644 --- a/http.c +++ b/http.c @@ -16,6 +16,14 @@ * at the top of the source tree. */ +/*! + * \file + * \brief http server + * + * This program implements a tiny http server supporting the "get" method + * only and was inspired by micro-httpd by Jef Poskanzer + */ + #include #include #include @@ -30,17 +38,15 @@ #include #include #include -#include -#include -#include -#include + +#include "asterisk/cli.h" +#include "asterisk/http.h" +#include "asterisk/utils.h" +#include "asterisk/strings.h" #define MAX_PREFIX 80 #define DEFAULT_PREFIX "asterisk" -/* This program implements a tiny http server supporting the "get" method - only and was inspired by micro-httpd by Jef Poskanzer */ - struct ast_http_server_instance { FILE *f; int fd; @@ -291,23 +297,21 @@ static void *http_root(void *data) ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno)); continue; } - ser = calloc(1, sizeof(*ser)); - if (ser) { - ser->fd = fd; - if ((ser->f = fdopen(ser->fd, "w+"))) { - if (ast_pthread_create(&launched, NULL, ast_httpd_helper_thread, ser)) { - ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno)); - fclose(ser->f); - free(ser); - } - } else { - ast_log(LOG_WARNING, "fdopen failed!\n"); - close(ser->fd); + if (!(ser = ast_calloc(1, sizeof(*ser)))) { + close(fd); + continue; + } + ser->fd = fd; + if ((ser->f = fdopen(ser->fd, "w+"))) { + if (ast_pthread_create(&launched, NULL, ast_httpd_helper_thread, ser)) { + ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno)); + fclose(ser->f); free(ser); } } else { - ast_log(LOG_WARNING, "Out of memory!\n"); - close(fd); + ast_log(LOG_WARNING, "fdopen failed!\n"); + close(ser->fd); + free(ser); } } return NULL;