root/main.h

Revision fc4ae5ac4c3000ecb26d84ab72fe84f304e4bad5, 1.7 kB (checked in by D.J. Capelis <dev@…>, 23 months ago)

Refactor: Less ugly, less broken and less painful. Cost: -40 lines.

I'm very pleased with this tradeoff. This refactor has been needed for
a long time. This should not only make services easier to write, but
should allow me to split out services into service modules now, which
has been a goal for awhile that this whole refactor needed to happen to
really do. Now we can just pass the socket structure to the modularized
services and for the most part most services will be able to do most of
what they need to do. There's going to still need to be some magic I
fear, but less.

Though given how simple things are, splitting these things out into
modules may not even be as necessary anymore.

  • Property mode set to 100644
Line 
1#ifndef _MAIN_H
2#define _MAIN_H
3
4#include<stdio.h>
5#include<stdlib.h>
6#include<pthread.h>
7#include<sys/socket.h>
8#include<sys/types.h>
9#include<sys/time.h>
10#include<netinet/in.h>
11#include<netinet/ip.h>
12#include<netinet/tcp.h>
13#include<errno.h>
14#include<err.h>
15#include<unistd.h>
16#include<signal.h>
17#include<string.h>
18#include<netdb.h>
19#include<arpa/inet.h>
20#include<openssl/ssl.h>
21
22#include<compat/epoll.h>
23
24/* Forward declarations */
25struct service;
26struct session;
27
28#include"init.h"
29#include"helpers.h"
30#include"config.h"
31#include"handler.h"
32
33/* defines */
34#define HELP_SERVICE 1
35#define LIST_SERVICE 2
36#define MULTIPLEX_SERVICE 3
37#define SSL_SERVICE 4
38#define AUTH_SERVICE 5
39#define HOST_SERVICE 6
40#define CUSTOM_SERVICE -1
41
42#define chk_error(cond) if (cond) { goto err; }
43
44/* Global Variables */
45extern int listen_queue;    //Queue size for listen()
46extern int mainsock;        //Main socket
47extern int port_number;     //Port number to listen on
48extern struct service * servicelist;
49
50/* Structures */
51
52struct service
53{
54    char * name;
55    int service_type;
56    struct sockaddr_in6 * info;
57    struct service * next;
58    char * restrict_host;
59    char * restrict_user;
60};
61
62struct session
63{
64    int sock;
65    SSL * ssl;               //For TLS, holds sock's SSL connection
66    SSL_CTX * contxt;        //For TLS, holds OpenSSL's SSL context
67    int multiplex;           //For MULTIPLEX, to determine whether multiplex is on
68    int multiplex_xtra;      //For MULTIPLEX, remaining data until next multiplexing header
69    char header[16];         //For MULTIPLEX, header formatting
70    unsigned int * ptr;      //For MULTIPLEX, convenient pointer to header
71    char * user;             //For AUTH
72    char * host;             //For AUTH
73};
74
75#endif
Note: See TracBrowser for help on using the browser.