source: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server.h @ 151

Revision 151, 2.2 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Line 
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#include "cexcept.h"
26define_exception_type(int);
27extern struct exception_context the_exception_context[1];
28
29void demo_throw(int fail)
30{
31        //fprintf(stderr, "enter demo_throw(%d)\n", fail);
32        if (fail) Throw 42;
33        //fprintf(stderr, "return from demo_throw(%d)\n", fail);
34}
35
36
37/* define max clients per child */
38#ifndef __CLIENTS__
39   #define __CLIENTS__ 100
40#endif
41
42/* define max clients waiting in the queue for connect */
43#ifndef __QUEUE_SIZE__
44        #define __QUEUE_SIZE__ 10
45#endif
46
47/* __SOCKET_ERROR__ must be -1, don't change this */
48#ifndef __SOCKET_ERROR__
49        #define __SOCKET_ERROR__ -1
50#endif
51
52/* open port when this server is activated */
53#ifndef __DEFAULT_OPEN_PORT__
54        #define __DEFAULT_OPEN_PORT__ 8888
55#endif
56
57/* ip of jabber service */
58#ifndef __DEFAULT_JABBER_PORT__
59        #define __DEFAULT_JABBER_PORT__ 5222
60#endif
61
62/* port to connect on jabber service */
63#ifndef __DEFAULT_JABBER_IP__
64        #define __DEFAULT_JABBER_IP__ "im.celepar.parana"
65#endif
66
67/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
68#ifndef __BUFFER_SIZE__
69        #define __BUFFER_SIZE__ 4096
70#endif
71
72#define MESSAGE                 "This is the message I'm sending back and forth"
73
74/* Make these what you want for certificate & key files */
75#define CERT_FILE "mycert.pem"
76#define KEY_FILE  "mycert.pem"
77
78/*Cipher list to be used*/
79#define CIPHER_LIST "RC4-MD5"
80
81/*Trusted CAs location*/
82#define CA_FILE CERT_FILE
83#define CA_DIR NULL
84
85/*Password for the key file*/
86#define KEY_PASSWD ""
87
88#ifndef __CLEAR_SCREEN__
89        #define __CLEAR_SCREEN__ "clear"
90#endif
91
92/* 0 -> false; 1 -> true */
93#ifndef __DEBUG__
94        #define __DEBUG__ 0
95#endif
96
97struct client
98{
99        int fd;
100        struct sockaddr_in sockaddr;
101        pthread_t thread;
102        SSL_CTX  *ctx;
103        SSL * myssl;
104        time_t last;
105        struct client * next;
106};
107
108void * handler(void *);
109
110void usage (void)
111{
112        puts("usage: ./server <PORT>\n\n");
113        exit (-1);
114}
Note: See TracBrowser for help on using the repository browser.