[151] | 1 | #include <fcntl.h> |
---|
| 2 | |
---|
| 3 | #include <netdb.h> |
---|
| 4 | #include <netinet/in.h> |
---|
| 5 | #include <netinet/tcp.h> |
---|
| 6 | |
---|
| 7 | #include <openssl/ssl.h> |
---|
| 8 | #include <openssl/err.h> |
---|
| 9 | #include <openssl/crypto.h> |
---|
| 10 | #include <openssl/x509.h> |
---|
| 11 | #include <openssl/pem.h> |
---|
| 12 | #include <openssl/bio.h> |
---|
| 13 | |
---|
| 14 | #include <pthread.h> |
---|
| 15 | |
---|
| 16 | #include <signal.h> |
---|
| 17 | #include <sys/types.h> |
---|
| 18 | #include <sys/socket.h> |
---|
| 19 | #include <string.h> |
---|
| 20 | #include <stdio.h> |
---|
| 21 | #include <stdlib.h> |
---|
| 22 | |
---|
| 23 | #include <unistd.h> |
---|
| 24 | |
---|
| 25 | /* define max clients per child */ |
---|
| 26 | #ifndef __CLIENTS__ |
---|
| 27 | #define __CLIENTS__ 100 |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | /* define max clients waiting in the queue for connect */ |
---|
| 31 | #ifndef __QUEUE_SIZE__ |
---|
| 32 | #define __QUEUE_SIZE__ 10 |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | /* __SOCKET_ERROR__ must be -1, don't change this */ |
---|
| 36 | #ifndef __SOCKET_ERROR__ |
---|
| 37 | #define __SOCKET_ERROR__ -1 |
---|
| 38 | #endif |
---|
| 39 | |
---|
| 40 | /* open port when this server is activated */ |
---|
| 41 | #ifndef __DEFAULT_OPEN_PORT__ |
---|
| 42 | #define __DEFAULT_OPEN_PORT__ 8888 |
---|
| 43 | #endif |
---|
| 44 | |
---|
| 45 | /* ip of jabber service */ |
---|
| 46 | #ifndef __DEFAULT_JABBER_PORT__ |
---|
| 47 | #define __DEFAULT_JABBER_PORT__ 5222 |
---|
| 48 | #endif |
---|
| 49 | |
---|
| 50 | /* port to connect on jabber service */ |
---|
| 51 | #ifndef __DEFAULT_JABBER_IP__ |
---|
| 52 | #define __DEFAULT_JABBER_IP__ "im.celepar.parana" |
---|
| 53 | #endif |
---|
| 54 | |
---|
| 55 | /* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */ |
---|
| 56 | #ifndef __BUFFER_SIZE__ |
---|
| 57 | #define __BUFFER_SIZE__ 4096 |
---|
| 58 | #endif |
---|
| 59 | |
---|
| 60 | #define MESSAGE "This is the message I'm sending back and forth" |
---|
| 61 | |
---|
| 62 | /* Make these what you want for certificate & key files */ |
---|
| 63 | #define CERT_FILE "mycert.pem" |
---|
| 64 | #define KEY_FILE "mycert.pem" |
---|
| 65 | |
---|
| 66 | /*Cipher list to be used*/ |
---|
| 67 | #define CIPHER_LIST "RC4-MD5" |
---|
| 68 | |
---|
| 69 | /*Trusted CAs location*/ |
---|
| 70 | #define CA_FILE CERT_FILE |
---|
| 71 | #define CA_DIR NULL |
---|
| 72 | |
---|
| 73 | /*Password for the key file*/ |
---|
| 74 | #define KEY_PASSWD "" |
---|
| 75 | |
---|
| 76 | #ifndef __CLEAR_SCREEN__ |
---|
| 77 | #define __CLEAR_SCREEN__ "clear" |
---|
| 78 | #endif |
---|
| 79 | |
---|
| 80 | /* 0 -> false; 1 -> true */ |
---|
| 81 | #ifndef __DEBUG__ |
---|
| 82 | #define __DEBUG__ 0 |
---|
| 83 | #endif |
---|
| 84 | |
---|
| 85 | struct client |
---|
| 86 | { |
---|
| 87 | int fd; |
---|
| 88 | struct sockaddr_in sockaddr; |
---|
| 89 | pthread_t thread; |
---|
| 90 | SSL_CTX *ctx; |
---|
| 91 | SSL * myssl; |
---|
| 92 | time_t last; |
---|
| 93 | struct client * next; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | void * handler(void *); |
---|
| 97 | |
---|
| 98 | void usage (void) |
---|
| 99 | { |
---|
| 100 | puts("usage: ./server <PORT>\n\n"); |
---|
| 101 | exit (-1); |
---|
| 102 | } |
---|