aboutsummaryrefslogtreecommitdiffstats
path: root/main/http.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-06 16:17:57 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-06 16:17:57 +0000
commitdcd0e21c1ba2170fbf3bcbae5b70bd6609f037eb (patch)
tree0522c9624995d285e90c8ae150fceb1697fb5818 /main/http.c
parent6f847542b7f27741c95fbdf7aafb41ef34570254 (diff)
Make externally visible some generic code useful to create
and implement services over tcp and/or tcp-tls. This commit is nothing more than moving structure definitions (and documentation) from main/http.c to include/asterisk/http.h (temporary location until we find a better place), and removing the 'static' qualifier from server_root() and server_start(). The name change (adding the ast_ prefix as a minimum, and then possibly a more meaningful name) is postponed to future commits. Does not apply to other versions of asterisk. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@48324 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/http.c')
-rw-r--r--main/http.c69
1 files changed, 3 insertions, 66 deletions
diff --git a/main/http.c b/main/http.c
index 863c9fd18..ba0f5f5e2 100644
--- a/main/http.c
+++ b/main/http.c
@@ -85,11 +85,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#endif
#ifdef DO_SSL
-#include <openssl/ssl.h>
-#include <openssl/err.h>
static SSL_CTX* ssl_ctx;
-#else
-typedef struct {} SSL; /* so we can define a pointer to it */
#endif /* DO_SSL */
/* SSL support */
@@ -98,65 +94,6 @@ static int do_ssl;
static char *certfile;
static char *cipher;
-/*!
- * The following code implements a generic mechanism for starting
- * services on a TCP or TLS socket.
- * The service is configured in the struct server_args, and
- * then started by calling server_start(desc) on the descriptor.
- * server_start() first verifies if an instance of the service is active,
- * and in case shuts it down. Then, if the service must be started, creates
- * a socket and a thread in charge of doing the accept().
- *
- * The body of the thread is desc->accept_fn(desc), which the user can define
- * freely. We supply a sample implementation, server_root(), structured as an
- * infinite loop. At the beginning of each iteration it runs periodic_fn()
- * if defined (e.g. to perform some cleanup etc.) then issues a poll()
- * or equivalent with a timeout of 'poll_timeout' milliseconds, and if the
- * following accept() is successful it creates a thread in charge of
- * running the session, whose body is desc->worker_fn(). The argument of
- * worker_fn() is a struct server_instance, which contains the address
- * of the other party, a pointer to desc, the file descriptors (fd) on which
- * we can do a select/poll (but NOT IO/, and a FILE * on which we can do I/O.
- * We have both because we want to support plain and SSL sockets, and
- * going through a FILE * lets us provide the encryption/decryption
- * on the stream without using an auxiliary thread.
- *
- * NOTE: in order to let other parts of asterisk use these services,
- * we need to do the following:
- * + move struct server_instance and struct server_args to
- * a common header file, together with prototypes for
- * server_start() and server_root().
- * +
- */
-
-/*!
- * describes a server instance
- */
-struct server_instance {
- FILE *f; /* fopen/funopen result */
- int fd; /* the socket returned by accept() */
- SSL *ssl; /* ssl state */
- struct sockaddr_in requestor;
- struct server_args *parent;
-};
-
-/*!
- * arguments for the accepting thread
- */
-struct server_args {
- struct sockaddr_in sin;
- struct sockaddr_in oldsin;
- int is_ssl; /* is this an SSL accept ? */
- int accept_fd;
- int poll_timeout;
- pthread_t master;
- void *(*accept_fn)(void *); /* the function in charge of doing the accept */
- void (*periodic_fn)(void *); /* something we may want to run before after select on the accept socket */
- void *(*worker_fn)(void *); /* the function in charge of doing the actual work */
- const char *name;
-};
-
-static void *server_root(void *arg);
static void *httpd_helper_thread(void *arg);
/*!
@@ -705,7 +642,7 @@ done:
return NULL;
}
-static void *server_root(void *data)
+void *server_root(void *data)
{
struct server_args *desc = data;
int fd;
@@ -765,7 +702,7 @@ char *ast_http_setcookie(const char *var, const char *val, int expires, char *bu
return buf;
}
-static int ssl_setup(void)
+int ssl_setup(void)
{
#ifndef DO_SSL
do_ssl = 0;
@@ -804,7 +741,7 @@ static int ssl_setup(void)
* which does the socket/bind/listen and starts a thread for handling
* accept().
*/
-static void server_start(struct server_args *desc)
+void server_start(struct server_args *desc)
{
int flags;
int x = 1;