taskrambler  v0.1.8
Web server and task management solution.
server.c File Reference
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "class.h"
#include "server.h"
#include "socket.h"
#include "logger.h"
#include "utils/memory.h"
+ Include dependency graph for server.c:

Go to the source code of this file.

Functions

void serverCloseConn (Server, unsigned int)
 
static int serverCtor (void *_this, va_list *params)
 
static void serverDtor (void *_this)
 
 INIT_IFACE (Class, serverCtor, serverDtor, NULL)
 
 CREATE_CLASS (Server, NULL, IFACE(Class))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file server.c.

Function Documentation

CREATE_CLASS ( Server  ,
NULL  ,
IFACE(Class)   
)
INIT_IFACE ( Class  ,
serverCtor  ,
serverDtor  ,
NULL   
)
void serverCloseConn ( Server  ,
unsigned  int 
)

Definition at line 31 of file close_conn.c.

References STREAM_SSL.

Referenced by serverDtor().

32 {
33  int fd = (this->fds)[i].fd;
34  Stream st = (this->conns[fd]).stream;
35 
36  delete((this->conns)[fd].sock);
37  delete((this->conns)[fd].worker);
38 
39  if (NULL != st && STREAM_SSL == st->type) {
40  SSL_shutdown((st->handle).ssl);
41  SSL_free((st->handle).ssl);
42  (st->handle).ssl = NULL;
43  }
44 
45  delete(st);
46 
47  memset(&(this->fds[i]), 0, sizeof(struct pollfd));
48 }
Definition: server.h:39

+ Here is the caller graph for this function:

static int serverCtor ( void *  _this,
va_list *  params 
)
static
Todo:
some logging would be appropriate :)

Definition at line 43 of file server.c.

References logger, LOGGER_INFO, loggerLog(), memCalloc(), socketListen(), and socketNonblock().

44 {
45  Server this = _this;
46  in_port_t port;
47  unsigned int backlog;
48 
49  this->max_fds = sysconf(_SC_OPEN_MAX);
50  if (this->max_fds <= 10) { // reserve 10 handles for internal use.
51  /**
52  * \todo some logging would be appropriate :)
53  */
54  return -1;
55  }
56  this->max_fds -= 10;
57 
58  this->logger = va_arg(* params, Logger);
59  this->worker = va_arg(* params, void *);
60  port = va_arg(* params, int);
61  backlog = va_arg(* params, unsigned int);
62 
63  loggerLog(this->logger,
65  "accept up to %zu connections",
66  this->max_fds);
67 
68  this->fds = memCalloc(sizeof(struct pollfd), this->max_fds);
69  this->conns = memCalloc(sizeof(struct conns), this->max_fds);
70 
71  this->sock = new(Sock, this->logger, port);
72  socketNonblock(this->sock);
73 
74  this->sockSSL = new(Sock, this->logger, port+1);
75  socketNonblock(this->sockSSL);
76 
77  SSL_library_init();
78  OpenSSL_add_all_algorithms();
79  SSL_load_error_strings();
80  this->ctx = SSL_CTX_new(SSLv23_server_method());
81  SSL_CTX_set_cipher_list(
82  this->ctx,
83  "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS");
84  SSL_CTX_use_certificate_file(
85  this->ctx,
86  CONFIGDIR "/taskrambler.crt",
87  SSL_FILETYPE_PEM);
88 
89  SSL_CTX_use_RSAPrivateKey_file(
90  this->ctx,
91  CONFIGDIR "/taskrambler.pem",
92  SSL_FILETYPE_PEM);
93 
94  socketListen(this->sock, backlog);
95  socketListen(this->sockSSL, backlog);
96 
97  (this->fds)[0].fd = this->sock->handle;
98  (this->fds)[0].events = POLLIN;
99  (this->fds)[1].fd = this->sockSSL->handle;
100  (this->fds)[1].events = POLLIN;
101  this->nfds = 2;
102 
103  return 0;
104 }
void socketListen(Sock this, int backlog)
Definition: listen.c:32
Logger logger
Definition: taskrambler.c:66
void socketNonblock(Sock this)
Definition: nonblock.c:32
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38
Definition: server.h:39
void * memCalloc(size_t, size_t)
Definition: memory.c:818

+ Here is the call graph for this function:

static void serverDtor ( void *  _this)
static

Definition at line 108 of file server.c.

References MEM_FREE, and serverCloseConn().

109 {
110  Server this = _this;
111  int i;
112 
113  for (i=0; i<this->nfds; i++) {
114  if (this->sock->handle != (this->fds)[i].fd &&
115  this->sockSSL->handle != (this->fds)[i].fd) {
116  serverCloseConn(this, i);
117  }
118  }
119 
120  MEM_FREE(this->fds);
121  MEM_FREE(this->conns);
122 
123  delete(this->sock);
124  delete(this->sockSSL);
125 
126  SSL_CTX_free(this->ctx);
127  ERR_free_strings();
128 }
#define MEM_FREE(seg)
Definition: memory.h:28
Definition: server.h:39
void serverCloseConn(Server, unsigned int)
Definition: close_conn.c:31

+ Here is the call graph for this function: