Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/client.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/client.c	(revision 151)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#include "unp.h"
-
-int main(int argc, char ** argv)
-{
-	int sockfd;
-	struct sockaddr_in servaddr;
-
-	if ( argc != 2 )
-		err_quit("you need use <IPaddress>");
-
-	sockfd = Socket(AF_INET, SOCK_STREAM, 0);
-
-	bzero(&servaddr, sizeof(servaddr));
-	servaddr.sin_family = AF_INET;
-	servaddr.sin_port = htons(SERV_PORT);
-	inet_pton(AF_INET, argv[1], &(servaddr.sin_addr));
-
-	connect(sockfd, (SA *) &(servaddr), sizeof(servaddr));
-
-	str_cli(stdin, sockfd);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/server.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/server.c	(revision 151)
+++ 	(revision )
@@ -1,82 +1,0 @@
-#include "unp.h"
-
-int main(int argc, char ** argv)
-{
-	int maxfdp1,
-		listenfd,
-		connfd,
-		nready,
-		udpfd;
-	char mesg[MAXLINE];
-	pid_t childpid;
-	fd_set rset;
-	ssize_t n;
-	socklen_t clilen,
-			  len;
-	const int on = 1;
-	struct sockaddr_in cliaddr,
-					   servaddr;
-	void sig_chld(int);
-
-	listenfd = Socket(AF_INET, SOCK_STREAM, 0); /* create listening TCP socket */
-
-	bzero(&servaddr, sizeof(servaddr));
-	servaddr.sin_family = AF_INET;
-	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
-	servaddr.sin_port = htons(SERV_PORT);
-
-	setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &(on), sizeof(on));
-	bind(listenfd, (SA *)&servaddr, sizeof(servaddr));
-
-	Listen(listenfd, LISTENQ);
-
-	udpfd = Socket(AF_INET, SOCK_DGRAM, 0); /* create UDP socket */
-
-	bzero(&servaddr, sizeof(servaddr));
-	servaddr.sin_family = AF_INET;
-	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
-	servaddr.sin_port = htons(SERV_PORT);
-
-	bind(udpfd, (SA *)&servaddr, sizeof(servaddr));
-
-	signal(SIGCHLD, sig_chld);	/* must call waitpid() */
-
-	FD_ZERO(&(rset));
-	maxfdp1 = max(listenfd, udpfd) + 1;
-
-	for ( ; ; )
-	{
-		FD_SET(listenfd,&(rset));
-		FD_SET(udpfd,&(rset));
-
-		if ( (nready = select(maxfdp1, &(rset), NULL, NULL, NULL)) < 0 )
-		{
-			if ( errno == EINTR )
-				continue;	/* back to for() */
-			else
-				err_sys("select error");
-		}
-		if ( FD_ISSET(listenfd, &(rset)) )
-		{
-			len = sizeof(cliaddr);
-			connfd = accept(listenfd, (SA *) &(cliaddr), &(len));
-
-			if ( childpid = fork() == 0 )	/* child process */
-			{
-				close(listenfd);			/* close listening socket */
-				str_echo(connfd);			/* process request */
-				exit(0);
-			}
-			close(connfd);					/* parent closes connected socket */
-		}
-		if ( FD_ISSET(udpfd, &(rset)) )
-		{
-			len = sizeof(cliaddr);
-			n = recvfrom(udpfd, mesg, MAXLINE, 0, (SA *) &(cliaddr), &(len));
-			sendto(udpfd, mesg, n, 0, (SA *) &(cliaddr), len);
-		}
-
-	}
-
-	return 0;
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/unp.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/unp.h	(revision 151)
+++ 	(revision )
@@ -1,567 +1,0 @@
-#include "config.h"
-
-#include <sys/types.h>		/* basic system data type */
-#include <sys/socket.h>		/* basic socket definitions */
-#include <sys/time.h>		/* timeval{} for select() */
-#include <time.h>			/* timespec{} for pselect() */
-#include <netinet/in.h>		/* sockaddr_in{} and other Internet defns */
-#include <arpa/inet.h>		/* inet(3) functions */
-#include <errno.h>
-#include <fcntl.h>			/* for nonblocking */
-#include <netdb.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>		/* for S_xxx file mode constants */
-#include <sys/uio.h>		/* for iovec{} and readv/writev */
-#include <unistd.h>
-#include <sys/wait.h>
-#include <sys/un.h>			/* for Unix domain sockets */
-
-#ifdef	HAVE_SYS_SELECT_H
-	#include <sys/select.h>	/* for convenience */
-#endif
-
-#ifdef	HAVE_POLL_H
-	#include <poll.h>	/* for convenience */
-#endif
-
-#ifdef	HAVE_STRINGS_H
-	#include <strings.h>	/* for convenience */
-#endif
-
-/* Three headers are normally needed for socket/file ioctl's:
- * <sys/ioctl.h>, <sys/filio.h> and <sys/sockio.h>.
- */
-#ifdef HAVE_SYS_IOCTL_H
-	#include <sys/ioctl.h>
-#endif
-
-#ifdef HAVE_SYS_FILIO_H
-	#include <sys/filio.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKIO_H
-	#include <sys/sockio.h>
-#endif
-
-#ifdef HAVE_PTHREAD_H
-	#include <pthread.h>
-#endif
-
-/* OSF/1 actually disable recv() and send() in <sys/socket.h> */
-#ifdef __osf__
-	#undef recv
-	#undef send
-	#define recv(a,b,c,d)	recvfrom(a,b,c,d,0,0)
-	#define send(a,b,c,d)	sendto(a,b,c,d,0,0)
-#endif
-
-#ifndef INADDR_NOME
-	#define INADDR_NOME 0xffffffff	/* should have been in <netinet/in.h> */
-#endif
-
-#ifndef SHUT_RD				/* these three Posix.1g names are quite now */
-	#define SHUT_RD		0	/* shutdown for reading */
-	#define SHUT_WR		1	/* shutdown for writing */
-	#define SHUT_RDWR	2	/* shutdown for reading and writing */
-#endif
-
-#ifndef INET_ADDRSTRLEN
-	#define INETADDRSTRLEN 16	/* "ddd.ddd.ddd.ddd\0" 1234567890123456 */
-#endif
-
-/* Define following even if IPv6 not supported, so we can always allocate
- * an adequately-sized buffer, without #ifdefs in the code.
- */
-#ifndef	INET6_ADDRSTRLEN
-	#define INET6_ADDRSTRLEN 46	/* max size of IPv6 address string:
-								 * "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or
-								 * "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"
-								 * 1234567890123456789012345678901234567890123456
-								 */
-#endif
-
-/* Define bzero() as a macro if it's not standard C libary. */
-#ifndef HAVE_BZERO
-	#define bzero(ptr,n)	memset(ptr,0,n)
-#endif
-
-/* Older resolvers do not have gethostbyname2() */
-#ifndef HAVE_GETHOSTBYNAME2
-	#define gethostbyname2(host,family)		gethostbyname((host))
-#endif
-
-/* The structure returned by recvfrom_frags() */
-//struct in_pktinfo
-//{
-//	struct in_addr ipi_addr;	/* dst IPv4 address */
-//	int ipi_ifindex;			/* received interface index */
-//}
-
-/* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few
- * implementions support them today. These two macros really need
- * an ALIGN() macro, but each implementation does this differently. */
-#ifndef CMSG_LEN
-	#define CMSG_LEN(size)		(sizeof(struct cmsghdr) + (size))
-#endif
-#ifndef CMSG_SPACE
-	#define CMSG_SPACE(size)	(sizeof(struct cmsghdr) + (size))
-#endif
-
-/* Posix.1g requires the SUN_LEN() macro but not all implementations
- * define it (yet). Note that this 4.4BSD macro works regardless
- * whether there is a length field or not
- */
-#ifndef SUN_LEN
-	#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
-#endif
-
-/* Posix.1g remanes "Unix domain" as "local IPC". But
- * not all systems define AF_LOCAL and PF_LOCAL (yet).
- */
-#ifndef AF_LOCAL
-	#define AF_LOCAL	AF_UNIX
-#endif
-#ifndef PF_LOCAL
-	#define PF_LOCAL	PF_UNIX
-#endif
-
-/* Posix.1g require that an include of <poll.h> define INFTIM, but
- * many systems still define it in <sys/stropts.h>. We don't want
- * to include all the streams stuff if it's not needed, so we just
- * define INFTIM here. This is the standard value, but there's no
- * guarantee it is -1.
- */
-#ifndef INFTIM
-	#define INFTIM (-1)			/* infinite poll timeout */
-	#ifdef HAVE_POLL_H
-		#define INFTIM_UNPH		/* tell unpxti.h we defined it */
-	#endif
-#endif
-
-/* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
- * kernels still #define it as 5, while actually supporting many more
- */
-#define LISTENQ		1024	/* 2nd argument to listen() */
-
-/* Miscellaneous constants */
-#define MAXLINE		4096	/* max text line length */
-#define MAXSOCKADDR	128		/* max socket address struct size */
-#define BUFFSIZE	8192	/* buffer size for reads and writes */
-
-/* Define some port number that can be used for client-servers */
-#define SERV_PORT		9877			/* TCP and UDP client-servers */
-#define SERV_PORT_STR	"9877"			/* TCP and UDP client-servers */
-#define UNIXSTR_PATH	"/tmp/unix.str"	/* Unix domain stream cli-serv */
-#define UNIXDG_PATH	"/tmp/unix.dg"	/* Unix domain datagram cli-serv */
-
-/* Following shortens all the type casts of point arguments */
-#define SA struct sockaddr
-#define FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)		/* default file access permissions for new files */
-#define DIR_MODE	(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)	/* default permissions for new directories */
-
-typedef void Sigfunc(int);	/* for signal handlers */
-
-#define min(a,b)	((a) < (b) ? (a) : (b))
-#define max(a,b)	((a) > (b) ? (a) : (b))
-
-#include <stdarg.h>		/* ANSI C hearder file */
-#include <syslog.h>		/* for syslog() */
-
-int daemon_proc;
-
-static void err_doit(int, int, const char *, va_list);
-
-void err_ret(const char * fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	err_doit(1, LOG_INFO, fmt, ap);
-	va_end(ap);
-	return;
-}
-
-int err_sys(const char * fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	err_doit(1, LOG_INFO, fmt, ap);
-	va_end(ap);
-	exit(1);
-}
-
-void err_dump(const char * fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	err_doit(1, LOG_INFO, fmt, ap);
-	va_end(ap);
-	abort();
-	exit(1);
-}
-
-void err_msg(const char * fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	err_doit(1, LOG_INFO, fmt, ap);
-	va_end(ap);
-	return;
-}
-
-void err_quit(const char * fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	err_doit(1, LOG_INFO, fmt, ap);
-	va_end(ap);
-	exit(1);
-}
-
-static void err_doit(int errnoflag, int level, const char * fmt, va_list ap)
-{
-	int errno_save,
-		n;
-	char buf[MAXLINE + 1];
-
-	errno_save = errno;
-	#ifdef HAVE_VSNPRINTF
-		vsnprintf(buf, MAXLINE, fmt, ap);
-	#else
-		vsprintf(buf, fmt, ap);
-	#endif
-	n = strlen(buf);
-	if ( errnoflag )
-		snprintf(buf + n, MAXLINE - n, ": %s", strerror(errno_save));
-	else
-	{
-		fflush(stdout);
-		fputs(buf, stderr);
-		fflush(stderr);
-	}
-	return;
-}
-
-int Socket(int family, int type, int protocol)
-{
-	int n;
-	if ( (n = socket(family, type, protocol)) < 0 )
-		err_sys("socket error");
-	return(n);
-}
-
-void Listen(int fd, int backlog)
-{
-	char * ptr;
-	/* can override 2nd argument with environment variable */
-	if ( (ptr = getenv("LISTENQ")) != NULL )
-		backlog = atoi(ptr);
-	if ( listen(fd, backlog) < 0 )
-		err_sys("listen error");
-}
-
-/* Read 'n' bytes from a descriptor. */
-ssize_t readn(int fd, void * vptr, size_t n)
-{
-	size_t	nleft;
-	ssize_t	nread;
-	char	* ptr;
-
-	ptr = vptr;
-	nleft = n;
-	while ( nleft > 0 )
-	{
-		if ( (nleft = read(fd, ptr, nleft)) < 0 )
-		{
-			if ( errno == EINTR )
-				nread = 0; /* and call read() again */
-			else
-				return (-1);
-		}
-		else if ( nread == 0 )
-			break; /* EOF */
-
-		nleft -= nread;
-		ptr += nread;
-	}
-	return (n - nleft); /* return >= 0 */
-}
-
-/* Write 'n' bytes to a descriptor. */
-ssize_t writen(int fd, const void *(vptr), size_t n)
-{
-	size_t	nleft;
-	ssize_t	nwritten;
-	const char * ptr;
-
-	ptr = vptr;
-	nleft = n;
-	while ( nleft > 0 )
-	{
-		if ( (nwritten = write(fd, ptr, nleft)) <= 0 )
-		{
-			if ( errno == EINTR )
-				nwritten = 0; /*and call write() again */
-			else
-				return (-1); /* error */
-		}
-
-		nleft -= nwritten;
-		ptr += nwritten;
-	}
-	return (n);
-}
-
-ssize_t readline(int fd, void *(vptr), size_t maxlen)
-{
-	size_t  n,
-			rc;
-	char c,
-		 * ptr;
-
-	ptr = vptr;
-	for ( n = 1; n < maxlen; n++ )
-	{
-		again:
-			if ( (rc = read(fd, &(c), 1)) == 1 )
-			{
-				*(ptr)++ = c;
-				if ( c == '\n' )
-					break; /* newline is stored, like fgets() */
-			}
-			else if ( rc == 0 )
-			{
-				if ( n == 1 )
-					return(0); /* EOF, no data read */
-				else
-					break; /* EOF, some data read */
-			}
-			else
-			{
-				if ( errno == EINTR )
-					goto again;
-				return(-1); /* error, errno set by read() */
-			}
-	}
-
-	*(ptr) = 0; /* null terminate like fgets() */
-	return(n);
-}
-
-char * gf_time(void)
-{
-	struct timeval tv;
-	static char str[30];
-	char * ptr;
-
-	if ( gettimeofday(&tv, NULL) < 0 )
-		err_sys("gettimeofday error");
-
-	ptr = ctime(&tv.tv_sec);
-	strcpy(str, &ptr[11]);
-	snprintf(str + 8, sizeof(str) - 8, ".%06d", tv.tv_usec);
-	return(str);
-}
-
-void str_echo(int sockfd)
-{
-	long arg1,
-		 arg2;
-	ssize_t n;
-	char line[MAXLINE];
-
-	for ( ; ; )
-	{
-		if ( (n = readline(sockfd, line, MAXLINE)) == 0 )
-			return; /* connection closed by other end */
-
-		/*if ( sscanf(line, "%ld%ld", &(arg1), &(arg2)) == 2 )
-			snprintf(line, sizeof(line), "%ld\n", arg1 + arg2);
-		else
-			snprintf(line, sizeof(line), "input error\n");
-
-		n = strlen(line);*/
-		writen(sockfd, line, n);
-	}
-}
-
-void str_cli(FILE * fp, int sockfd)
-{
-	int maxfdp1, stdineof, val;
-	ssize_t n, nwritten;
-	fd_set rset, wset;
-	char sendline[MAXLINE],
-		 recvline[MAXLINE];
-	char to[MAXLINE],
-		 fr[MAXLINE];
-	char * toiptr,
-		 * tooptr,
-		 * friptr,
-		 * froptr;
-
-	val = fcntl(sockfd, F_GETFL, 0);
-	fcntl(sockfd, F_SETFL, val| O_NONBLOCK);
-
-	val = fcntl(STDIN_FILENO, F_GETFL, 0);
-	fcntl(STDIN_FILENO, F_SETFL, val| O_NONBLOCK);
-
-	val = fcntl(STDOUT_FILENO, F_GETFL, 0);
-	fcntl(STDOUT_FILENO, F_SETFL, val| O_NONBLOCK);
-
-	toiptr = tooptr = to;
-	friptr = froptr = fr;
-	stdineof = 0;
-
-	maxfdp1 = max(max(STDIN_FILENO, STDOUT_FILENO), sockfd) + 1;
-	for ( ; ; )
-	{
-		FD_ZERO(&(rset));
-		FD_ZERO(&(wset));
-		if ( stdineof == 0 && toiptr < &to[MAXLINE] )
-			FD_SET(STDIN_FILENO, &(rset));	/* read from stdin */
-		if ( friptr < &fr[MAXLINE] )
-			FD_SET(sockfd, &(rset));		/* read from socket */
-		if ( tooptr != toiptr )
-			FD_SET(sockfd, &(wset));		/* data to wrtite to socket */
-		if ( froptr != friptr )
-			FD_SET(STDOUT_FILENO, &(wset));	/* data to wrtite to stdout */
-
-		select(maxfdp1, &(rset), &(wset), NULL, NULL);
-
-		if ( FD_ISSET(STDIN_FILENO, &(rset)) )
-		{
-			if ( (n = readline(STDIN_FILENO, toiptr, &to[MAXLINE] - toiptr)) < 0 )
-			{
-				if ( errno != EWOULDBLOCK )
-					err_sys("read error on stdin");
-			}
-			else if ( n == 0 )
-			{
-				fprintf(stderr, "%s: EOF on stdin\n", gf_time());
-				stdineof = 1;	/* all done with stdin */
-				if ( tooptr == toiptr )
-					shutdown(sockfd, SHUT_WR);	/* send FIN */
-			}
-			else
-			{
-				fprintf(stderr, "%s: read %d bytes from socket\n", gf_time(), n);
-				toiptr += n;	/* # just read */
-				FD_SET(sockfd, &(wset));	/* try and write below */
-			}
-		}
-
-		if ( FD_ISSET(sockfd, &(rset)) )
-		{
-			if ( (n = readline(sockfd, friptr, &fr[MAXLINE] - friptr)) < 0 )
-			{
-				if ( errno != EWOULDBLOCK )
-					err_sys("read error on socket");
-			}
-			else if ( n == 0 )
-			{
-				fprintf(stderr, "%s: EOF on socket\n", gf_time());
-				if ( stdineof )
-					return;	/* normal termination */
-				else
-					err_quit("server terminated prematurely");
-			}
-			else
-			{
-				fprintf(stderr, "%s: read %d bytes from socket\n", gf_time(), n);
-				friptr += n;	/* # just read */
-				FD_SET(STDOUT_FILENO, &(wset));	/* try and write below */
-			}
-		}
-
-		if ( FD_ISSET(STDOUT_FILENO, &(wset)) && ((n = friptr - froptr) < 0) )
-		{
-			if ( (nwritten = write(STDOUT_FILENO, froptr, n)) < 0 )
-			{
-				if ( errno != EWOULDBLOCK )
-					err_sys("write error to stdout");
-			}
-			else
-			{
-				fprintf(stderr, "%s: wrote %d bytes to stdout\n", gf_time(), nwritten);
-				froptr += nwritten;	/* # just written */
-				if ( froptr == friptr )
-					froptr = friptr = fr;	/* back to beginning of buffer */
-			}
-		}
-
-		if ( FD_ISSET(sockfd, &(wset)) && ((n = toiptr - tooptr) < 0) )
-		{
-			if ( (nwritten = write(sockfd, tooptr, n)) < 0 )
-			{
-				if ( errno != EWOULDBLOCK )
-					err_sys("write error to socket");
-			}
-			else
-			{
-				fprintf(stderr, "%s: wrote %d bytes to socket\n", gf_time(), nwritten);
-				tooptr += nwritten;	/* # just written */
-				if ( tooptr == toiptr )
-				{
-					tooptr = toiptr = to;	/* back to beginning of buffer */
-					if ( stdineof )
-						shutdown(sockfd, SHUT_WR);	/* send FIN */
-				}
-			}
-		}
-
-
-
-
-
-		/*
-		if ( FD_ISSET(fileno(fp), &(rset)) ) // input is readable
-		{
-			if ( fgets(sendline, MAXLINE, fp) == NULL )
-			{
-				stdineof == 1;
-				shutdown(sockfd, SHUT_WR); // send FIN
-				FD_CLR(fileno(fp), &(rset));
-				continue;
-			}
-			writen(sockfd, sendline, strlen(sendline));
-		}
-		*/
-	}
-}
-
-Sigfunc * signal(int signo, Sigfunc * func)
-{
-	struct sigaction act,
-					 oact;
-
-	act.sa_handler = func;
-	sigemptyset(&(act.sa_mask));
-	act.sa_flags = 0;
-	if ( signo == SIGALRM )
-	{
-		#ifdef SA_INTERRUPT
-			act.sa_flags |= SA_INTERRUPT;	/* SunOS 4.x */
-		#endif
-	}
-	else
-	{
-		#ifdef SA_RESTART
-			act.sa_flags |= SA_RESTART;		/* SVR4, 4.4BSD */
-		#endif
-	}
-	if ( sigaction(signo, &(act), &(oact)) < 0 )
-		return SIG_ERR;
-	return oact.sa_handler;
-}
-
-void sig_chld(int signo)
-{
-	pid_t pid;
-	int stat;
-
-	while ( (pid = waitpid(-1, &(stat), WNOHANG)) > 0 )
-		printf("child %d terminated\n", pid);
-	return;
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/config.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BOOK/config.h	(revision 151)
+++ 	(revision )
@@ -1,52 +1,0 @@
-#define HAVE_PTHREAD_H		1		/* <pthread.h> */
-#define HAVE_STRINGS_H		1		/* <strings.h> */
-
-//#define HAVE_SYS_FILIO_H	1		/* <sys/filio.h> */
-#define HAVE_SYS_IOCTL_H	1		/* <sys/ioctl.h> */
-#define HAVE_SYS_SELECT_H	1		/* <sys/select.h> */
-//#define HAVE_SYS_SOCKIO_H	1		/* <sys/sockio.h> */
-#define HAVE_SYS_SYSCTL_H	1		/* <sys/sysctl.h> */
-#define HAVE_SYS_TIME_H		1		/* <sys/time.h> */
-
-/* Define if we can include <time.h> with <sys/time.h> */
-#define TIME_WITH_SYS_TIME	1
-
-/* Define the following if the function is provided */
-#define HAVE_BZERO			1
-#define HAVE_GETHOSTBYNAME	1
-#define HAVE_VSNPRINTF		1
-
-/* Define the following if the function prototype is in a header */
-#define HAVE_GETHOSTNAME_PROTO	1	/* <unistd.h> */
-#define HAVE_GETRUSAGE_PROTO	1	/* <sys/resource.h> */
-#define HAVE_HSTRERROR_PROTO	1	/* <netdb.h> */
-#define HAVE_INET_ATON_PROTO	1	/* <arpa/inet.h> */
-#define HAVE_INET_PTON_PROTO	1	/* <arpa/inet.h> */
-#define HAVE_SNPRINTF_PROTO		1	/* <stdio.h> */
-
-/* Define the following if the strutured is defined */
-#define HAVE_SOCKADDR_DL_STRUCT	1	/* <.h> */
-#define HAVE_TIMESPEC_STRUCT	1	/* <.h> */
-
-/* Define the following if the feature is defined */
-#define HAVE_SOCKADDR_SA_LEN	1	/* sockadr{} has sa_len */
-#define HAVE_MSGHDR_MSG_CONTROL	1	/* msghdr{} has msg_control member */
-
-/* Define the following to the appropriate datatype, if necessary */
-//#define uint8_t	unsigned char		/* <sys/type.h> */
-//#define uint16_t	unsigned short		/* <sys/type.h> */
-//#define uint32_t	unsigned int		/* <sys/type.h> */
-
-/* socklen_t should be typedef'd as uint32_t, but configure defines
- * it to be an unsigned int, as it is needed early in the compile
- * process, sometimes before some implementations define uint32_t. */
-//#define socklen_t	unsigned int	/* <sys/socket.h> */
-//#define sa_family_t	SA_FAMILY_T		/* <sys/socket.h> */
-//#define SA_FAMILY_T	uint8_t
-
-/* Define the following, if system suports the feature */
-#define IPV4		1	/* IPv4, uppercase V name */
-#define IPv4		1	/* IPv4, lowercase V name */
-#define UNIXDOMAIN	1	/* Unix domain sockets */
-#define UNIXdomain	1	/* Unix domain sockets */
-#define MCAST		1	/* multicasting support */
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_27092007.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_27092007.c	(revision 151)
+++ 	(revision )
@@ -1,256 +1,0 @@
-#include "server.h"
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL;
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-	//exit(0);
-
-	/*if ( argc != 2 || (socket_server_port = strtol(argv[1], 0, 10)) == 0 )
-		usage();*/
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-		puts("jah era #5");
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char pBuffer[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	//fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK );
-	//printf(":::client %d\n\n\n", fcntl( client->fd, F_GETFL, 0));
-	//printf(":::client %d\n\n\n", fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK ));
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	//jabber_port = strtol(__DEFAULT_JABBER_PORT__, 0, 10);
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	//while ( (time(NULL) - last) < 60 )
-	//{
-		/* read from client */
-	//	read(client->fd, pBuffer, __BUFFER_SIZE__);
-	//	printf("\n\n--------\n\nread from client:\n%s\n\n------------\n\n", pBuffer);
-		/* write in the jabber service */
-	//	write(jabber_fd, pBuffer, strlen(pBuffer));
-	//	sleep(1);
-		/* read from jabber service */
-	//	read(jabber_fd, pBuffer, __BUFFER_SIZE__);
-	//	printf("\n\n--------\n\nread from jabber:\n%s\n\n------------\n\n", pBuffer);
-		/* write in the client */
-	//	write(client->fd, pBuffer, strlen(pBuffer));
-	//}
-
-	int optval = 1;
-	socklen_t optlen = sizeof(optval);
-	if ( setsockopt(client->fd, SOL_SOCKET, SO_KEEPALIVE, &(optval), optlen ) )
-	{
-		puts("asdgsdfgsdfg");
-		exit(1);
-	}
-
-	int retval, ttlval, rbuf, len;
-	while ( (time(NULL) - last) < 20 )
-	{
-		printf("\n\n#################\n%d\n", getsockopt(client->fd, SOL_SOCKET, SO_KEEPALIVE, &optval, NULL));
-		printf("%d\n#######################\n\n", optval );
-		bzero(pBuffer, __BUFFER_SIZE__);
-		/* read from client */
-		printf("\n\n--------\nread from client...\n");
-		printf("error: %d\n", read(client->fd, pBuffer, __BUFFER_SIZE__));
-		printf("read from client:\n%s\n\n------------\n\n", pBuffer);
-
-		/* write in the jabber service */
-		printf("write in the jabber...\n");
-		//write(jabber_fd, pBuffer, strlen(pBuffer));
-		printf("send to jabber %d", sendto(jabber_fd, pBuffer, strlen(pBuffer), MSG_CONFIRM, 0,0));
-
-		//while ( (time(NULL) - last) < 5 );
-
-		bzero(pBuffer, __BUFFER_SIZE__);
-		/* read from jabber service */
-		printf("\n\n--------\nread from jabber...\n");
-		printf("error: %d\n", read(jabber_fd, pBuffer, __BUFFER_SIZE__));
-		printf("read from jabber:\n%s\n\n------------\n\n", pBuffer);
-
-		/* write in the client */
-		printf("write in the client...\n");
-		write(client->fd, pBuffer, strlen(pBuffer));
-
-		//printf("buffer limpo: %s\n\n----------------\n\n", pBuffer);
-		sleep(1);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client2.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client2.c	(revision 151)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include <unistd.h>
-#include <fcntl.h> 
-
-int main()
-{
-  register int s;
-  register int bytes;
-  struct sockaddr_in sa;
-  //char buffer[BUFSIZ+1];
-  int status = 1;
-  char * buffer = malloc(BUFSIZ),//(char)NULL;
-		 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='localhost' xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"};
-  
-  //fcntl(O_NONBLOCK, F_SETFL, 0);
-  //fcntl(O_ASYNC, F_SETFL, 1);
-  if ( (s = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
-  {
-    perror("socket");
-    return 1;
-  }
-
-  bzero(&sa, sizeof sa);
-
-  sa.sin_family = AF_INET;
-  sa.sin_port = htons(5222);
-  sa.sin_addr.s_addr = htonl((((((127 << 8) | 0) << 8) | 0) << 8) | 1);
-
-  //fcntl(O_NONBLOCK, F_SETFL, 0);
-  //fcntl(O_ASYNC, F_SETFL, 1);
-  if ( connect(s, (struct sockaddr *)&sa, sizeof sa) < 0 )
-  {
-    perror("connect");
-    close(s);
-    return 2;
-  }
-  
-  printf("::: %d\n\n\n", fcntl( s, F_SETFL, fcntl( s, F_GETFL ) & ~O_NONBLOCK ));
-
-  write(s, xml_connect, sizeof(xml_connect)-1);
-
-  while ((bytes = read(s, buffer, 4096)) > 0)
-  //bytes = read(s, buffer, 1);//BUFSIZ);
-  printf("%s", buffer);
-
-  close(s);
-  return 0;
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c	(revision 151)
+++ 	(revision )
@@ -1,240 +1,0 @@
-/*#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-*/
-/* define HOME to be dir for key and certificate files... */
-//#define HOME "/usr/local/ssl/"
-/* Make these what you want for certificate & key files */
-//#define CERT_FILE "mycert.pem"
-//#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-//#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-//#define CA_FILE CERT_FILE
-//#define CA_DIR  NULL
-
-/*Password for the key file*/
-//#define KEY_PASSWD ""
-
-//#define IP "im.celepar.parana"
-
-//#define PORT "5222"
-
-#include "server.h"
-
-
-int main(void)
-{
-int socketfd, nHostPort;
-   int err;
-   char buff[32];
-struct sockaddr_in socketaddr;
-
-/*SSL PART*/
-SSL_METHOD *meth;
-SSL_CTX  *ctx;
-SSL  *myssl;
-/*SSL PART*/
-
-   /* if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-    {
-       printf("\n<port>\n\n");
-       printf("\ncould not make a socket\n");
-       return 0;
-    }*/
-
-   socketfd=socket(AF_INET,SOCK_STREAM,0);
-
-socketaddr.sin_family=AF_INET;
-inet_aton("127.0.0.1", &socketaddr.sin_addr);
-socketaddr.sin_port=htons(8888);
-
-/* Connect to the server, TCP/IP layer,*/
-   err=connect(socketfd,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
-   if(err<0){
-      printf("Socket returned error #%d,program terminated\n", err);
-      exit(0);
-   }
-
-   /* SSL Part*/
-	OpenSSL_add_all_algorithms();
-SSL_library_init();
-SSL_load_error_strings();
-
-
-   meth=TLSv1_client_method();
-  
-   ctx=SSL_CTX_new(meth);
-   if (!ctx) {
-    printf("Error creating the context.\n");
-    exit(0);
-}
-
-/*
-   if (SSL_CTX_set_cipher_list(ctx,CIPHER_LIST) <= 0) {
-printf("Error setting the cipher list.\n");
-exit(0);
-}
-*/
-   /*Indicate the certificate file to be used*/
-  /* if (SSL_CTX_use_certificate_file(ctx,CERT_FILE, SSL_FILETYPE_PEM) <= 0) {
-   printf("Error setting the certificate file.\n");
-   exit(0);
-}*/
-
-
-
-/*Load the password for the Private Key*/
-   //SSL_CTX_set_default_passwd_cb_userdata(ctx,KEY_PASSWD);
-
-
-/*Indicate the key file to be used*/
-/*if (SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) <= 0) {
-printf("Error setting the key file.\n");
-exit(0);
-}*/
-
-/*Make sure the key and certificate file match*/
-/*if (!SSL_CTX_check_private_key(ctx)) {
-    printf("Private key does not match the certificate public key\n");
-    exit(0);
-}*/
-
-/* Set the list of trusted CAs based on the file and/or directory provided*/
-/*   if(SSL_CTX_load_verify_locations(ctx,CA_FILE,CA_DIR)<1){
-            printf("Error setting verify location\n");
-            exit(0);
-   }*/
-
-/* Set for server verification*/
-//   SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL);
-   SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-
-/*Create new ssl object*/
-myssl=SSL_new(ctx);
-
-   if(!myssl){
-      printf("Error creating SSL structure.\n");
-      exit(0);
-   }
-
-/*Bind the socket to the SSL structure*/
-SSL_set_fd(myssl,socketfd);
-
-/*Connect to the server, SSL layer.*/
-err=SSL_connect(myssl);
-      printf("SSL error #%d in accept,program terminated\n",err);
-   /*Check for error in connect.*/
-if (err<1) {
-
-      err=SSL_get_error(myssl,err);
-      printf("SSL error #%d in accept,program terminated\n",err);
-
-      if(err==5){printf("sockerrno is:\n");}
-
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-
-/*Print out connection details*/
-   printf("SSL connection on socket %x,Version: %s, Cipher: %s\n",
-      socketfd,
-   SSL_get_version(myssl),
-SSL_get_cipher(myssl));
-
-puts("_________OK_______________");
-exit(0);
-/*Send message to the server.*/
-   err=SSL_write(myssl,"Hello there!!!!",sizeof("Hello there!!!!")+1);
-   /*Check for error in write.*/
-   if(err<1){
-      err=SSL_get_error(myssl,err);
-      printf("Error #%d in write,program terminated\n",err);
-      /********************************/
-      /* If err=6 it means the client */
-      /* issued an SSL_shutdown. You  */
-      /* must respond with a shutdown */
-      /* to complete a graceful       */
-      /* shutdown                     */
-      /********************************/
-      if(err==6){
-         SSL_shutdown(myssl);
-      }
-      SSL_free(myssl);
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-
-/*Read servers response.*/
-   err = SSL_read (myssl, buff, sizeof(buff));
-   /*Check for error in read.*/
-   if(err<1){
-      err=SSL_get_error(myssl,err);
-      printf("Error #%d in read,program terminated\n",err);
-      /********************************/
-      /* If err=6 it means the client */
-      /* issued an SSL_shutdown. You  */
-      /* must respond with a shutdown */
-      /* to complete a graceful       */
-      /* shutdown                     */
-      /********************************/
-      if(err==6){
-         SSL_shutdown(myssl);
-      }
-      SSL_free(myssl);
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-   printf("Server said: %s\n",buff);
-   err=SSL_shutdown(myssl);
-	buff[0] = '\0';
-   SSL_read (myssl, buff, sizeof(buff));
-   /*********************************/
-   /* If err is equal to 0 you are  */
-   /* issuing the shutdown first.   */
-   /* If its 1 then you are         */
-   /* responding to a previously    */
-   /* issued shutdown message       */
-   /*********************************/
-   if(err==0)
-	{
-      err=SSL_shutdown(myssl);
-		buff[0] = '\0';
-	   SSL_read (myssl, buff, sizeof(buff));
-      if(err<1){
-         printf("#1 Error in shutdown\n");
-      }else if(err==1){
-         printf("Client exited gracefully\n");
-      }
-   }else if(err<0){
-         printf("Error in shutdown\n");
-
-   }else if(err==1){
-      printf("Client exited gracefully\n");
-   }
-   close(socketfd);
-SSL_free(myssl);
-SSL_CTX_free(ctx);
-   exit(0);
-
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_24092007.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_24092007.h	(revision 151)
+++ 	(revision )
@@ -1,66 +1,0 @@
-#include <fcntl.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 10
-#endif
-
-#define SOCKET_ERROR        -1
-#define BUFFER_SIZE         4096
-#define MESSAGE             "This is the message I'm sending back and forth"
-#define QUEUE_SIZE          5
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/mycert.pem
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/mycert.pem	(revision 151)
+++ 	(revision )
@@ -1,34 +1,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDY8Tao9bylsCI6LVR8yWWO7HgfnQQCwh2cqigKHaSnuo5n67R5
-Cp7dAbYkVf1V7BZ+V3nn7eVQ2FXcb8BooBQY51J9j7Q75IT5AZRar1ket5pRnVJH
-THGpm8trQsP54gV14lRToI36zXFzxakR08B1iKRyyLUVwp8RvAUxS+kKHwIDAQAB
-AoGAFIbWTixaOi8tPeX2HYyM0HYtc4hOzdgCJ0WuXi6p2rj7KngR7nYDzBOSYWPF
-gbDB/BhYz4oh7YFatm3Yfc3PuNLbuTxaMuuevDl9Qy+0cVI3FL7ban5jgEXMZVB8
-rgIfxmem8Kj7Eu/WtF/UJiz+epJQgrndlNtWJTWSDHoLRqkCQQD3lf4kRwiJJrAS
-Hj48/FVaR+0nvcEia7YsF44is8Yd++BG1tKNZZaKpdhssVA/9Pd+8hC9Sqzji+Mc
-ZXdbAoh1AkEA4FCeoH/ZfWZ3KfCyGfK6T2SEf3tJB/bleFg1mdmv9INuk6HSKMKW
-62mhxAk4DjcYcoM8QSeAE4FN7aOwB3OVwwJAeL/7qf/G5vUqbDu5yQ6cJiLsRDSk
-rD/yIkD+vmgFWPxOHt6I5BNGv6oxCpnT9M1po801Ysy302aXRnMqKgXrPQJBAMYG
-ZgNK2rXZv1lHI/PEVLXCBzaDn/VoASw8sxUfGDbD0NqEAQP6xUEN/8EQYmwqN2rg
-cFEUjfyqKiGgX8Y0RAECQGTEkKvhDzgyyphx5JkYem7sAUI7gFGKZxJaVU+KkN5e
-pU4pgNiFUT0uTbfFzzOYQKeyVlBqGiv7rVn3BO3pfV4=
------END RSA PRIVATE KEY-----
------BEGIN CERTIFICATE-----
-MIIDKzCCApSgAwIBAgIJAOkSDgQDK1oGMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkJSMQswCQYDVQQIEwJQUjEMMAoGA1UEBxMDQ1dCMQ0wCwYDVQQKEwRTQ0tU
-MQ0wCwYDVQQLEwRzY2t0MSUwIwYDVQQDExxlY2VsZXBhcjkxMTM3LmNlbGVwYXIu
-cGFyYW5hMB4XDTA3MDgwOTE2Mzg0MVoXDTA4MDgwODE2Mzg0MVowbTELMAkGA1UE
-BhMCQlIxCzAJBgNVBAgTAlBSMQwwCgYDVQQHEwNDV0IxDTALBgNVBAoTBFNDS1Qx
-DTALBgNVBAsTBHNja3QxJTAjBgNVBAMTHGVjZWxlcGFyOTExMzcuY2VsZXBhci5w
-YXJhbmEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANjxNqj1vKWwIjotVHzJ
-ZY7seB+dBALCHZyqKAodpKe6jmfrtHkKnt0BtiRV/VXsFn5Xeeft5VDYVdxvwGig
-FBjnUn2PtDvkhPkBlFqvWR63mlGdUkdMcamby2tCw/niBXXiVFOgjfrNcXPFqRHT
-wHWIpHLItRXCnxG8BTFL6QofAgMBAAGjgdIwgc8wHQYDVR0OBBYEFDqDGL/fTaKt
-NtkTuuzBet9mgcSOMIGfBgNVHSMEgZcwgZSAFDqDGL/fTaKtNtkTuuzBet9mgcSO
-oXGkbzBtMQswCQYDVQQGEwJCUjELMAkGA1UECBMCUFIxDDAKBgNVBAcTA0NXQjEN
-MAsGA1UEChMEU0NLVDENMAsGA1UECxMEc2NrdDElMCMGA1UEAxMcZWNlbGVwYXI5
-MTEzNy5jZWxlcGFyLnBhcmFuYYIJAOkSDgQDK1oGMAwGA1UdEwQFMAMBAf8wDQYJ
-KoZIhvcNAQEFBQADgYEAVHm/1+iybB3u48nP0NDIocPIhUC55e8iL9h0GOmvJalp
-IpCeIuefCTPCkrJHNMSVNqz6q3UfJLNXe91UdaAYvXEqWLP0mYUz5DWnzUYIIb/y
-W1BZ2WqcX8KZeJJgF/Gu0BJj5oGaf8LMVQoS58TiWgQABg1UTFHnHoXJhABQ1Qo=
------END CERTIFICATE-----
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_27092007.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_27092007.h	(revision 151)
+++ 	(revision )
@@ -1,102 +1,0 @@
-#include <fcntl.h>
-
-#include <linux/tcp.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-/* define max clients per child */
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 100
-#endif
-
-/* define max clients waiting in the queue for connect */
-#ifndef __QUEUE_SIZE__
-	#define __QUEUE_SIZE__ 10
-#endif
-
-/* __SOCKET_ERROR__ must be -1, don't change this */
-#ifndef __SOCKET_ERROR__
-	#define __SOCKET_ERROR__ -1
-#endif
-
-/* open port when this server is activated */
-#ifndef __DEFAULT_OPEN_PORT__
-	#define __DEFAULT_OPEN_PORT__ 8888
-#endif
-
-/* ip of jabber service */
-#ifndef __DEFAULT_JABBER_PORT__
-	#define __DEFAULT_JABBER_PORT__ 5222
-#endif
-
-/* port to connect on jabber service */
-#ifndef __DEFAULT_JABBER_IP__
-	#define __DEFAULT_JABBER_IP__ "10.15.20.202"
-#endif
-
-/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
-#ifndef __BUFFER_SIZE__
-	#define __BUFFER_SIZE__ 4096
-#endif
-
-#define MESSAGE			"This is the message I'm sending back and forth"
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-/* 0 -> false; 1 -> true */
-#ifndef __DEBUG__
-	#define __DEBUG__ 0
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/keepalive.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/keepalive.c	(revision 151)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-int main(void);
-
-int main()
-{
-	int s;
-	int optval;
-	socklen_t optlen = sizeof(optval);
-
-	/* Create the socket */
-	if((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
-		perror("socket()");
-		exit(EXIT_FAILURE);
-	}
-
-	/* Check the status for the keepalive option */
-	if(getsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen) < 0) {
-		perror("getsockopt()");
-		close(s);
-		exit(EXIT_FAILURE);
-	}
-	printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
-
-	/* Set the option active */
-	optval = 1;
-	optlen = sizeof(optval);
-	if(setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
-		perror("setsockopt()");
-		close(s);
-		exit(EXIT_FAILURE);
-	}
-	printf("SO_KEEPALIVE set on socket\n");
-
-	/* Check the status again */
-	if(getsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen) < 0) {
-		perror("getsockopt()");
-		close(s);
-		exit(EXIT_FAILURE);
-	}
-	printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
-
-	close(s);
-
-	exit(EXIT_SUCCESS);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server.c	(revision 151)
+++ 	(revision )
@@ -1,173 +1,0 @@
-#include "server.h"
-
-int main(int argc, char* argv[])
-{
-	/* handle to socket */
-	int hSocket = (int)NULL,
-		hServerSocket = (int)NULL;
-
-	int nAddressSize = sizeof(struct sockaddr_in);
-	int nHostPort = (int)NULL;
-	int err;
-
-	/* holds info about a machine */
-	struct hostent * pHostInfo = (struct hostent *)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in Address;
-
-	struct client * clients = (struct client *)NULL;
-	pthread_t threads;
-	//pthread_t clients;
-
-	system(__CLEAR_SCREEN__);
-
-	char * end = {"2"};
-	if ( argc != 2 || (nHostPort = strtol(argv[1], (char **)NULL, 10)) == 0 )
-	{
-		printf("\nCould not make a socket\n");
-		usage();
-	}
-
-	puts("\nStarting server");
-	puts("Making socket");
-
-	/* make a socket */
-	hServerSocket = socket(AF_INET, SOCK_STREAM, 0);
-	if ( hServerSocket == SOCKET_ERROR )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	/* fill address struct */
-	Address.sin_addr.s_addr = INADDR_ANY;
-	Address.sin_port = htons(nHostPort);
-	Address.sin_family = AF_INET;
-
-	printf("\nBinding to port %d...\n", nHostPort);
-
-	/* bind to a port */
-	if ( bind(hServerSocket, (struct sockaddr*)&Address, sizeof(Address)) == SOCKET_ERROR )
-	{
-		printf("\nCould not connect to host\n");
-		return 0;
-	}
-
-	/* get port number */
-	getsockname( hServerSocket, (struct sockaddr *) &Address,(socklen_t *)&nAddressSize);
-	printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", hServerSocket, ntohs(Address.sin_port));
-
-	printf("Server\n\
-			sin_family        = %d\n\
-			sin_addr.s_addr   = %d\n\
-			sin_port          = %d\n"
-			, Address.sin_family
-			, Address.sin_addr.s_addr
-			, ntohs(Address.sin_port)
-			);
-	printf("\nMaking a listen queue of %d elements", QUEUE_SIZE);
-
-	/* establish listen queue */
-	if ( listen(hServerSocket, QUEUE_SIZE) == SOCKET_ERROR )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		hSocket = accept(hServerSocket, (struct sockaddr*)&Address, (socklen_t *)&nAddressSize);
-
-		printf("%d\n\n", hSocket);
-
-		clients = (struct client *) malloc(sizeof(struct client));
-		clients->hSocket = hSocket;
-		clients->last = time(NULL);
-
-		pthread_create(&threads, NULL, handler, (void *)clients);
-		clients = (struct client *)NULL;
-		puts("jah era #5");
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char pBuffer[BUFFER_SIZE];
-    struct client * client = (struct client *)pClient;
-    int i = 0, err;
-	time_t last;
-
-    if ( close(client->hSocket) == SOCKET_ERROR )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-	printf("%d", client->hSocket);
-	//sin_addr.s_addr
-
-    fflush(stdin);
-    fflush(stdout);
-    pthread_exit(NULL);
-    /*
-	printf("\nGot a connection");
-
-	last = time(NULL);
-	while ( time(NULL) - client->last < 10 )
-	{
-		printf("%s\n\n", "teste");
-		sleep(1);
-	}
-
-	client->last = time(NULL);
-	*/
-
-    /**
-	 * number returned by read() and write() is the number of bytes
-     * read or written, with -1 being that an error occured
-     * write what we received back to the server
-	 **/
-
-    /*
-	strcpy(pBuffer, MESSAGE);
-    printf("\nSending \"%s\" to client\n",pBuffer);
-    write(client->hSocket, pBuffer, strlen(pBuffer)+1);
-	*/
-
-	/* read from socket into buffer */
-	/*read(client->hSocket, pBuffer, sizeof(pBuffer));
-
-	printf("Received from client: %s\n", pBuffer);
-
-    if ( strcmp(pBuffer, MESSAGE) == 0 )
-        printf("The messages match\n");
-    else
-        printf("Something was changed in the message\n");
-	*/
-
-    /*while (i < 10)
-    {
-		 printf("%d\n", i);
-		 usleep(1000000);
-		 i++;
-    }*/
-
-    /* close socket */
-    /*printf("\nClosing the socket");
-    if ( close(client->hSocket) == SOCKET_ERROR )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-	*/
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server.h	(revision 151)
+++ 	(revision )
@@ -1,101 +1,0 @@
-#include <fcntl.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-/* define max clients per child */
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 100
-#endif
-
-/* define max clients waiting in the queue for connect */
-#ifndef __QUEUE_SIZE__
-	#define __QUEUE_SIZE__ 10
-#endif
-
-/* __SOCKET_ERROR__ must be -1, don't change this */
-#ifndef __SOCKET_ERROR__
-	#define __SOCKET_ERROR__ -1
-#endif
-
-/* open port when this server is activated */
-#ifndef __DEFAULT_OPEN_PORT__
-	#define __DEFAULT_OPEN_PORT__ 8888
-#endif
-
-/* ip of jabber service */
-#ifndef __DEFAULT_JABBER_PORT__
-	#define __DEFAULT_JABBER_PORT__ 5222
-#endif
-
-/* port to connect on jabber service */
-#ifndef __DEFAULT_JABBER_IP__
-	#define __DEFAULT_JABBER_IP__ "10.15.20.219"
-#endif
-
-/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
-#ifndef __BUFFER_SIZE__
-	#define __BUFFER_SIZE__ 4096
-#endif
-
-#define MESSAGE			"This is the message I'm sending back and forth"
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-/* 0 -> false; 1 -> true */
-#ifndef __DEBUG__
-	#define __DEBUG__ 0
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/signal.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/signal.c	(revision 151)
+++ 	(revision )
@@ -1,37 +1,0 @@
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* This flag controls termination of the main loop.  */
-volatile sig_atomic_t keep_going = 1;
-
-/* The signal handler just clears the flag and re-enables itself.  */
-	void 
-catch_alarm (int sig)
-{
-	keep_going = 0;
-	puts("ALARM");
-	signal (sig, catch_alarm);
-}
-
-	void 
-do_stuff (void)
-{
-	puts ("Doing stuff while waiting for alarm....");
-}
-
-	int
-main (void)
-{
-	/* Establish a handler for SIGALRM signals.  */
-	signal (SIGALRM, catch_alarm);
-
-	/* Set an alarm to go off in a little while.  */
-	alarm (2);
-
-	/* Check the flag once in a while to see when to quit.  */
-	while (keep_going)
-		do_stuff ();
-
-	return EXIT_SUCCESS;
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client.c	(revision 151)
+++ 	(revision )
@@ -1,63 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#define IP "localhost"
-
-#define PORT "8888"
-
-int main(void)
-{
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-	int err,
-		i,
-		unit;
-	char buff[4096];
-	char * _xml = (char)NULL,
-		 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"};
-
-	_xml = (char *)malloc(sizeof(xml_connect));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	//printf("::: %d\n\n\n", fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & ~O_NONBLOCK ));
-	//printf("::: %d\n\n\n", fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & O_NONBLOCK ));
-
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	sprintf(_xml, xml_connect, "localhost");
-
-	write(socketfd, _xml, strlen(_xml));
-
-	read (socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c_bkp2
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c_bkp2	(revision 151)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/*#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-*/
-/* define HOME to be dir for key and certificate files... */
-//#define HOME "/usr/local/ssl/"
-/* Make these what you want for certificate & key files */
-//#define CERT_FILE "mycert.pem"
-//#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-//#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-//#define CA_FILE CERT_FILE
-//#define CA_DIR  NULL
-
-/*Password for the key file*/
-//#define KEY_PASSWD ""
-
-//#define IP "im.celepar.parana"
-
-//#define PORT "5222"
-
-#include "server.h"
-
-
-int main(void)
-{
-	int jabber_fd       = (int)NULL,
-		jabber_port     = (int)NULL,
-		jabber_error    = (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	printf("Socket %d\n", jabber_fd);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-	printf("Socket returned error #%d, ip = %s and port = %d, program terminated\n", jabber_error, __DEFAULT_JABBER_IP__, __DEFAULT_JABBER_PORT__);
-
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/proxy.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/proxy.c	(revision 151)
+++ 	(revision )
@@ -1,588 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-#include <syslog.h>
-
-/* Buffer size, in bytes, used for copying in the Cat() function. */
-const size_t BUF_SIZE = 10240;
-
-/* Typedef for a signal handler function. */
-typedef void (*signal_handler_t) (int);
-
-/* Prototypes for functions in this file. */
-void ParseArgs (int argc, char *argv[], struct in_addr *ra,
-		unsigned short *rp, struct in_addr *la, unsigned short *lp);
-void Initialise (void);
-void sig_child (int signo);
-int CreateServerSocket (struct in_addr addr, unsigned short port);
-void Daemonise (void);
-void MainLoop (int listen_fd, struct in_addr rem_addr,
-		unsigned short rem_port);
-void Proxy (int server_fd, int client_fd);
-int AcceptClientConnection (int listen_fd);
-int ConnectToServer (struct in_addr addr, unsigned short port);
-void Cat (int in_fd, int out_fd);
-int NameToAddr (const char *name, struct in_addr *p_inaddr);
-int NameToPort (const char *name, unsigned short *port, const char *proto);
-#ifdef __GNUC__
-void quit (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
-void pbomb (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
-void hbomb (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
-#else
-void quit (const char *fmt, ...);
-void pbomb (const char *fmt, ...);
-void hbomb (const char *fmt, ...);
-#endif
-void set_signal_handler (int signum, signal_handler_t sig_handler_func);
-
-/* Global variables */
-char g_program_name[100];       /* Initialised from argv[0] in ParseArgs() */
-
-	int
-main (int argc, char *argv[])
-{
-	struct in_addr remote_addr, local_addr;
-	unsigned short remote_port, local_port;
-	int listen_fd;
-
-	ParseArgs (argc, argv, &remote_addr, &remote_port, &local_addr,
-			&local_port);
-
-	Initialise ();
-
-	/* Create server socket before becoming a daemon so there is still a
-	 *      chance to print an error message. */
-	listen_fd = CreateServerSocket (local_addr, local_port);
-	if (listen_fd < 0)
-		pbomb ("Unable to create server socket");
-
-	Daemonise ();
-
-	MainLoop (listen_fd, remote_addr, remote_port);       /* never returns */
-
-	exit (EXIT_SUCCESS);
-}
-
-/* ParseArgs(): Parse the command line arguments to extract the remote and
- *  * local adresses and port numbers, ra, rp, la & lp.  Exit the program
- *   * gracefully upon error.
- *    */
-	void
-ParseArgs (int argc, char *argv[], struct in_addr *ra, unsigned short *rp,
-		struct in_addr *la, unsigned short *lp)
-{
-	/*
-	 *    * argv[0] = program name
-	 *       * argv[1] = remote_addr
-	 *          * argv[2] = remote_port
-	 *             * argv[3] = local_addr (optional)
-	 *                * argv[4] = local_port (optional)
-	 *                   */
-
-	char *p = strrchr (argv[0], '/');
-
-	strncpy (g_program_name, (p == NULL) ? argv[0] : p + 1,
-			sizeof (g_program_name) - 1);
-
-	if ((argc < 3) || (argc > 5))
-	{
-		fprintf (stderr,
-				"usage: %s remote_addr remote_port [local_addr] [local_port]\n",
-				argv[0]);
-		exit (EXIT_FAILURE);
-	}
-
-	if (NameToAddr (argv[1], ra))
-		hbomb ("Unable to resolve \"%s\" to an ip address", argv[1]);
-
-	if (NameToPort (argv[2], rp, "tcp"))
-		quit ("Unable to resolve \"%s\" to a port number", argv[2]);
-
-	if (argc < 4)
-		la->s_addr = htonl (INADDR_ANY);
-	else if (NameToAddr (argv[3], la))
-		hbomb ("Unable to resolve \"%s\" to an ip address", argv[3]);
-
-	if (argc < 5)
-		memcpy (lp, rp, sizeof (*lp));
-	else if (NameToPort (argv[4], lp, "tcp"))
-		quit ("Unable to resolve \"%s\" to a port number", argv[4]);
-}
-
-/* Initialise(): Setup syslog, signal handlers, and other intialisation.
- *  */
-	void
-Initialise (void)
-{
-	openlog (g_program_name, LOG_PID, LOG_USER);
-	syslog (LOG_INFO, "%s started", g_program_name);
-
-	chdir ("/");                  /* Change working directory to the root. */
-
-	umask (0);                    /* Clear our file mode creation mask */
-
-	set_signal_handler (SIGCHLD, sig_child);
-
-	signal (SIGPIPE, SIG_IGN);
-}
-
-/* sig_child(): Handles SIGCHLD from exiting child processes.
- *  */
-	void
-sig_child (int signo)
-{
-	pid_t pid;
-
-	(void) signo;                 /* suppress compiler warning */
-
-	puts("AKI....................");
-	for (;;)
-	{
-		pid = waitpid (WAIT_ANY, NULL, WNOHANG);
-
-		if (pid > 0)
-			syslog (LOG_INFO, "Caught SIGCHLD from pid %d", pid);
-		else
-			break;
-	}
-
-	if ((pid < 0) && (errno != ECHILD))
-		syslog (LOG_ERR, "waitpid(): %m"), exit (EXIT_FAILURE);
-
-	return;
-}
-
-/* CreateServerSocket(): Create a socket, bind it to the specified address
- *  * and port, and set it to listen for client connections.  Returns <0 on
- *   * failure to bind, bombs on error otherwise, returns the fd of the new
- *    * socket on success.
- *     */
-	int
-CreateServerSocket (struct in_addr addr, unsigned short port)
-{
-	int err, fd;
-	const int on = 1;
-	struct sockaddr_in sa;
-
-	/* Create a socket and get its descriptor. */
-	fd = socket (AF_INET, SOCK_STREAM, 0);
-	if (fd < 0)
-		syslog (LOG_ERR, "socket(): %m"), exit (EXIT_FAILURE);
-
-	/* Set SO_REUSEADDR socket option */
-	if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
-		syslog (LOG_ERR, "setsockopt(fd%d, SO_REUSEADDR): %m", fd);
-
-	/* Load a sa structure with the specified address and port */
-	sa.sin_family = AF_INET;
-	sa.sin_port = htons (port);
-	sa.sin_addr = addr;
-	memset (sa.sin_zero, 0, sizeof (sa.sin_zero));
-
-	/* Bind our socket to the address and port specified */
-	err = bind (fd, (struct sockaddr *) &sa, sizeof (sa));
-	if (err < 0)
-	{
-		syslog (LOG_ERR, "bind(): %m");
-		return err;
-	}
-
-	/* Tell socket to listen and queue up to 5 incoming connections. */
-	if (listen (fd, 5) < 0)
-		syslog (LOG_ERR, "listen(): %m"), exit (EXIT_FAILURE);
-
-	return fd;
-}
-
-/* Daemonise(): Put the program in the background, set PPID=1, create a new
- *  * session and process group, without a controlling tty.
- *   */
-	void
-Daemonise (void)
-{
-	pid_t pid;
-
-	/* Close stdin, stdout & stderr */
-	/* TODO: open /dev/null and dup the fd to stdin, stdout & stderr
-	 *      close(STDIN_FILENO);
-	 *           close(STDOUT_FILENO);
-	 *                close(STDERR_FILENO);
-	 *                   */
-
-	syslog (LOG_INFO, "%s daemonising", g_program_name);
-
-	/* Fork the process to put it in the background. */
-
-	pid = fork ();
-	if (pid == -1)
-		syslog (LOG_ERR, "fork(): %m"), exit (EXIT_FAILURE);
-
-	/* parent terminates here, so shell thinks the command is done. */
-	if (pid)
-		exit (0);
-
-	syslog (LOG_INFO, "%s in background", g_program_name);
-
-	/* 1st child continues to run in the background with PPID=1 */
-
-	/* Become leader of a new session and a new process group,
-	 *      with no controlling tty.  */
-	setsid ();
-
-	/* Fork again to guarantee the process will not be able to aquire a
-	 *      controlling tty. */
-
-	/*signal (SIGHUP, SIG_IGN); *//* required according to Stevens' UNP2 p333 */
-
-	pid = fork ();
-	if (pid == -1)
-		syslog (LOG_ERR, "fork(): %m"), exit (EXIT_FAILURE);
-
-	if (pid)                      /* 1st child terminates */
-		exit (0);
-
-	/* 2nd child continues, no longer a session or group leader */
-
-	syslog (LOG_INFO, "%s daemonised", g_program_name);
-}
-
-/* MainLoop(): Classic concurrent server model. Wait for a client to connect,
- *  * fork a child process to do the business with the client, parent process
- *   * continues to wait for the next connection.  This function does not return.
- *    */
-	void
-MainLoop (int listen_fd, struct in_addr rem_addr, unsigned short rem_port)
-{
-	int server_fd, client_fd;
-	pid_t child_pid;
-
-	for (;;)
-	{
-		client_fd = AcceptClientConnection (listen_fd);
-
-		child_pid = fork ();
-		if (child_pid == -1)
-			syslog (LOG_ERR, "fork(): %m"), exit (EXIT_FAILURE);
-
-		if (child_pid)            /* parent */
-		{
-			close (client_fd);
-
-			syslog (LOG_INFO, "Forked child pid %d to deal with client",
-					child_pid);
-
-			continue;
-		}
-		else                      /* child */
-		{
-			close (listen_fd);
-
-			server_fd = ConnectToServer (rem_addr, rem_port);
-
-			Proxy (server_fd, client_fd);
-
-			syslog (LOG_INFO, "exiting");
-			_exit (0);
-		}
-	}
-}
-
-/* Proxy(): Copies data between server_fd and client_fd in both directions
- *  * until one or other peer closes their connection.
- *   */
-	void
-Proxy (int server_fd, int client_fd)
-{
-	pid_t helper_pid;
-
-	syslog (LOG_INFO, "Proxy(fd%d, fd%d)", server_fd, client_fd);
-
-	signal (SIGCHLD, SIG_IGN);
-
-	helper_pid = fork ();
-	if (helper_pid == -1)
-		syslog (LOG_ERR, "fork(): %m"), exit (EXIT_FAILURE);
-
-	if (helper_pid)               /* parent */
-	{
-		syslog (LOG_INFO, "Forked child pid %d to help with proxying",
-				helper_pid);
-
-		Cat (server_fd, client_fd);
-
-		shutdown (client_fd, 1);
-		close (server_fd);
-		close (client_fd);
-
-		wait (0);                 /* wait for helper to exit */
-	}
-	else                          /* child (helper) */
-	{
-		Cat (client_fd, server_fd);
-
-		shutdown (server_fd, 1);
-
-		syslog (LOG_INFO, "exiting");
-		exit (0);                 /* helper exits here */
-	}
-}
-
-/* AcceptClientConnection(): waits for a tcp connect to the socket listen_fd,
- *  * which must already be bound and set to listen on a local port.  Bombs on
- *   * error, returns the fd of the new socket on success.
- *    */
-	int
-AcceptClientConnection (int listen_fd)
-{
-	int newfd;
-	struct sockaddr_in sa;
-	socklen_t socklen;
-
-	syslog (LOG_INFO, "AcceptClientConnection(fd%d)", listen_fd);
-
-	/* Accept the connection and create a new socket for it. */
-	socklen = sizeof (sa);
-	memset (&sa, 0, socklen);
-	do
-	{
-		newfd = accept (listen_fd, (struct sockaddr *) &sa, &socklen);
-	}
-	while ((newfd < 0) && (errno == EINTR));
-
-	syslog (LOG_INFO, "Accepted client connection on new socket fd%d", newfd);
-
-	if (newfd < 0)
-		syslog (LOG_ERR, "accept(): %m"), exit (EXIT_FAILURE);
-
-	if (socklen != sizeof (sa))
-		syslog (LOG_ERR, "accept() screwed up!"), exit (EXIT_FAILURE);
-
-	return (newfd);
-}
-
-/* ConnectToServer(): attempts a tcp connect to the server specified by addr
- *  * and port.  Bombs on failure to connect, returns the fd of the new socket
- *   * on success.
- *    */
-	int
-ConnectToServer (struct in_addr addr, unsigned short port)
-{
-	/* TODO: have a timeout for connect() - see Unix socket FAQ 6.2 */
-
-	int fd, err;
-	struct sockaddr_in sa;
-
-	/* Create a socket and get its descriptor. */
-	fd = socket (AF_INET, SOCK_STREAM, 0);
-	if (fd < 0)
-		syslog (LOG_ERR, "socket(): %m"), exit (EXIT_FAILURE);
-
-	sa.sin_family = AF_INET;
-	sa.sin_port = htons (port);
-	sa.sin_addr = addr;
-	memset (sa.sin_zero, 0, sizeof (sa.sin_zero));
-
-	err = connect (fd, (struct sockaddr *) &sa, sizeof (sa));
-	if (err < 0)
-	{
-		syslog (LOG_ERR, "Unable to connect socket fd%d to server: %m", fd);
-		exit (EXIT_FAILURE);
-	}
-
-	syslog (LOG_INFO, "Connected socket fd%d to server", fd);
-
-	return fd;
-}
-
-/* Cat(): read data from in_fd and write it to out_fd until the connection is
- *  * closed by one of the peers.  Data is copied using a dynamically allocated
- *   * buffer.
- *    */
-	void
-Cat (int in_fd, int out_fd)
-{
-	unsigned char *const buf = malloc (BUF_SIZE);
-	int bytes_rcvd, bytes_sent = 0, i;
-
-	syslog (LOG_INFO, "Cat(fd%d, fd%d)", in_fd, out_fd);
-
-	if (buf == NULL)
-		syslog (LOG_ERR, "malloc(): %m"), exit (EXIT_FAILURE);
-
-	do
-	{
-		bytes_rcvd = recv (in_fd, buf, BUF_SIZE, 0);
-
-		for (i = 0; i < bytes_rcvd; i += bytes_sent)
-		{
-			bytes_sent = send (out_fd, buf + i, bytes_rcvd - i, 0);
-
-			if (bytes_sent < 0)
-				break;
-		}
-
-	}
-	while ((bytes_rcvd > 0) && (bytes_sent > 0));
-
-	if ((bytes_rcvd < 0) && (errno != ECONNRESET))
-		syslog (LOG_ERR, "recv(): %m"), exit (EXIT_FAILURE);
-
-	if ((bytes_sent < 0) && (errno != EPIPE))
-		syslog (LOG_ERR, "send(): %m"), exit (EXIT_FAILURE);
-
-	free (buf);
-}
-
-/* NameToAddress(): Convert name to an ip address.  Returns 0 on success,
- *  * -1 on failure.
- *   */
-	int
-NameToAddr (const char *name, struct in_addr *p_inaddr)
-{
-	struct hostent *he;
-
-	/* First, attempt to convert from string ip format */
-	/* TODO: use inet_aton() instead */
-	p_inaddr->s_addr = inet_addr (name);
-	if (p_inaddr->s_addr != -1U)  /* Success */
-		return 0;
-
-	/* Next, attempt to read from /etc/hosts or do a DNS lookup */
-	he = gethostbyname (name);
-	if (he != NULL)               /* Success */
-	{
-		memcpy (p_inaddr, he->h_addr, sizeof (struct in_addr));
-		return 0;
-	}
-
-	return -1;                    /* Failed to resolve name to an ip address */
-}
-
-/* NameToPort(): Convert name to a port number. Name can either be a port
- *  * name (in which case proto must also be set to either "tcp" or "udp") or
- *   * name can be the ascii representation of the port number.  Returns 0 on
- *    * success, -1 on failure.
- *     */
-	int
-NameToPort (const char *name, unsigned short *port, const char *proto)
-{
-	unsigned long lport;
-	char *errpos;
-	struct servent *se;
-
-	/* First, attempt to convert string to integer */
-	lport = strtoul (name, &errpos, 0);
-	if ((*errpos == 0) && (lport <= 65535))       /* Success */
-	{
-		*port = lport;
-		return 0;
-	}
-
-	/* Next, attempt to read the string from /etc/services */
-	se = getservbyname (name, proto);
-	if (se != NULL)               /* Success */
-	{
-		*port = ntohs (se->s_port);
-		return 0;
-	}
-
-	return -1;                    /* Failed to resolve port name to a number */
-}
-
-/* quit(), pbomb(), hbomb(): Print an error message to stderr and syslog, then
- *  * exit the program.  pbomb() and hbomb() additionally include the string
- *   * representation of errno and h_errno respectively.
- *    */
-	void
-quit (const char *fmt, ...)     /* quit with msg */
-{
-	va_list ap;
-
-	fflush (stdout);
-
-	fprintf (stderr, "%s: ", g_program_name);
-
-	va_start (ap, fmt);
-	vfprintf (stderr, fmt, ap);
-	va_end (ap);
-
-	fputc ('\n', stderr);
-
-	syslog (LOG_ERR, "I quit!");
-
-	exit (EXIT_FAILURE);
-}
-
-	void
-pbomb (const char *fmt, ...)    /* bomb with perror */
-{
-	va_list ap;
-	int errno_save = errno;
-	char buf[100];
-
-	fflush (stdout);
-
-	fprintf (stderr, "%s: ", g_program_name);
-
-	va_start (ap, fmt);
-	vsnprintf (buf, sizeof (buf), fmt, ap);
-	va_end (ap);
-
-	errno = errno_save;
-	perror (buf);
-
-	syslog (LOG_ERR, "Bang!: %s: %m", buf);
-
-	exit (EXIT_FAILURE);
-}
-
-	void
-hbomb (const char *fmt, ...)    /* bomb with herror */
-{
-	va_list ap;
-	int h_errno_save = h_errno;
-	char buf[100];
-
-	fflush (stdout);
-
-	fprintf (stderr, "%s: ", g_program_name);
-
-	va_start (ap, fmt);
-	vsnprintf (buf, sizeof (buf), fmt, ap);
-	va_end (ap);
-
-	h_errno = h_errno_save;
-	herror (buf);
-
-	syslog (LOG_ERR, "Bang!: %s: %s", buf, hstrerror (h_errno));
-
-	exit (EXIT_FAILURE);
-}
-
-/* set_signal_handler(): Sets a signal handler function.  Similar to signal()
- *  * but this method is more portable between platforms.
- *   */
-	void
-set_signal_handler (int signum, signal_handler_t sa_handler_func)
-{
-	struct sigaction act;
-
-	act.sa_handler = sa_handler_func;
-	sigemptyset (&(act.sa_mask));
-	act.sa_flags = 0;
-
-	if (sigaction (signum, &act, NULL) < 0)
-	{
-		syslog (LOG_ERR, "Error setting handler for signal %d: %m", signum);
-		exit (EXIT_FAILURE);
-	}
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/rand.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/rand.c	(revision 151)
+++ 	(revision )
@@ -1,39 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-/*
-
-#define MAX 10000
-
-int main(void)
-{
-	int i = (int)NULL;
-	int j =i;
-	long int vet[MAX];
-
-	for ( i = 0; i < MAX; ++i )
-	{
-		vet[i] = rand();
-		for ( j = 0; j < i; ++j )
-			if ( vet[i] == vet[j] )
-				printf("[%d]%d - [%d]%d\n", i, vet[i], j, vet[j]);
-	}
-	printf("rand_max: %d\n", RAND_MAX);
-	printf("time: %d\n", time(NULL));
-	printf("rand: %d\n", rand(1));
-}
-*/
-
-main(int ac, char **av)
-{
-	double x;
-	unsigned seed;
-
-	if (ac > 0) {
-		sscanf(microtime,"%u", &seed);
-		srand(seed);
-	}
-
-	x = rand()/(RAND_MAX+1.0);
-
-	printf("%g\n",x);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/teste_ldap.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/teste_ldap.c	(revision 151)
+++ 	(revision )
@@ -1,71 +1,0 @@
-#include <stdio.h>
-#include <ldap.h>
-
-int main(void)
-{
-	LDAP            *ld;
-	LDAPMessage     *res, *e;
-	int             i, rc;
-	char            *a, *dn;
-	BerElement      *ptr;
-	char            **vals;
-
-	/* open an LDAP session */
-	if ( (ld = ldap_init( "ldap.eparana.parana", 389 )) == NULL )
-	{
-		fprintf( stderr, "erro ao se conectar:");
-		return 1;
-	}
-
-	/* authenticate as nobody */
-	if (( rc = ldap_simple_bind_s( ld, NULL, NULL )) != LDAP_SUCCESS )
-	{
-		fprintf( stderr, "ldap_simple_bind_s: %s\n", ldap_err2string( rc ));
-		ldap_unbind( ld );
-		return 1;
-	}
-
-	/* search for entries with cn of "Babs Jensen", return all attrs  */
-	if (( rc = ldap_search_s( ld, "dc=pr, dc=gov, dc=br", LDAP_SCOPE_SUBTREE, "(uid=alexandrecorreia)", NULL, 0, &res )) != LDAP_SUCCESS )
-	{
-		fprintf( stderr, "ldap_search_s: %s\n", ldap_err2string( rc ));
-		if ( res == NULL )
-		{
-			ldap_unbind( ld );
-			return 1;
-		}
-	}
-
-	/* step through each entry returned */
-	for ( e = ldap_first_entry( ld, res ); e != NULL; e = ldap_next_entry( ld, e ) )
-	{
-		/* print its name */
-		dn = ldap_get_dn( ld, e );
-		printf( "uid: %s\n", dn );
-		ldap_memfree( dn );
-
-		/* print each attribute */
-		for ( a = ldap_first_attribute( ld, e, &ptr ); a != NULL; a = ldap_next_attribute( ld, e, ptr ) )
-		{
-			printf( "\tattribute: %s\n", a );
-
-			/* print each value */
-			vals = ldap_get_values( ld, e, a );
-
-			for ( i = 0; vals[i] != NULL; i++ )
-				printf( "\t\tvalue: %s\n", vals[i] );
-
-			ldap_value_free( vals );
-			ldap_memfree( a );
-		}
-		if ( ptr != NULL )
-			ber_free( ptr, 0 );
-	}
-	/* free the search results */
-	ldap_msgfree( res );
-
-	/* close and free connection resources */
-	ldap_unbind( ld );
-
-	return 0;
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_tls.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_tls.c	(revision 151)
+++ 	(revision )
@@ -1,247 +1,0 @@
-#include "server.h"
-
-int main(int argc, char* argv[])
-{
-	/* handle to socket */
-	int hSocket = (int)NULL,
-		hServerSocket = (int)NULL;
-
-	int nAddressSize = sizeof(struct sockaddr_in);
-	int nHostPort = (int)NULL;
-	int err;
-
-	/* holds info about a machine */
-	struct hostent * pHostInfo = (struct hostent *)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in Address;
-
-	struct client * clients = (struct client *)NULL;
-	pthread_t threads;
-	//pthread_t clients;
-
-	SSL_CTX * ctx;
-	SSL * myssl;
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-
-	if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	if ( SSL_CTX_set_cipher_list(ctx, CIPHER_LIST) < 1 )
-	{
-		printf("Error setting the cipher list.\n");
-		exit(0);
-	}
-
-	/*Indicate the certificate file to be used*/
-	if ( SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the certificate file.\n");
-		exit(0);
-	}
-
-	/*Load the password for the Private Key*/
-	SSL_CTX_set_default_passwd_cb_userdata(ctx, KEY_PASSWD);
-
-	/*Indicate the key file to be used*/
-	if ( SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the key file.\n");
-		exit(0);
-	}
-
-	/*Make sure the key and certificate file match*/
-	if ( !SSL_CTX_check_private_key(ctx) )
-	{
-		printf("Private key does not match the certificate public key\n");
-		exit(0);
-	}
-
-	/* Set the list of trusted CAs based on the file and/or directory provided*/
-	if ( SSL_CTX_load_verify_locations(ctx, CA_FILE, CA_DIR) < 1 )
-	{
-		printf("Error setting verify location\n");
-		exit(0);
-	}
-
-	/* Set for server verification*/
-	SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
-
-	if ( argc != 2 || (nHostPort = strtol(argv[1], 0, 10)) == 0 )
-	{
-		printf("\n<PORT>\n\n");
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	printf("\nStarting server");
-	printf("\nMaking socket");
-
-	/* make a socket */
-	hServerSocket = socket(AF_INET, SOCK_STREAM, 0);
-	if ( hServerSocket == SOCKET_ERROR )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	/* fill address struct */
-	Address.sin_addr.s_addr = INADDR_ANY;
-	Address.sin_port = htons(nHostPort);
-	Address.sin_family = AF_INET;
-
-	printf("\nBinding to port %d", nHostPort);
-
-	/* bind to a port */
-	if ( bind(hServerSocket, (struct sockaddr*)&Address, sizeof(Address)) == SOCKET_ERROR )
-	{
-		printf("\nCould not connect to host\n");
-		return 0;
-	}
-
-	/* get port number */
-	getsockname( hServerSocket, (struct sockaddr *) &Address,(socklen_t *)&nAddressSize);
-	printf("opened socket as fd (%d) on port (%d) for stream i/o\n", hServerSocket, ntohs(Address.sin_port));
-
-	printf("Server\n\
-			sin_family        = %d\n\
-			sin_addr.s_addr   = %d\n\
-			sin_port          = %d\n"
-			, Address.sin_family
-			, Address.sin_addr.s_addr
-			, ntohs(Address.sin_port)
-			);
-	printf("\nMaking a listen queue of %d elements", QUEUE_SIZE);
-
-	/* establish listen queue */
-	if ( listen(hServerSocket, QUEUE_SIZE) == SOCKET_ERROR )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		fflush(stdin);
-		fflush(stdout);
-		///printf("\nWaiting for a connection\n");
-		puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		hSocket = accept(hServerSocket, (struct sockaddr*)&Address, (socklen_t *)&nAddressSize);
-		clients = (struct client *) malloc(sizeof(struct client));
-		clients->hSocket = hSocket;
-
-		/*Create new ssl object*/
-		if( !(clients->myssl = SSL_new(ctx)) )
-		{
-			printf("Error creating SSL structure.\n");
-			exit(0);
-		}
-
-		/*Bind the socket to the SSL structure*/
-		SSL_set_fd(clients->myssl, hSocket);
-
-		puts("_____TESTE______");
-		/*Connect to the server, SSL layer.*/
-		err = SSL_accept(clients->myssl);
-		puts("_____TESTE______");
-
-		/*Check for error in connect.*/
-		if ( err < 1 )
-		{
-			printf("SSL error #%d in accept,program terminated\n", err);
-			err = SSL_get_error(clients->myssl, 0);
-			printf("SSL error #%d in accept,program terminated\n", err);
-
-			switch ( err )
-			{
-				case SSL_ERROR_NONE : puts("SSL_ERROR_NONE");break;
-				case SSL_ERROR_SSL : puts("SSL_ERROR_SSL");break;
-				case SSL_ERROR_WANT_READ : puts("SSL_ERROR_WANT_READ");
-			}
-
-			if ( err == 5 )
-				printf("sockerrno is: %d\n", err);
-
-
-			close(hSocket);
-			SSL_CTX_free(ctx);
-			exit(0);
-		}
-
-		//clients->myssl = myssl;
-		pthread_create(&threads, NULL, handler, (void *)clients);
-		clients = (struct client *)NULL;
-	}
-	pthread_exit(NULL);
-	puts("FIM LAssO");
-}
-
-void * handler(void * pClient)
-{
-    char pBuffer[BUFFER_SIZE];
-    struct client * client = (struct client *)pClient;
-    int i = 0, err;
-
-    printf("\nGot a connection");
-    strcpy(pBuffer,MESSAGE);
-    printf("\nSending \"%s\" to client",pBuffer);
-
-    /* number returned by read() and write() is the number of bytes
-    ** read or written, with -1 being that an error occured
-    ** write what we received back to the server */
-    //write(client->hSocket, pBuffer, strlen(pBuffer)+1);
-    err=SSL_write(client->myssl, pBuffer, strlen(pBuffer)+1);
-	 printf("-------%s\n\n", pBuffer);
-
-
-    /* read from socket into buffer */
-    //read(client->hSocket, pBuffer, BUFFER_SIZE);
-	 err = SSL_read(client->myssl, pBuffer, BUFFER_SIZE);
-
-	 printf("-------%s\n\n", pBuffer);
-
-    if ( strcmp(pBuffer, MESSAGE) == 0 )
-        printf("\nThe messages match");
-    else
-        printf("\nSomething was changed in the message");
-
-    while (i < 10)
-    {
-		 printf("%d\n", i);
-		 usleep(1000000);
-		 i++;
-    }
-
-    printf("\nClosing the socket");
-
-	 /*pBuffer[0] = '\0';
-	 printf("\n\nread = %s\n\nsd = %d\n\n\n", pBuffer, SSL_get_shutdown(client->myssl));
-	 SSL_shutdown(client->myssl);
-	 pBuffer[0] = '\0';
-	 printf("\n\nread = %s\n\nsd = %d\n\n\n", pBuffer, SSL_get_shutdown(client->myssl));
-	 SSL_shutdown(client->myssl);
-	 pBuffer[0] = '\0';
-	 printf("\n\nread = %s\n\nsd = %d\n\n\n", pBuffer, SSL_get_shutdown(client->myssl));
-    SSL_free(client->myssl);
-	*/
-    /* close socket */
-    if ( close(client->hSocket) == SOCKET_ERROR )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	 free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c_bkp
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client_tls.c_bkp	(revision 151)
+++ 	(revision )
@@ -1,270 +1,0 @@
-/*#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-*/
-/* define HOME to be dir for key and certificate files... */
-//#define HOME "/usr/local/ssl/"
-/* Make these what you want for certificate & key files */
-//#define CERT_FILE "mycert.pem"
-//#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-//#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-//#define CA_FILE CERT_FILE
-//#define CA_DIR  NULL
-
-/*Password for the key file*/
-//#define KEY_PASSWD ""
-
-//#define IP "im.celepar.parana"
-
-//#define PORT "5222"
-
-#include "server.h"
-
-
-int main(void)
-{
-	int jabber_fd       = (int)NULL,
-		jabber_port     = (int)NULL,
-		jabber_error    = (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	printf("Socket returned error #%d,program terminated\n", jabber_error);
-
-	exit(0);
-
-
-
-
-
-
-
-
-
-
-
-
-
-int socketfd, nHostPort;
-   int err;
-   char buff[32];
-struct sockaddr_in socketaddr;
-
-/*SSL PART*/
-SSL_METHOD *meth;
-SSL_CTX  *ctx;
-SSL  *myssl;
-/*SSL PART*/
-
-    if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-    {
-       printf("\n<port>\n\n");
-       printf("\ncould not make a socket\n");
-       return 0;
-    }
-
-   socketfd=socket(AF_INET,SOCK_STREAM,0);
-
-socketaddr.sin_family=AF_INET;
-inet_aton("im.celepar.parana", &socketaddr.sin_addr);
-socketaddr.sin_port=htons(5222);
-
-/* Connect to the server, TCP/IP layer,*/
-   err=connect(socketfd,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
-   if(err<0){
-      printf("Socket returned error #%d,program terminated\n", err);
-      exit(0);
-   }
-    exit(0);
-
-   /* SSL Part*/
-SSL_library_init();
-SSL_load_error_strings();
-
-   meth=TLSv1_client_method();
-  
-   ctx=SSL_CTX_new(meth);
-   if (!ctx) {
-    printf("Error creating the context.\n");
-    exit(0);
-}
-
-/*
-   if (SSL_CTX_set_cipher_list(ctx,CIPHER_LIST) <= 0) {
-printf("Error setting the cipher list.\n");
-exit(0);
-}
-*/
-   /*Indicate the certificate file to be used*/
-  /* if (SSL_CTX_use_certificate_file(ctx,CERT_FILE, SSL_FILETYPE_PEM) <= 0) {
-   printf("Error setting the certificate file.\n");
-   exit(0);
-}*/
-
-
-
-/*Load the password for the Private Key*/
-   //SSL_CTX_set_default_passwd_cb_userdata(ctx,KEY_PASSWD);
-
-
-/*Indicate the key file to be used*/
-/*if (SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) <= 0) {
-printf("Error setting the key file.\n");
-exit(0);
-}*/
-
-/*Make sure the key and certificate file match*/
-/*if (!SSL_CTX_check_private_key(ctx)) {
-    printf("Private key does not match the certificate public key\n");
-    exit(0);
-}*/
-
-/* Set the list of trusted CAs based on the file and/or directory provided*/
-/*   if(SSL_CTX_load_verify_locations(ctx,CA_FILE,CA_DIR)<1){
-            printf("Error setting verify location\n");
-            exit(0);
-   }*/
-
-/* Set for server verification*/
-//   SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL);
-
-/*Create new ssl object*/
-myssl=SSL_new(ctx);
-
-   if(!myssl){
-      printf("Error creating SSL structure.\n");
-      exit(0);
-   }
-
-/*Bind the socket to the SSL structure*/
-SSL_set_fd(myssl,socketfd);
-
-/*Connect to the server, SSL layer.*/
-err=SSL_connect(myssl);
-   /*Check for error in connect.*/
-if (err<1) {
-
-      err=SSL_get_error(myssl,err);
-      printf("SSL error #%d in accept,program terminated\n",err);
-
-      if(err==5){printf("sockerrno is:\n");}
-
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-
-/*Print out connection details*/
-   printf("SSL connection on socket %x,Version: %s, Cipher: %s\n",
-      socketfd,
-   SSL_get_version(myssl),
-SSL_get_cipher(myssl));
-
-puts("_________OK_______________");
-exit(0);
-/*Send message to the server.*/
-   err=SSL_write(myssl,"Hello there!!!!",sizeof("Hello there!!!!")+1);
-   /*Check for error in write.*/
-   if(err<1){
-      err=SSL_get_error(myssl,err);
-      printf("Error #%d in write,program terminated\n",err);
-      /********************************/
-      /* If err=6 it means the client */
-      /* issued an SSL_shutdown. You  */
-      /* must respond with a shutdown */
-      /* to complete a graceful       */
-      /* shutdown                     */
-      /********************************/
-      if(err==6){
-         SSL_shutdown(myssl);
-      }
-      SSL_free(myssl);
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-
-/*Read servers response.*/
-   err = SSL_read (myssl, buff, sizeof(buff));
-   /*Check for error in read.*/
-   if(err<1){
-      err=SSL_get_error(myssl,err);
-      printf("Error #%d in read,program terminated\n",err);
-      /********************************/
-      /* If err=6 it means the client */
-      /* issued an SSL_shutdown. You  */
-      /* must respond with a shutdown */
-      /* to complete a graceful       */
-      /* shutdown                     */
-      /********************************/
-      if(err==6){
-         SSL_shutdown(myssl);
-      }
-      SSL_free(myssl);
-      close(socketfd);
-      SSL_CTX_free(ctx);
-      exit(0);
-   }
-   printf("Server said: %s\n",buff);
-   err=SSL_shutdown(myssl);
-	buff[0] = '\0';
-   SSL_read (myssl, buff, sizeof(buff));
-   /*********************************/
-   /* If err is equal to 0 you are  */
-   /* issuing the shutdown first.   */
-   /* If its 1 then you are         */
-   /* responding to a previously    */
-   /* issued shutdown message       */
-   /*********************************/
-   if(err==0)
-	{
-      err=SSL_shutdown(myssl);
-		buff[0] = '\0';
-	   SSL_read (myssl, buff, sizeof(buff));
-      if(err<1){
-         printf("#1 Error in shutdown\n");
-      }else if(err==1){
-         printf("Client exited gracefully\n");
-      }
-   }else if(err<0){
-         printf("Error in shutdown\n");
-
-   }else if(err==1){
-      printf("Client exited gracefully\n");
-   }
-   close(socketfd);
-SSL_free(myssl);
-SSL_CTX_free(ctx);
-   exit(0);
-
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_24092007.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/server_24092007.c	(revision 151)
+++ 	(revision )
@@ -1,197 +1,0 @@
-#include "server.h"
-
-int main(int argc, char* argv[])
-{
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * atual = (struct client *) NULL;
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	if ( argc != 2 || (socket_server_port = strtol(argv[1], 0, 10)) == 0 )
-		usage();
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == SOCKET_ERROR )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	/* fill address struct */
-	//server_addr.sin_addr.s_addr = inet_aton("10.15.20.42");//INADDR_ANY;
-	//inet_aton(INADDR_ANY, &server_addr.sin_addr);//INADDR_ANY;
-	server_addr.sin_addr.s_addr = INADDR_ANY;
-	server_addr.sin_port = htons(socket_server_port);
-	server_addr.sin_family = AF_INET;
-
-	printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == SOCKET_ERROR )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&server_addr, (socklen_t *)&sockaddr_in_size);
-	printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-	printf("Server\n\
-			sin_family        = %d\n\
-			sin_addr.s_addr   = %d\n\
-			sin_port          = %d\n"
-			, server_addr.sin_family
-			, server_addr.sin_addr.s_addr
-			, ntohs(server_addr.sin_port)
-			);
-	printf("\nMaking a listen queue of %d elements", QUEUE_SIZE);
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, QUEUE_SIZE) == SOCKET_ERROR )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &accept_addr, (socklen_t *) &sockaddr_in_size);
-		if ( socket_accept_fd > -1 )
-		{
-			/*
-			char ip[46];
-			unsigned short port;
-			printf("%d\n\n", inet_ntoa(server_addr.sin_addr.s_addr));
-			printf("%d\n\n", inet_ntoa(accept_addr.sin_addr.s_addr));
-			inet_ntop (AF_INET, &accept_addr.sin_addr, ip, sizeof (ip));
-			port = ntohs(accept_addr.sin_port);
-			printf("connection from %s, port %hu\n", ip, port);
-			*/
-
-
-			/*
-			 if ( close(socket_accept_fd) == SOCKET_ERROR )
-				printf("\nCould not close socket\n");
-			*/
-
-			if ( clients == (struct client *) NULL )
-				atual = clients;
-			else
-				while ( (atual = clients->next) != (struct client *) NULL );
-
-			atual = (struct client *) malloc(sizeof(struct client));
-			atual->next = (struct client *) NULL;
-			atual->fd = socket_accept_fd;
-			atual->sockaddr = accept_addr;
-			atual->last = time(NULL);
-
-			pthread_create(&threads, NULL, handler, (void *)atual);
-			//clients = (struct client *)NULL;
-		}
-		puts("jah era #5");
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char pBuffer[BUFFER_SIZE];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	//printf("%d\n\n", inet_ntoa(client->fd));
-	//printf("%d\n\n", inet_ntoa(client->sockaddr.sin_addr.s_addr));
-	inet_ntop(AF_INET, &client->sockaddr.sin_addr, ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-
-    if ( close(client->fd) == SOCKET_ERROR )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-    /*
-
-	last = time(NULL);
-	while ( time(NULL) - client->last < 10 )
-	{
-		printf("%s\n\n", "teste");
-		sleep(1);
-	}
-
-	client->last = time(NULL);
-	*/
-
-    /**
-	 * number returned by read() and write() is the number of bytes
-     * read or written, with -1 being that an error occured
-     * write what we received back to the server
-	 **/
-
-    /*
-	strcpy(pBuffer, MESSAGE);
-    printf("\nSending \"%s\" to client\n",pBuffer);
-    write(client->hSocket, pBuffer, strlen(pBuffer)+1);
-	*/
-
-	/* read from socket into buffer */
-	/*read(client->hSocket, pBuffer, sizeof(pBuffer));
-
-	printf("Received from client: %s\n", pBuffer);
-
-    if ( strcmp(pBuffer, MESSAGE) == 0 )
-        printf("The messages match\n");
-    else
-        printf("Something was changed in the message\n");
-	*/
-
-    /*while (i < 10)
-    {
-		 printf("%d\n", i);
-		 usleep(1000000);
-		 i++;
-    }*/
-
-    /* close socket */
-    /*printf("\nClosing the socket");
-    if ( close(client->hSocket) == SOCKET_ERROR )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-	*/
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/client.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/client.c	(revision 151)
+++ 	(revision )
@@ -1,73 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#define IP "10.15.20.116"
-
-#define PORT "8888"
-
-int main(void)
-{
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-	int err,
-		i,
-		unit;
-	char buff[4096];
-	char * _xml = (char)NULL,
-		 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"};
-
-	_xml = (char *)malloc(sizeof(xml_connect));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	//socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-	//socketaddr.sin_addr.s_addr = inet_addr("10.15.20.42");
-	inet_aton("10.15.20.42", &socketaddr.sin_addr);
-	socketaddr.sin_port = htons(nHostPort);
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	struct hostent *hp;
-	hp = gethostbyaddr((char *)&socketaddr.sin_addr.s_addr, sizeof socketaddr.sin_addr.s_addr, AF_INET);
-
-	printf("\n\n%s\n\n", inet_ntoa(socketaddr.sin_addr));
-	printf("\n\n%d\n\n", inet_network("expresso.pr.gov.br"));
-
-	//printf("\n\n%d\n\n", socketaddr.sin_addr.s_addr);
-	//printf("\n\n%s\n\n", gethostbyaddr((char *)&socketaddr.sin_addr.s_addr, sizeof socketaddr.sin_addr.s_addr, AF_INET));
-
-
-	sprintf(_xml, xml_connect, "localhost");
-
-	write(socketfd, _xml, strlen(_xml));
-
-	read (socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	//sleep(10);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/server.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/server.c	(revision 151)
+++ 	(revision )
@@ -1,263 +1,0 @@
-#include "server.h"
-
-void my_shutdown(int n){
-	printf("server recvd SIGPIPE");
-	exit(1);
-}
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-	signal(SIGPIPE, my_shutdown);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-	//exit(0);
-
-	/*if ( argc != 2 || (socket_server_port = strtol(argv[1], 0, 10)) == 0 )
-		usage();*/
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( setsockopt(socket_accept_fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0)
-		{
-			perror("setsockopt()");
-			exit(EXIT_FAILURE);
-		}
-
-		int val;
-		val = 10; /* 10 sec before starting probes */
-		setsockopt (socket_accept_fd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof (val));
-		val = 2; /* 2 probes max */
-		setsockopt (socket_accept_fd, SOL_TCP, TCP_KEEPCNT, &val, sizeof (val));
-		val = 5; /* 5 seconds between each probe */
-		setsockopt (socket_accept_fd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof (val));
-
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-		puts("jah era #5");
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	//fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK );
-	//printf(":::client %d\n\n\n", fcntl( client->fd, F_GETFL, 0));
-	//printf(":::client %d\n\n\n", fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK ));
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	//jabber_port = strtol(__DEFAULT_JABBER_PORT__, 0, 10);
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-	int sockaddr_in_size    = sizeof(struct sockaddr_in);
-	while ( client_is_connected != 0 )
-	{
-		puts("begin loop");
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 && strlen(buffer_jabber) > 0 )
-		{
-			puts("\twrite - jabber");
-			/* write in the client */
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-		}
-
-		/*if ( client_is_connected == 0 )
-			break;*/
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(jabber_fd, buffer_jabber, __BUFFER_SIZE__)) && strlen(buffer_client) > 0 )
-		{
-			puts("\twrite - client");
-			/* write in the jabber service */
-			write(jabber_fd, buffer_client, strlen(buffer_client));
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/server.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/server.h	(revision 151)
+++ 	(revision )
@@ -1,103 +1,0 @@
-#include <fcntl.h>
-
-#include <linux/tcp.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-/* define max clients per child */
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 100
-#endif
-
-/* define max clients waiting in the queue for connect */
-#ifndef __QUEUE_SIZE__
-	#define __QUEUE_SIZE__ 10
-#endif
-
-/* __SOCKET_ERROR__ must be -1, don't change this */
-#ifndef __SOCKET_ERROR__
-	#define __SOCKET_ERROR__ -1
-#endif
-
-/* open port when this server is activated */
-#ifndef __DEFAULT_OPEN_PORT__
-	#define __DEFAULT_OPEN_PORT__ 8888
-#endif
-
-/* ip of jabber service */
-#ifndef __DEFAULT_JABBER_PORT__
-	#define __DEFAULT_JABBER_PORT__ 5222
-#endif
-
-/* port to connect on jabber service */
-#ifndef __DEFAULT_JABBER_IP__
-	#define __DEFAULT_JABBER_IP__ "10.15.20.202"
-#endif
-
-/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
-#ifndef __BUFFER_SIZE__
-	#define __BUFFER_SIZE__ 4096
-#endif
-
-#define MESSAGE			"This is the message I'm sending back and forth"
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-/* 0 -> false; 1 -> true */
-#ifndef __DEBUG__
-	#define __DEBUG__ 0
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/mycert.pem
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/mycert.pem	(revision 151)
+++ 	(revision )
@@ -1,34 +1,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDY8Tao9bylsCI6LVR8yWWO7HgfnQQCwh2cqigKHaSnuo5n67R5
-Cp7dAbYkVf1V7BZ+V3nn7eVQ2FXcb8BooBQY51J9j7Q75IT5AZRar1ket5pRnVJH
-THGpm8trQsP54gV14lRToI36zXFzxakR08B1iKRyyLUVwp8RvAUxS+kKHwIDAQAB
-AoGAFIbWTixaOi8tPeX2HYyM0HYtc4hOzdgCJ0WuXi6p2rj7KngR7nYDzBOSYWPF
-gbDB/BhYz4oh7YFatm3Yfc3PuNLbuTxaMuuevDl9Qy+0cVI3FL7ban5jgEXMZVB8
-rgIfxmem8Kj7Eu/WtF/UJiz+epJQgrndlNtWJTWSDHoLRqkCQQD3lf4kRwiJJrAS
-Hj48/FVaR+0nvcEia7YsF44is8Yd++BG1tKNZZaKpdhssVA/9Pd+8hC9Sqzji+Mc
-ZXdbAoh1AkEA4FCeoH/ZfWZ3KfCyGfK6T2SEf3tJB/bleFg1mdmv9INuk6HSKMKW
-62mhxAk4DjcYcoM8QSeAE4FN7aOwB3OVwwJAeL/7qf/G5vUqbDu5yQ6cJiLsRDSk
-rD/yIkD+vmgFWPxOHt6I5BNGv6oxCpnT9M1po801Ysy302aXRnMqKgXrPQJBAMYG
-ZgNK2rXZv1lHI/PEVLXCBzaDn/VoASw8sxUfGDbD0NqEAQP6xUEN/8EQYmwqN2rg
-cFEUjfyqKiGgX8Y0RAECQGTEkKvhDzgyyphx5JkYem7sAUI7gFGKZxJaVU+KkN5e
-pU4pgNiFUT0uTbfFzzOYQKeyVlBqGiv7rVn3BO3pfV4=
------END RSA PRIVATE KEY-----
------BEGIN CERTIFICATE-----
-MIIDKzCCApSgAwIBAgIJAOkSDgQDK1oGMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkJSMQswCQYDVQQIEwJQUjEMMAoGA1UEBxMDQ1dCMQ0wCwYDVQQKEwRTQ0tU
-MQ0wCwYDVQQLEwRzY2t0MSUwIwYDVQQDExxlY2VsZXBhcjkxMTM3LmNlbGVwYXIu
-cGFyYW5hMB4XDTA3MDgwOTE2Mzg0MVoXDTA4MDgwODE2Mzg0MVowbTELMAkGA1UE
-BhMCQlIxCzAJBgNVBAgTAlBSMQwwCgYDVQQHEwNDV0IxDTALBgNVBAoTBFNDS1Qx
-DTALBgNVBAsTBHNja3QxJTAjBgNVBAMTHGVjZWxlcGFyOTExMzcuY2VsZXBhci5w
-YXJhbmEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANjxNqj1vKWwIjotVHzJ
-ZY7seB+dBALCHZyqKAodpKe6jmfrtHkKnt0BtiRV/VXsFn5Xeeft5VDYVdxvwGig
-FBjnUn2PtDvkhPkBlFqvWR63mlGdUkdMcamby2tCw/niBXXiVFOgjfrNcXPFqRHT
-wHWIpHLItRXCnxG8BTFL6QofAgMBAAGjgdIwgc8wHQYDVR0OBBYEFDqDGL/fTaKt
-NtkTuuzBet9mgcSOMIGfBgNVHSMEgZcwgZSAFDqDGL/fTaKtNtkTuuzBet9mgcSO
-oXGkbzBtMQswCQYDVQQGEwJCUjELMAkGA1UECBMCUFIxDDAKBgNVBAcTA0NXQjEN
-MAsGA1UEChMEU0NLVDENMAsGA1UECxMEc2NrdDElMCMGA1UEAxMcZWNlbGVwYXI5
-MTEzNy5jZWxlcGFyLnBhcmFuYYIJAOkSDgQDK1oGMAwGA1UdEwQFMAMBAf8wDQYJ
-KoZIhvcNAQEFBQADgYEAVHm/1+iybB3u48nP0NDIocPIhUC55e8iL9h0GOmvJalp
-IpCeIuefCTPCkrJHNMSVNqz6q3UfJLNXe91UdaAYvXEqWLP0mYUz5DWnzUYIIb/y
-W1BZ2WqcX8KZeJJgF/Gu0BJj5oGaf8LMVQoS58TiWgQABg1UTFHnHoXJhABQ1Qo=
------END CERTIFICATE-----
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp.c	(revision 151)
+++ 	(revision )
@@ -1,335 +1,0 @@
-#include "server.h"
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-int starttls(int * jabberfd, int * clientfd)
-{
-	int err;
-
-	SSL_CTX * ctx;
-	SSL * clientssl,
-		* jabberssl;
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-
-	if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-	
-	/*
-	clientssl = SSL_new(ctx);
-
-	puts("#1");
-	SSL_set_fd(clientssl, *(clientfd));
-
-	puts("accept");
-	err = SSL_accept(clientssl);
-	// Check for error in connect.
-	if ( err < 1 )
-	{
-		puts("server");
-		SSL_CTX_free(ctx);
-		return 0;
-	}
-	*/
-
-	jabberssl = SSL_new(ctx);
-
-	puts("#2");
-	SSL_set_fd(jabberssl, *(jabberfd));
-
-	puts("connect");
-	err = SSL_connect(jabberssl);
-	/* Check for error in connect. */
-	if ( err < 1 )
-	{
-		puts("client");
-		SSL_CTX_free(ctx);
-		return 0;
-	}
-
-	return 1;
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	//jabber_addr.sin_addr.s_addr = inet_addr(__DEFAULT_JABBER_IP__);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-	int sockaddr_in_size    = sizeof(struct sockaddr_in);
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 && strlen(buffer_jabber) > 0 )
-		{
-			puts("\twrite - client");
-			printf("\t%s\n", buffer_jabber);
-			/* write in the client */
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(jabber_fd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-				puts("\twrite - jabber");
-				printf("\t%s\n", buffer_client);
-				/* write in the jabber service */
-				if ( !strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-					write(jabber_fd, buffer_client, strlen(buffer_client));
-		}
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | ~O_NDELAY);
-			//starttls(&jabber_fd, &client->fd);
-			int err;
-
-			SSL_CTX * ctx;
-			SSL * jabberssl;
-
-			//OpenSSL_add_all_algorithms();
-
-			SSL_library_init();
-			SSL_load_error_strings();
-
-			if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-			{
-				printf("Error creating the context.\n");
-				exit(0);
-			}
-
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-
-			jabberssl = SSL_new(ctx);
-
-			puts("#1");
-			err=SSL_set_fd(jabberssl, jabber_fd);
-			if ( err < 1 )
-			{
-				puts("shsfghdfgh");
-				SSL_CTX_free(ctx);
-			}
-
-			puts("connect");
-			err = SSL_connect(jabberssl);
-			if ( err < 1 )
-			{
-				puts("client");
-				err = SSL_get_error(jabberssl, err);
-				printf("%d\n", err);
-				char err_str[1024];
-				ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
-				printf("%s\n", err_str);
-				SSL_CTX_free(ctx);
-			}
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008_2.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008_2.c	(revision 151)
+++ 	(revision )
@@ -1,439 +1,0 @@
-#include "server.h"
-#include "xmpp.h"
-
-#define HOST "im.celepar.parana"
-#define IP "10.15.20.219"
-#define PORT "5222"
-
-int tls = 0;
-
-void Read(void * fd, void *buf, int count)
-{
-	bzero(buf, count);
-	if ( tls == 0 )
-		read(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_read((SSL *) fd, buf, count);
-}
-
-void Write(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		write(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_write((SSL *) fd, buf, count);
-}
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-
-	char buff[4096];
-	char * xml = (char)NULL;
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-
-	xml = (char *) malloc(sizeof(__CONNECT__));
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		//fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-			if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-			{
-				printf("\n<port>\n\n");
-				printf("\ncould not make a socket\n");
-				return 0;
-			}
-
-			socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-			socketaddr.sin_family = AF_INET;
-			//socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-			socketaddr.sin_addr.s_addr = inet_addr(IP);
-			socketaddr.sin_port = htons(nHostPort);
-
-			SSL_library_init();
-			if ( !(ctx = SSL_CTX_new(TLSv1_client_method())) )
-			{
-				printf("Error creating the context.\n");
-				exit(0);
-			}
-
-			err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-
-			if ( err < 0 )
-			{
-				printf("Socket returned error #%d,program terminated\n", err);
-				exit(0);
-			}
-
-			sprintf(xml, __CONNECT__, HOST);
-			Write(&socketfd, xml, strlen(xml));
-			int stop = 0;
-			do
-			{
-				Read (&socketfd, buff, sizeof(buff));
-				if ( strstr(buff, __FEATURES_BEGIN__) )
-					stop = 1;
-				else
-					usleep(100);
-			}
-			while ( !stop );
-
-			puts(buff);
-			stop = 0;
-			int starttls = 0;
-
-			if ( strstr(buff, __STARTTLS_SERVER__) )
-				starttls = 1;
-
-			if ( starttls )
-			{
-				sprintf(xml, __STARTTLS_CLIENT__);
-				Write(&socketfd, xml, strlen(xml));
-
-				stop = 0;
-				do
-				{
-					Read (&socketfd, buff, sizeof(buff));
-					if ( strstr(buff, __PROCEED__) )
-						stop = 1;
-					else
-						usleep(100);
-				}
-				while ( !stop );
-				printf("%s\n\n", buff);
-				bzero(buff, 4096);
-
-				SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-				/*Create new ssl object*/
-				myssl=SSL_new(ctx);
-
-				if(!myssl){
-					printf("Error creating SSL structure.\n");
-					exit(0);
-				}
-
-				/*Bind the socket to the SSL structure*/
-				SSL_set_fd(myssl,socketfd);
-
-				/*Connect to the server, SSL layer.*/
-				err=SSL_connect(myssl);
-				printf("SSL error #%d in accept,program terminated\n",err);
-				/*Check for error in connect.*/
-				if (err<1) {
-
-					err=SSL_get_error(myssl,err);
-					printf("SSL error #%d in accept,program terminated\n",err);
-					printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-					if(err==5){printf("sockerrno is:\n");}
-
-					close(socketfd);
-					SSL_CTX_free(ctx);
-					exit(0);
-				}
-
-				tls = 1;
-
-				printf("SSL connection on socket %x,Version: %s, Cipher: %s\n\n\n",
-						socketfd,
-						SSL_get_version(myssl),
-						SSL_get_cipher(myssl));
-
-				sprintf(xml, __CONNECT__, HOST);
-				SSL_write(myssl, xml, strlen(xml));
-				usleep(10000);
-				SSL_read(myssl, buff, sizeof(buff));
-				printf("%s\n\n", buff);
-				bzero(buff, 4096);
-
-				usleep(10000);
-				SSL_read(myssl, buff, sizeof(buff));
-				printf("%s\n\n", buff);
-				bzero(buff, 4096);
-
-				SSL_clear(myssl);
-				SSL_shutdown(myssl);
-				SSL_free(myssl);
-				SSL_CTX_free(ctx);
-			}
-			fflush(stdin);
-			fflush(stdout);
-
-
-
-			//pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	//jabber_addr.sin_addr.s_addr = inet_addr(__DEFAULT_JABBER_IP__);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-	int sockaddr_in_size    = sizeof(struct sockaddr_in);
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 && strlen(buffer_jabber) > 0 )
-		{
-			puts("\twrite - client");
-			printf("\t%s\n", buffer_jabber);
-			/* write in the client */
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(jabber_fd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-				puts("\twrite - jabber");
-				printf("\t%s\n", buffer_client);
-				/* write in the jabber service */
-				if ( !strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-					write(jabber_fd, buffer_client, strlen(buffer_client));
-		}
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | ~O_NDELAY);
-			//starttls(&jabber_fd, &client->fd);
-			int err;
-
-			SSL_CTX * ctx;
-			SSL * jabberssl;
-
-			//OpenSSL_add_all_algorithms();
-
-			SSL_library_init();
-			SSL_load_error_strings();
-
-			if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-			{
-				printf("Error creating the context.\n");
-				exit(0);
-			}
-
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-
-			jabberssl = SSL_new(ctx);
-
-			puts("#1");
-			err=SSL_set_fd(jabberssl, jabber_fd);
-			if ( err < 1 )
-			{
-				puts("shsfghdfgh");
-				SSL_CTX_free(ctx);
-			}
-
-			puts("connect");
-			err = SSL_connect(jabberssl);
-			if ( err < 1 )
-			{
-				puts("client");
-				err = SSL_get_error(jabberssl, err);
-				printf("%d\n", err);
-				char err_str[1024];
-				ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
-				printf("%s\n", err_str);
-				SSL_CTX_free(ctx);
-			}
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server.c	(revision 151)
+++ 	(revision )
@@ -1,422 +1,0 @@
-#include "server.h"
-#include "xmpp.h"
-
-#define HOST "im.celepar.parana"
-#define IP "10.15.20.219"
-#define PORT "5222"
-
-int tls = 0;
-
-void Read(void * fd, void *buf, int count)
-{
-	bzero(buf, count);
-	if ( tls == 0 )
-		read(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_read((SSL *) fd, buf, count);
-}
-
-void Write(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		write(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_write((SSL *) fd, buf, count);
-}
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	SSL_CTX * ctx;
-
-	pthread_t threads;
-
-	// clear screen
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				// -f or -o without operand
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-	if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	if ( SSL_CTX_set_cipher_list(ctx, CIPHER_LIST) < 1 )
-	{
-		printf("Error setting the cipher list.\n");
-		exit(0);
-	}
-
-	//Indicate the certificate file to be used
-	if ( SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the certificate file.\n");
-		exit(0);
-	}
-
-	//Load the password for the Private Key
-	SSL_CTX_set_default_passwd_cb_userdata(ctx, KEY_PASSWD);
-
-	//Indicate the key file to be used
-	if ( SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the key file.\n");
-		exit(0);
-	}
-
-	//Make sure the key and certificate file match
-	if ( !SSL_CTX_check_private_key(ctx) )
-	{
-		printf("Private key does not match the certificate public key\n");
-		exit(0);
-	}
-
-	// Set the list of trusted CAs based on the file and/or directory provided
-	if ( SSL_CTX_load_verify_locations(ctx, CA_FILE, CA_DIR) < 1 )
-	{
-		printf("Error setting verify location\n");
-		exit(0);
-	}
-
-	// Set for server verification
-	SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->ctx		= ctx;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-
-	char buff[4096];
-	char * xml = (char)NULL;
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-
-	char * old_host,
-		 * replace_host;
-
-	xml = (char *) malloc(sizeof(__CONNECT__));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	if ( !(ctx = SSL_CTX_new(TLSv1_client_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 )
-		{
-			if ( strlen(buffer_jabber) > 0 )
-			{
-				puts("\twrite - client");
-				printf("\t%s\n", buffer_jabber);
-				/* write in the client */
-				write(client->fd, buffer_jabber, strlen(buffer_jabber));
-			}
-
-			if ( strstr(buffer_client, "<stream:stream") && (old_host = strstr(buffer_client, "to=")) )
-			{
-				strncpy(replace_host, buffer_client, (strlen(buffer_client) - strlen(old_host))+4);
-				strcat(replace_host, HOST);
-				old_host = strstr(old_host, " ");
-				old_host--;
-				strcat(replace_host, old_host);
-				strcpy(buffer_client, replace_host);
-			}
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(socketfd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-			puts("\twrite - jabber");
-			printf("\t%s\n", buffer_client);
-			/* write in the jabber service */
-			write(socketfd, buffer_client, strlen(buffer_client));
-		}
-
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & ~O_NDELAY );
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-			//Create new ssl object
-			myssl=SSL_new(ctx);
-
-			if(!myssl){
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(myssl,socketfd);
-
-			//Connect to the server, SSL layer.
-			err=SSL_connect(myssl);
-			printf("SSL error #%d in accept,program terminated\n",err);
-			//Check for error in connect.
-			if (err<1) {
-
-				err=SSL_get_error(myssl,err);
-				printf("SSL error #%d in accept,program terminated\n",err);
-				printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-				if(err==5){printf("sockerrno is:\n");}
-
-				close(socketfd);
-				SSL_CTX_free(ctx);
-				exit(0);
-			}
-
-			fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY);
-
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-			bzero(buffer_jabber, __BUFFER_SIZE__);
-
-			fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NDELAY );
-
-			//Create new ssl object
-			if( !(client->myssl = SSL_new(client->ctx)) )
-			{
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(client->myssl, client->fd);
-
-			puts("_____TESTE______");
-			//Connect to the server, SSL layer.
-			err = SSL_accept(client->myssl);
-			puts("_____TESTE______");
-
-			//Check for error in connect.
-			if ( err < 1 )
-			{
-				printf("SSL error #%d in accept,program terminated\n", err);
-				err = SSL_get_error(client->myssl, 0);
-				printf("SSL error #%d in accept,program terminated\n", err);
-
-				switch ( err )
-				{
-					case SSL_ERROR_NONE : puts("SSL_ERROR_NONE");break;
-					case SSL_ERROR_SSL : puts("SSL_ERROR_SSL");break;
-					case SSL_ERROR_WANT_READ : puts("SSL_ERROR_WANT_READ");
-				}
-
-				if ( err == 5 )
-					printf("sockerrno is: %d\n", err);
-
-
-				SSL_CTX_free(client->ctx);
-				client_is_connected = 0;
-			}
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-    if ( close(socketfd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	//---------------------------------------------------
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/unp.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/unp.h	(revision 151)
+++ 	(revision )
@@ -1,28 +1,0 @@
-/**
- * unp.h
- * Unix Network Programming
- **/
-
-#include <fcntl.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008_jabber_tls.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008_jabber_tls.c	(revision 151)
+++ 	(revision )
@@ -1,333 +1,0 @@
-#include "server.h"
-#include "xmpp.h"
-
-#define HOST "im.celepar.parana"
-#define IP "10.15.20.219"
-#define PORT "5222"
-
-int tls = 0;
-
-void Read(void * fd, void *buf, int count)
-{
-	bzero(buf, count);
-	if ( tls == 0 )
-		read(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_read((SSL *) fd, buf, count);
-}
-
-void Write(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		write(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_write((SSL *) fd, buf, count);
-}
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	/* make a socket */
-	int one = 1;
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-
-	char buff[4096];
-	char * xml = (char)NULL;
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-
-	char * old_host,
-		 * replace_host;
-
-	xml = (char *) malloc(sizeof(__CONNECT__));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-	if ( !(ctx = SSL_CTX_new(TLSv1_client_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 )
-		{
-			if ( strlen(buffer_jabber) > 0 )
-			{
-				puts("\twrite - client");
-				printf("\t%s\n", buffer_jabber);
-				/* write in the client */
-				write(client->fd, buffer_jabber, strlen(buffer_jabber));
-			}
-
-			if ( strstr(buffer_client, "<stream:stream") && (old_host = strstr(buffer_client, "to=")) )
-			{
-				strncpy(replace_host, buffer_client, (strlen(buffer_client) - strlen(old_host))+4);
-				strcat(replace_host, HOST);
-				old_host = strstr(old_host, " ");
-				old_host--;
-				strcat(replace_host, old_host);
-				strcpy(buffer_client, replace_host);
-			}
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(socketfd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-			puts("\twrite - jabber");
-			printf("\t%s\n", buffer_client);
-			/* write in the jabber service */
-			write(socketfd, buffer_client, strlen(buffer_client));
-		}
-
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & ~O_NDELAY );
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-			//Create new ssl object
-			myssl=SSL_new(ctx);
-
-			if(!myssl){
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(myssl,socketfd);
-
-			//Connect to the server, SSL layer.
-			err=SSL_connect(myssl);
-			printf("SSL error #%d in accept,program terminated\n",err);
-			//Check for error in connect.
-			if (err<1) {
-
-				err=SSL_get_error(myssl,err);
-				printf("SSL error #%d in accept,program terminated\n",err);
-				printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-				if(err==5){printf("sockerrno is:\n");}
-
-				close(socketfd);
-				SSL_CTX_free(ctx);
-				exit(0);
-			}
-
-
-			fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY);
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-    if ( close(socketfd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	//---------------------------------------------------
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server.h	(revision 151)
+++ 	(revision )
@@ -1,102 +1,0 @@
-#include <fcntl.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-/* define max clients per child */
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 100
-#endif
-
-/* define max clients waiting in the queue for connect */
-#ifndef __QUEUE_SIZE__
-	#define __QUEUE_SIZE__ 10
-#endif
-
-/* __SOCKET_ERROR__ must be -1, don't change this */
-#ifndef __SOCKET_ERROR__
-	#define __SOCKET_ERROR__ -1
-#endif
-
-/* open port when this server is activated */
-#ifndef __DEFAULT_OPEN_PORT__
-	#define __DEFAULT_OPEN_PORT__ 8888
-#endif
-
-/* ip of jabber service */
-#ifndef __DEFAULT_JABBER_PORT__
-	#define __DEFAULT_JABBER_PORT__ 5222
-#endif
-
-/* port to connect on jabber service */
-#ifndef __DEFAULT_JABBER_IP__
-	#define __DEFAULT_JABBER_IP__ "im.celepar.parana"
-#endif
-
-/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
-#ifndef __BUFFER_SIZE__
-	#define __BUFFER_SIZE__ 4096
-#endif
-
-#define MESSAGE			"This is the message I'm sending back and forth"
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-/* 0 -> false; 1 -> true */
-#ifndef __DEBUG__
-	#define __DEBUG__ 0
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL_CTX  *ctx;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/client.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/client.c	(revision 151)
+++ 	(revision )
@@ -1,73 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#define IP "200.189.113.148"
-
-#define PORT "5222"
-
-int main(void)
-{
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-	int err,
-		i,
-		unit;
-	char buff[4096];
-	char * _xml = (char)NULL,
-		 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"};
-
-	_xml = (char *)malloc(sizeof(xml_connect));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	//socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-	//socketaddr.sin_addr.s_addr = inet_addr("10.15.20.42");
-	inet_aton(IP, &socketaddr.sin_addr);
-	socketaddr.sin_port = htons(nHostPort);
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	struct hostent *hp;
-	hp = gethostbyaddr((char *)&socketaddr.sin_addr.s_addr, sizeof socketaddr.sin_addr.s_addr, AF_INET);
-
-	printf("\n\n%s\n\n", inet_ntoa(socketaddr.sin_addr));
-	printf("\n\n%d\n\n", inet_network("expresso.pr.gov.br"));
-
-	//printf("\n\n%d\n\n", socketaddr.sin_addr.s_addr);
-	//printf("\n\n%s\n\n", gethostbyaddr((char *)&socketaddr.sin_addr.s_addr, sizeof socketaddr.sin_addr.s_addr, AF_INET));
-
-
-	sprintf(_xml, xml_connect, IP);
-
-	write(socketfd, _xml, strlen(_xml));
-
-	read (socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	//sleep(10);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/teste_bkp.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/teste_bkp.c	(revision 151)
+++ 	(revision )
@@ -1,185 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-
-//#define HOST "im.pr.gov.br"
-//#define IP "200.189.113.148"
-#define HOST "localhost"
-#define IP "10.15.20.42"
-//#define HOST "im.celepar.parana"
-//#define IP "10.15.20.219"
-#define PORT "5222"
-
-int tls = 0;
-
-void Read(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		read(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_read((SSL *) fd, buf, count);
-}
-
-void Write(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		write(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_write((SSL *) fd, buf, count);
-}
-
-int main(void)
-{
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-	int err,
-		i,
-		unit;
-	extern int tls;
-	char buff[4096];
-	char * _xml = (char)NULL,
-		 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"},
-		 * xml_starttls = {"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"};
-
-	/*SSL PART*/
-	SSL_METHOD *meth;
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-	/*SSL PART*/
-
-	_xml = (char *) malloc(sizeof(xml_connect));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	//socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-	meth=TLSv1_client_method();
-
-	ctx=SSL_CTX_new(meth);
-	if (!ctx)
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	//fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY | O_NONBLOCK);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	sprintf(_xml, xml_connect, HOST);
-	Write(&socketfd, _xml, strlen(_xml));
-	//usleep(500);
-	Read (&socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	bzero(buff, 4096);
-
-	puts("-----------\n");
-
-	/*
-	read (socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	bzero(buff, 4096);
-
-	puts("-----------\n");
-	*/
-
-	sprintf(_xml, xml_starttls);
-	Write(&socketfd, _xml, strlen(_xml));
-	//usleep(500);
-	Read (&socketfd, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	bzero(buff, 4096);
-
-	SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-	/*Create new ssl object*/
-	myssl=SSL_new(ctx);
-
-	if(!myssl){
-		printf("Error creating SSL structure.\n");
-		exit(0);
-	}
-
-	/*Bind the socket to the SSL structure*/
-	SSL_set_fd(myssl,socketfd);
-
-	/*Connect to the server, SSL layer.*/
-	err=SSL_connect(myssl);
-	printf("SSL error #%d in accept,program terminated\n",err);
-	/*Check for error in connect.*/
-	if (err<1) {
-
-		err=SSL_get_error(myssl,err);
-		printf("SSL error #%d in accept,program terminated\n",err);
-		printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-		if(err==5){printf("sockerrno is:\n");}
-
-		close(socketfd);
-		SSL_CTX_free(ctx);
-		exit(0);
-	}
-
-	tls = 1;
-
-	/*Print out connection details*/
-	printf("SSL connection on socket %x,Version: %s, Cipher: %s\n\n\n",
-			socketfd,
-			SSL_get_version(myssl),
-			SSL_get_cipher(myssl));
-
-	sprintf(_xml, xml_connect, HOST);
-	SSL_write(myssl, _xml, strlen(_xml));
-	usleep(10000);
-	SSL_read(myssl, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	bzero(buff, 4096);
-
-	usleep(10000);
-	SSL_read(myssl, buff, sizeof(buff));
-	printf("%s\n\n", buff);
-	bzero(buff, 4096);
-
-	SSL_clear(myssl);
-	SSL_shutdown(myssl);
-	SSL_free(myssl);
-	SSL_CTX_free(ctx);
-	fflush(stdin);
-    fflush(stdout);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/server_bkp_20071008.c	(revision 151)
+++ 	(revision )
@@ -1,406 +1,0 @@
-#include "server.h"
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	pthread_t threads;
-
-	/* clear screen */
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				/* -f or -o without operand */
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->last		= time(NULL);
-
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = current;//(struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	//jabber_addr.sin_addr.s_addr = inet_addr(__DEFAULT_JABBER_IP__);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-	int sockaddr_in_size    = sizeof(struct sockaddr_in);
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 && strlen(buffer_jabber) > 0 )
-		{
-			puts("\twrite - client");
-			printf("\t%s\n", buffer_jabber);
-			/* write in the client */
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(jabber_fd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-				puts("\twrite - jabber");
-				printf("\t%s\n", buffer_client);
-				/* write in the jabber service */
-				if ( !strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-					write(jabber_fd, buffer_client, strlen(buffer_client));
-		}
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | ~O_NDELAY);
-			//starttls(&jabber_fd, &client->fd);
-			int err;
-
-			SSL_CTX * ctx;
-			SSL * jabberssl;
-
-			//OpenSSL_add_all_algorithms();
-
-			SSL_library_init();
-			SSL_load_error_strings();
-
-			if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-			{
-				printf("Error creating the context.\n");
-				exit(0);
-			}
-
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-
-			jabberssl = SSL_new(ctx);
-
-			puts("#1");
-			err=SSL_set_fd(jabberssl, jabber_fd);
-			if ( err < 1 )
-			{
-				puts("shsfghdfgh");
-				SSL_CTX_free(ctx);
-			}
-
-			puts("connect");
-			err = SSL_connect(jabberssl);
-			if ( err < 1 )
-			{
-				puts("client");
-				err = SSL_get_error(jabberssl, err);
-				printf("%d\n", err);
-				char err_str[1024];
-				ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
-				printf("%s\n", err_str);
-				SSL_CTX_free(ctx);
-			}
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-			//pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err;
-	time_t last;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int jabber_fd		= (int)NULL,
-		jabber_port		= (int)NULL,
-		jabber_error	= (int)NULL;
-
-	struct sockaddr_in jabber_addr;
-
-	jabber_port = __DEFAULT_JABBER_PORT__;
-	jabber_fd = socket(AF_INET, SOCK_STREAM, 0);
-
-	fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | O_NDELAY);
-
-	jabber_addr.sin_family = AF_INET;
-	inet_aton(__DEFAULT_JABBER_IP__, &jabber_addr.sin_addr);
-	//jabber_addr.sin_addr.s_addr = inet_addr(__DEFAULT_JABBER_IP__);
-	jabber_addr.sin_port = htons(jabber_port);
-
-	jabber_error = connect(jabber_fd, (struct sockaddr *) &(jabber_addr), sizeof(jabber_addr));
-
-	last = time(NULL);
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-	int sockaddr_in_size    = sizeof(struct sockaddr_in);
-	while ( client_is_connected != 0 )
-	{
-		/* read from client */
-		puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( (client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__)) != 0 && strlen(buffer_jabber) > 0 )
-		{
-			puts("\twrite - client");
-			printf("\t%s\n", buffer_jabber);
-			/* write in the client */
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-		}
-
-		/* read from jabber service */
-		puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-		if ( (jabber_is_connected = read(jabber_fd, buffer_jabber, __BUFFER_SIZE__))  && strlen(buffer_client) > 0 )
-		{
-				puts("\twrite - jabber");
-				printf("\t%s\n", buffer_client);
-				/* write in the jabber service */
-				if ( !strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-					write(jabber_fd, buffer_client, strlen(buffer_client));
-		}
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			fcntl(jabber_fd, F_SETFL, fcntl(jabber_fd, F_GETFL, 0) | ~O_NDELAY);
-			//starttls(&jabber_fd, &client->fd);
-			int err;
-
-			SSL_CTX * ctx;
-			SSL * jabberssl;
-
-			//OpenSSL_add_all_algorithms();
-
-			SSL_library_init();
-			SSL_load_error_strings();
-
-			if ( !(ctx = SSL_CTX_new(TLSv1_server_method())) )
-			{
-				printf("Error creating the context.\n");
-				exit(0);
-			}
-
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-
-			jabberssl = SSL_new(ctx);
-
-			puts("#1");
-			err=SSL_set_fd(jabberssl, jabber_fd);
-			if ( err < 1 )
-			{
-				puts("shsfghdfgh");
-				SSL_CTX_free(ctx);
-			}
-
-			puts("connect");
-			err = SSL_connect(jabberssl);
-			if ( err < 1 )
-			{
-				puts("client");
-				err = SSL_get_error(jabberssl, err);
-				printf("%d\n", err);
-				char err_str[1024];
-				ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
-				printf("%s\n", err_str);
-				SSL_CTX_free(ctx);
-			}
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		puts("end loop");
-		usleep(500000);
-	}
-
-    if ( close(jabber_fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	/*---------------------------------------------------*/
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/teste.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/teste.c	(revision 151)
+++ 	(revision )
@@ -1,200 +1,0 @@
-#include "unp.h"
-#include "xmpp.h"
-#include <malloc.h>
-
-//#define HOST "im.pr.gov.br"
-//#define IP "200.189.113.148"
-//#define HOST "localhost"
-//#define IP "10.15.20.42"
-#define HOST "im.celepar.parana"
-#define IP "10.15.20.219"
-#define PORT "5222"
-
-
-int tls = 0;
-
-void Read(void * fd, void *buf, int count)
-{
-	bzero(buf, count);
-	if ( tls == 0 )
-		read(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_read((SSL *) fd, buf, count);
-}
-
-void Write(void * fd, void *buf, int count)
-{
-	if ( tls == 0 )
-		write(*(int *) fd, buf, (ssize_t)count);
-	else
-		SSL_write((SSL *) fd, buf, count);
-}
-
-int main(void)
-{
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-	int err,
-		i,
-		unit;
-	extern int tls;
-	char buff[4096];
-	char * xml = (char)NULL;
-
-	/*SSL PART*/
-	//SSL_METHOD *meth;
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-	/*SSL PART*/
-
-	xml = (char *) malloc(sizeof(__CONNECT__));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	//socketaddr.sin_addr.s_addr = INADDR_ANY;//inet_addr(IP);
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	//OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	//SSL_load_error_strings();
-
-	//meth=TLSv1_client_method();
-
-	//ctx=SSL_CTX_new(TLSv1_client_method());
-	if ( !(ctx = SSL_CTX_new(TLSv1_client_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	//fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NDELAY | O_NONBLOCK);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	sprintf(xml, __CONNECT__, HOST);
-	Write(&socketfd, xml, strlen(xml));
-	//usleep(500);
-	int stop = 0;
-	do
-	{
-		Read (&socketfd, buff, sizeof(buff));
-		if ( strstr(buff, __FEATURES_BEGIN__) )
-			stop = 1;
-		else
-			usleep(100);
-	}
-	while ( !stop );
-
-puts(buff);
-	stop = 0;
-	int starttls = 0;
-
-	if ( strstr(buff, __STARTTLS_SERVER__) )
-		starttls = 1;
-
-/*	if ( !strstr(buff, __FEATURES_END__) )
-	{
-		do
-		{
-			Read (&socketfd, buff, sizeof(buff));
-			if ( strstr(buff, __STARTTLS_SERVER__) )
-				starttls = 1;
-			if ( strstr(buff, __FEATURES_END__) )
-				stop = 1;
-			else
-				usleep(100);
-		}
-		while ( !stop );
-	}*/
-
-	if ( starttls )
-	{
-		sprintf(xml, __STARTTLS_CLIENT__);
-		Write(&socketfd, xml, strlen(xml));
-
-		stop = 0;
-		do
-		{
-			Read (&socketfd, buff, sizeof(buff));
-			if ( strstr(buff, __PROCEED__) )
-				stop = 1;
-			else
-				usleep(100);
-		}
-		while ( !stop );
-		printf("%s\n\n", buff);
-		bzero(buff, 4096);
-
-		SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-		/*Create new ssl object*/
-		myssl=SSL_new(ctx);
-
-		if(!myssl){
-			printf("Error creating SSL structure.\n");
-			exit(0);
-		}
-
-		/*Bind the socket to the SSL structure*/
-		SSL_set_fd(myssl,socketfd);
-
-		/*Connect to the server, SSL layer.*/
-		err=SSL_connect(myssl);
-		printf("SSL error #%d in accept,program terminated\n",err);
-		/*Check for error in connect.*/
-		if (err<1) {
-
-			err=SSL_get_error(myssl,err);
-			printf("SSL error #%d in accept,program terminated\n",err);
-			printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-			if(err==5){printf("sockerrno is:\n");}
-
-			close(socketfd);
-			SSL_CTX_free(ctx);
-			exit(0);
-		}
-
-		tls = 1;
-
-		/*Print out connection details*/
-		printf("SSL connection on socket %x,Version: %s, Cipher: %s\n\n\n",
-				socketfd,
-				SSL_get_version(myssl),
-				SSL_get_cipher(myssl));
-
-		sprintf(xml, __CONNECT__, HOST);
-		SSL_write(myssl, xml, strlen(xml));
-		usleep(10000);
-		SSL_read(myssl, buff, sizeof(buff));
-		printf("%s\n\n", buff);
-		bzero(buff, 4096);
-
-		usleep(10000);
-		SSL_read(myssl, buff, sizeof(buff));
-		printf("%s\n\n", buff);
-		bzero(buff, 4096);
-
-		SSL_clear(myssl);
-		SSL_shutdown(myssl);
-		SSL_free(myssl);
-		SSL_CTX_free(ctx);
-	}
-	fflush(stdin);
-    fflush(stdout);
-	exit(0);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/xmpp.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/xmpp.h	(revision 151)
+++ 	(revision )
@@ -1,9 +1,0 @@
-#define __CONNECT__	"<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='%s' version='1.0'>"
-
-#define __FEATURES_BEGIN__ "<stream:features"
-#define __FEATURES_END__ "</stream:features>"
-
-#define __STARTTLS_SERVER__	"<starttls"
-#define __STARTTLS_CLIENT__	"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
-
-#define __PROCEED__		"<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/cexcept.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/cexcept.h	(revision 151)
+++ 	(revision )
@@ -1,244 +1,0 @@
-/*===
-cexcept.h 1.0.0 (2000-Jun-21-Wed)
-Adam M. Costello <amc@cs.berkeley.edu>
-
-An interface for exception-handling in ANSI C, developed jointly with
-Cosmin Truta <cosmin@cs.toronto.edu>.
-
-    Copyright (c) 2000 Adam M. Costello and Cosmin Truta.  Everyone
-    is hereby granted permission to do whatever they like with this
-    file, provided that if they modify it they take reasonable steps to
-    avoid confusing or misleading people about the authors, version,
-    and terms of use of the derived file.  The copyright holders make
-    no guarantees about the correctness of this file, and are not
-    responsible for any damage resulting from its use.
-
-If this interface is used by multiple .c files, they shouldn't include
-this header file directly.  Instead, create a wrapper header file that
-includes this header file and then invokes the define_exception_type
-macro (see below), and let your .c files include that header file.
-
-The interface consists of one type, one well-known name, and six macros.
-
-
-define_exception_type(type_name);
-
-    This macro is used like an external declaration.  It specifies
-    the type of object that gets copied from the exception thrower to
-    the exception catcher.  The type_name can be any type that can be
-    assigned to, that is, a non-constant arithmetic type, struct, union,
-    or pointer.  Examples:
-
-        define_exception_type(int);
-
-        enum exception { out_of_memory, bad_arguments, disk_full };
-        define_exception_type(enum exception);
-
-        struct exception { int code; const char *msg; };
-        define_exception_type(struct exception);
-
-
-struct exception_context;
-
-    This type may be used after the define_exception_type() macro has
-    been invoked.  A struct exception_context must be known to both
-    the thrower and the catcher.  It is expected that there be one
-    context for each thread that uses exceptions.  It would certainly
-    be dangerous for multiple threads to access the same context.
-    One thread can use multiple contexts, but that is likely to be
-    confusing and not typically useful.  The application can allocate
-    this structure in any way it pleases--automatic, static, or dynamic.
-    The application programmer should pretend not to know the structure
-    members, which are subject to change.
-
-
-struct exception_context *the_exception_context;
-
-    The Try/Catch and Throw statements (described below) implicitly
-    refer to a context, using the name the_exception_context.  It is
-    the application's responsibility to make sure that this name yields
-    the address of a mutable (non-constant) struct exception_context
-    wherever those statements are used.  Subject to that constraint, the
-    application may declare a variable of this name anywhere it likes
-    (inside a function, in a parameter list, or externally), and may
-    use whatever storage class specifiers (static, extern, etc) or type
-    qualifiers (const, volatile) it likes.  Examples:
-
-        static struct exception_context
-          * const the_exception_context = &foo;
-
-        { struct exception_context *the_exception_context = bar; ... }
-
-        int blah(struct exception_context *the_exception_context, ...);
-
-        extern struct exception_context the_exception_context[1];
-
-    The last example illustrates a trick that avoids creating a pointer
-    object separate from the structure object.
-
-    The name could even be a macro, for example:
-
-        struct exception_context ec_array[numthreads];
-        #define the_exception_context (ec_array + thread_id)
-
-    Be aware that the_exception_context is used several times by the
-    Try/Catch/Throw macros, so it shouldn't be expensive or have side
-    effects.  The expansion must be a drop-in replacement for an
-    identifier, so it's safest to put parentheses around it.
-
-
-void init_exception_context(struct exception_context *ec);
-
-    For context structures allocated statically (by an external
-    definition or using the "static" keyword), the implicit
-    initialization to all zeros is sufficient, but contexts allocated
-    by other means must be initialized using this macro before they
-    are used by a Try/Catch statement.  It does no harm to initialize
-    a context more than once (by using this macro on a statically
-    allocated context, or using this macro twice on the same context),
-    but a context must not be re-initialized after it has been used by a
-    Try/Catch statement.
-
-
-Try statement
-Catch (expression) statement
-
-    The Try/Catch/Throw macros are capitalized in order to avoid
-    confusion with the C++ keywords, which have subtly different
-    semantics.
-
-    A Try/Catch statement has a syntax similar to an if/else
-    statement, except that the parenthesized expression goes after
-    the second keyword rather than the first.  As with if/else,
-    there are two clauses, each of which may be a simple statement
-    ending with a semicolon or a brace-enclosed compound statement.
-    But whereas the else clause is optional, the Catch clause is
-    required.  The expression must be a modifiable lvalue (something
-    capable of being assigned to) of the exact same type passed to
-    define_exception_type().
-
-    If a Throw that uses the same exception context as the Try/Catch is
-    executed within the Try clause (typically within a function called
-    by the Try clause), and the exception is not caught by a nested
-    Try/Catch statement, then a copy of the exception will be assigned
-    to the expression, and control will jump to the Catch clause.  If no
-    such Throw is executed, then the assignment is not performed, and
-    the Catch clause is not executed.
-
-    Regardless of whether an exception is caught, the expression is
-    always evaluated exactly once, which is significant if it has side
-    effects, for example:
-
-        Try foo();
-        Catch (p[++i].e) { ... }
-
-    IMPORTANT: Jumping into or out of a Try clause (for example via
-    return, break, continue, goto, longjmp) is forbidden--the compiler
-    will not complain, but bad things will happen at run-time.  Jumping
-    into or out of a Catch clause is okay, and so is jumping around
-    inside a Try clause.  In many cases where one is tempted to return
-    from a Try clause, it will suffice to use Throw, and then return
-    from the Catch clause.  Another option is to set a flag variable and
-    use goto to jump to the end of the Try clause, then check the flag
-    after the Try/Catch statement.
-
-    IMPORTANT: The values of any non-volatile automatic variables
-    changed within the Try clause are undefined after an exception is
-    caught.  Therefore, variables modified inside the Try block whose
-    values are needed later outside the Try block must either use static
-    storage or be declared with the "volatile" type qualifier.
-
-
-Throw expression;
-
-    A Throw statement is very much like a return statement, except that
-    the expression is required.  Whereas return jumps back to the place
-    where the current function was called, Throw jumps back to the Catch
-    clause of the innermost enclosing Try clause.  The expression must
-    be compatible with the type passed to define_exception_type().  The
-    exception must be caught, otherwise the program may crash.
-
-    Slight limitation:  If the expression is a comma-expression it must
-    be enclosed in parentheses.
-
-
-Try statement
-Catch_anonymous statement
-
-    When the value of the exception is not needed, a Try/Catch statement
-    can use Catch_anonymous instead of Catch (expression).
-
-
-Everything below this point is for the benefit of the compiler.  The
-application programmer should pretend not to know any of it, because it
-is subject to change.
-
-===*/
-
-
-#ifndef CEXCEPT_H
-#define CEXCEPT_H
-
-
-#include <setjmp.h>
-
-#define define_exception_type(etype) \
-struct exception__state { \
-  etype *exception; \
-  jmp_buf env; \
-}
-
-struct exception_context { \
-  struct exception__state *last; \
-  int caught; \
-};
-
-#define init_exception_context(ec) ((void)((ec)->last = 0))
-
-#define Catch(e) exception__catch(&(e))
-#define Catch_anonymous exception__catch(0)
-
-#define Try \
-  { \
-    struct exception__state *exception__p, exception__s; \
-    int exception__i; \
-    exception__p = the_exception_context->last; \
-    the_exception_context->last = &exception__s; \
-    for (exception__i = 0; ; exception__i = 1) \
-      if (exception__i) { \
-        if (setjmp(exception__s.env) == 0) { \
-          if (&exception__s)
-
-#define exception__catch(e_addr) \
-          else { } \
-          the_exception_context->caught = 0; \
-        } \
-        else the_exception_context->caught = 1; \
-        the_exception_context->last = exception__p; \
-        break; \
-      } \
-      else exception__s.exception = e_addr; \
-  } \
-  if (!the_exception_context->caught) { } \
-  else
-
-/* Try ends with if(), and Catch begins and ends with else.  This     */
-/* ensures that the Try/Catch syntax is really the same as the        */
-/* if/else syntax.                                                    */
-/*                                                                    */
-/* We use &exception__s instead of 1 to appease compilers that        */
-/* warn about constant expressions inside if().  Most compilers       */
-/* should still recognize that &exception__s is never zero and avoid  */
-/* generating test code.                                              */
-/*                                                                    */
-/* We use the variable exception__i to start the loop at the bottom,  */
-/* rather than jump into the loop using a switch statement, to        */
-/* appease compilers that warn about jumping into loops.              */
-
-#define Throw \
-  for (;; longjmp(the_exception_context->last->env, 1)) \
-    if (the_exception_context->last->exception) \
-      *the_exception_context->last->exception =
-
-
-#endif /* CEXCEPT_H */
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/mycert.pem
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/mycert.pem	(revision 151)
+++ 	(revision )
@@ -1,34 +1,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDY8Tao9bylsCI6LVR8yWWO7HgfnQQCwh2cqigKHaSnuo5n67R5
-Cp7dAbYkVf1V7BZ+V3nn7eVQ2FXcb8BooBQY51J9j7Q75IT5AZRar1ket5pRnVJH
-THGpm8trQsP54gV14lRToI36zXFzxakR08B1iKRyyLUVwp8RvAUxS+kKHwIDAQAB
-AoGAFIbWTixaOi8tPeX2HYyM0HYtc4hOzdgCJ0WuXi6p2rj7KngR7nYDzBOSYWPF
-gbDB/BhYz4oh7YFatm3Yfc3PuNLbuTxaMuuevDl9Qy+0cVI3FL7ban5jgEXMZVB8
-rgIfxmem8Kj7Eu/WtF/UJiz+epJQgrndlNtWJTWSDHoLRqkCQQD3lf4kRwiJJrAS
-Hj48/FVaR+0nvcEia7YsF44is8Yd++BG1tKNZZaKpdhssVA/9Pd+8hC9Sqzji+Mc
-ZXdbAoh1AkEA4FCeoH/ZfWZ3KfCyGfK6T2SEf3tJB/bleFg1mdmv9INuk6HSKMKW
-62mhxAk4DjcYcoM8QSeAE4FN7aOwB3OVwwJAeL/7qf/G5vUqbDu5yQ6cJiLsRDSk
-rD/yIkD+vmgFWPxOHt6I5BNGv6oxCpnT9M1po801Ysy302aXRnMqKgXrPQJBAMYG
-ZgNK2rXZv1lHI/PEVLXCBzaDn/VoASw8sxUfGDbD0NqEAQP6xUEN/8EQYmwqN2rg
-cFEUjfyqKiGgX8Y0RAECQGTEkKvhDzgyyphx5JkYem7sAUI7gFGKZxJaVU+KkN5e
-pU4pgNiFUT0uTbfFzzOYQKeyVlBqGiv7rVn3BO3pfV4=
------END RSA PRIVATE KEY-----
------BEGIN CERTIFICATE-----
-MIIDKzCCApSgAwIBAgIJAOkSDgQDK1oGMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkJSMQswCQYDVQQIEwJQUjEMMAoGA1UEBxMDQ1dCMQ0wCwYDVQQKEwRTQ0tU
-MQ0wCwYDVQQLEwRzY2t0MSUwIwYDVQQDExxlY2VsZXBhcjkxMTM3LmNlbGVwYXIu
-cGFyYW5hMB4XDTA3MDgwOTE2Mzg0MVoXDTA4MDgwODE2Mzg0MVowbTELMAkGA1UE
-BhMCQlIxCzAJBgNVBAgTAlBSMQwwCgYDVQQHEwNDV0IxDTALBgNVBAoTBFNDS1Qx
-DTALBgNVBAsTBHNja3QxJTAjBgNVBAMTHGVjZWxlcGFyOTExMzcuY2VsZXBhci5w
-YXJhbmEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANjxNqj1vKWwIjotVHzJ
-ZY7seB+dBALCHZyqKAodpKe6jmfrtHkKnt0BtiRV/VXsFn5Xeeft5VDYVdxvwGig
-FBjnUn2PtDvkhPkBlFqvWR63mlGdUkdMcamby2tCw/niBXXiVFOgjfrNcXPFqRHT
-wHWIpHLItRXCnxG8BTFL6QofAgMBAAGjgdIwgc8wHQYDVR0OBBYEFDqDGL/fTaKt
-NtkTuuzBet9mgcSOMIGfBgNVHSMEgZcwgZSAFDqDGL/fTaKtNtkTuuzBet9mgcSO
-oXGkbzBtMQswCQYDVQQGEwJCUjELMAkGA1UECBMCUFIxDDAKBgNVBAcTA0NXQjEN
-MAsGA1UEChMEU0NLVDENMAsGA1UECxMEc2NrdDElMCMGA1UEAxMcZWNlbGVwYXI5
-MTEzNy5jZWxlcGFyLnBhcmFuYYIJAOkSDgQDK1oGMAwGA1UdEwQFMAMBAf8wDQYJ
-KoZIhvcNAQEFBQADgYEAVHm/1+iybB3u48nP0NDIocPIhUC55e8iL9h0GOmvJalp
-IpCeIuefCTPCkrJHNMSVNqz6q3UfJLNXe91UdaAYvXEqWLP0mYUz5DWnzUYIIb/y
-W1BZ2WqcX8KZeJJgF/Gu0BJj5oGaf8LMVQoS58TiWgQABg1UTFHnHoXJhABQ1Qo=
------END CERTIFICATE-----
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server_bkp_20071009.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server_bkp_20071009.c	(revision 151)
+++ 	(revision )
@@ -1,444 +1,0 @@
-#include "server.h"
-
-/* Globally accessible storage for the exception context: */
-struct exception_context the_exception_context[1];
-
-#define HOST "im.celepar.parana"
-#define IP "10.15.20.219"
-#define PORT "5222"
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	SSL_CTX * ctx;
-
-	pthread_t threads;
-
-	// clear screen
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				// -f or -o without operand
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-	if ( !(ctx = SSL_CTX_new(SSLv23_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	if ( SSL_CTX_set_cipher_list(ctx, CIPHER_LIST) < 1 )
-	{
-		printf("Error setting the cipher list.\n");
-		exit(0);
-	}
-
-	//Indicate the certificate file to be used
-	if ( SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the certificate file.\n");
-		exit(0);
-	}
-
-	//Load the password for the Private Key
-	SSL_CTX_set_default_passwd_cb_userdata(ctx, KEY_PASSWD);
-
-	//Indicate the key file to be used
-	if ( SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the key file.\n");
-		exit(0);
-	}
-
-	//Make sure the key and certificate file match
-	if ( !SSL_CTX_check_private_key(ctx) )
-	{
-		printf("Private key does not match the certificate public key\n");
-		exit(0);
-	}
-
-	// Set the list of trusted CAs based on the file and/or directory provided
-	if ( SSL_CTX_load_verify_locations(ctx, CA_FILE, CA_DIR) < 1 )
-	{
-		printf("Error setting verify location\n");
-		exit(0);
-	}
-
-	// Set for server verification
-	SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-		fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-
-		if ( socket_accept_fd > -1 )
-		{
-			if ( clients == (struct client *) NULL )
-				current = clients;
-			else
-				while ( (current = clients->next) != (struct client *) NULL );
-
-			current				= (struct client *) malloc(sizeof(struct client));
-			current->next		= (struct client *) NULL;
-			current->fd			= socket_accept_fd;
-			current->sockaddr	= accept_addr;
-			current->ctx		= ctx;
-			current->last		= time(NULL);
-
-			pthread_create(&(threads), NULL, handler, (void *) current);
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err, e;
-	time_t last;
-
-	int tls = 0;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-
-	char buff[4096];
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-
-	char * old_host,
-		 * replace_host;
-
-	replace_host = (char *) malloc(__BUFFER_SIZE__*sizeof(char));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	if ( !(ctx = SSL_CTX_new(SSLv23_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	while ( client_is_connected != 0 )
-	{
-		// read from client
-		//puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( !tls )
-			client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__);
-		else
-			client_is_connected = SSL_read(client->myssl, buffer_client, __BUFFER_SIZE__);
-
-		if ( client_is_connected != 0 )
-		{
-			if ( strlen(buffer_jabber) > 0 )
-			{
-				puts("\twriting - client");
-				printf("\t%s\n\n", buffer_jabber);
-				// write in the client
-				Try
-				{
-					if ( !tls )
-						write(client->fd, buffer_jabber, strlen(buffer_jabber));
-					else
-						SSL_write(client->myssl, buffer_jabber, strlen(buffer_jabber));
-				}
-				Catch(e) fprintf(stderr, "exception %d\n", e);
-				puts("\twrote - client");
-			}
-
-			if ( strstr(buffer_client, "<stream:stream") && (old_host = strstr(buffer_client, "to=")) )
-			{
-				bzero(replace_host, __BUFFER_SIZE__);
-				strncpy(replace_host, buffer_client, (strlen(buffer_client) - strlen(old_host))+4);
-				strcat(replace_host, HOST);
-				old_host = strstr(old_host, " ");
-				old_host--;
-				strcat(replace_host, old_host);
-				bzero(buffer_client, __BUFFER_SIZE__);
-				strcpy(buffer_client, replace_host);
-			}
-		}
-
-		// read from jabber service
-		//puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-
-		if ( !tls )
-			jabber_is_connected = read(socketfd, buffer_jabber, __BUFFER_SIZE__);
-		else
-			jabber_is_connected = SSL_read(myssl, buffer_jabber, __BUFFER_SIZE__);
-
-
-		if ( jabber_is_connected != 0 && strlen(buffer_client) > 0 )
-		{
-			puts("\twriting - jabber");
-			printf("\t%s\n\n", buffer_client);
-			// write in the jabber service
-			Try
-			{
-				if ( !tls )
-					write(socketfd, buffer_client, strlen(buffer_client));
-				else
-					SSL_write(myssl, buffer_client, strlen(buffer_client));
-			}
-			Catch(e) fprintf(stderr, "exception %d\n", e);
-			puts("\twrote - jabber");
-		}
-
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			puts("\tbegin tls with jabber");
-			fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & ~O_NONBLOCK & ~O_NDELAY);
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-			//Create new ssl object
-			myssl = SSL_new(ctx);
-
-			if ( !myssl )
-			{
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(myssl, socketfd);
-
-			//Connect to the server, SSL layer.
-			err = SSL_connect(myssl);
-			//printf("SSL error #%d in accept,program terminated\n",err);
-			//Check for error in connect.
-			if ( err < 1 )
-			{
-				err = SSL_get_error(myssl,err);
-				printf("SSL error #%d in accept, program terminated\n",err);
-				printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-				if(err==5){printf("sockerrno is:\n");}
-
-				SSL_CTX_free(ctx);
-				client_is_connected = 0;
-			}
-
-			fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-			puts("\tend tls with jabber");
-
-			puts("\twriting proceed in the client");
-			printf("%s - %d\n", buffer_jabber, strlen(buffer_jabber));
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-			bzero(buffer_jabber, __BUFFER_SIZE__);
-
-			puts("\tbegin tls with client");
-			fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK & ~O_NDELAY );
-
-			//Create new ssl object
-			if( !(client->myssl = SSL_new(client->ctx)) )
-			{
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(client->myssl, client->fd);
-
-			//Connect to the server, SSL layer.
-			err = SSL_accept(client->myssl);
-
-			//Check for error in connect.
-			if ( err < 1 )
-			{
-				printf("SSL error #%d in accept,program terminated\n", err);
-				err = SSL_get_error(client->myssl, 0);
-				printf("SSL error #%d in accept,program terminated\n", err);
-
-				switch ( err )
-				{
-					case SSL_ERROR_NONE : puts("SSL_ERROR_NONE");break;
-					case SSL_ERROR_SSL : puts("SSL_ERROR_SSL");break;
-					case SSL_ERROR_WANT_READ : puts("SSL_ERROR_WANT_READ");
-				}
-
-				if ( err == 5 )
-					printf("sockerrno is: %d\n", err);
-
-
-				SSL_CTX_free(client->ctx);
-				client_is_connected = 0;
-			}
-			fcntl(client->fd, F_SETFL, fcntl(client->fd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-			puts("\tend tls with client");
-
-			tls = 1;
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		//puts("end loop");
-		usleep(1000);
-	}
-	puts("\n=========================\n");
-    if ( close(socketfd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	//---------------------------------------------------
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server.c
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server.c	(revision 151)
+++ 	(revision )
@@ -1,452 +1,0 @@
-#include "server.h"
-
-/* Globally accessible storage for the exception context: */
-struct exception_context the_exception_context[1];
-
-//#define HOST "im.celepar.parana"
-//#define IP "10.15.20.219"
-#define HOST "im.pr.gov.br"
-#define IP "200.189.113.148"
-#define PORT "5222"
-
-int main(int argc, char ** argv)
-{
-	/* variables to parse arguments */
-	extern int optind,
-			   optopt;
-	extern char * optarg;
-
-	char * log_file;
-	int c		= (int)NULL,
-		errflg	= (int)NULL,
-		verbose	= (int)NULL,
-		optval	= 1,
-		pid;
-
-	socklen_t optlen = sizeof(optval);
-
-	/* fd -> file descriptor */
-	int socket_server_fd	= (int)NULL,
-		socket_server_port	= (int)NULL,
-		socket_accept_fd	= (int)NULL,
-		sockaddr_in_size	= sizeof(struct sockaddr_in),
-		err					= (int)NULL;
-
-	/* Internet socket address stuct */
-	struct sockaddr_in server_addr,
-					   accept_addr;
-
-	struct client * clients = (struct client *) NULL,
-				  * current = (struct client *) NULL;
-
-	SSL_CTX * ctx;
-
-	pthread_t threads;
-
-	// clear screen
-	system(__CLEAR_SCREEN__);
-
-	while ( (c = getopt(argc, argv, ":vp:")) != -1 )
-	{
-		switch ( c )
-		{
-			case 'p':
-				if ( socket_server_port = strtol(optarg, 0, 10) == 0 )
-				{
-					fprintf(stderr, "Option -%c requires a valid port and '%s' isn't valid\n", optopt, optarg);
-					++errflg;
-				}
-				break;
-			case 'v':
-				verbose = 1;
-				break;
-			case ':':
-				// -f or -o without operand
-				fprintf(stderr, "Option -%c requires an operand\n", optopt);
-				++errflg;
-				break;
-			case '?':
-				fprintf(stderr, "Unrecognized option: -%c\n", optopt);
-				++errflg;
-		}
-	}
-	if ( errflg )
-	{
-		fprintf(stderr, "usage: . . . \n\n");
-		exit(2);
-	}
-
-	OpenSSL_add_all_algorithms();
-	SSL_library_init();
-	SSL_load_error_strings();
-
-	/* make a socket */
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if ( socket_server_fd == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not make a socket\n");
-		return 0;
-	}
-
-	bzero((char *) &server_addr, sockaddr_in_size);
-	bzero((char *) &accept_addr, sockaddr_in_size);
-
-	if ( !socket_server_port )
-		socket_server_port = __DEFAULT_OPEN_PORT__;
-
-	/* fill address struct */
-	server_addr.sin_addr.s_addr	= INADDR_ANY;
-	server_addr.sin_port		= htons(socket_server_port);
-	server_addr.sin_family		= AF_INET;
-	bzero(&(server_addr.sin_zero), 8);
-
-	if ( __DEBUG__  || verbose )
-		printf("\nBinding to port %d...\n", socket_server_port);
-
-	/* bind to a port */
-	if ( bind(socket_server_fd, (struct sockaddr *)&(server_addr), sizeof(server_addr)) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not connect to host\n");
-		exit(1);
-	}
-
-	/* get port number */
-	getsockname(socket_server_fd, (struct sockaddr *)&(server_addr), (socklen_t *) &(sockaddr_in_size));
-	if ( __DEBUG__  || verbose )
-	{
-		printf("\nopened socket as fd (%d) on port (%d) for stream i/o\n", socket_server_fd, ntohs(server_addr.sin_port));
-
-		printf("Server\n\
-				sin_family        = %d\n\
-				sin_addr.s_addr   = %d\n\
-				sin_port          = %d\n"
-				, server_addr.sin_family
-				, server_addr.sin_addr.s_addr
-				, ntohs(server_addr.sin_port)
-			  );
-		printf("\nMaking a listen queue of %d elements", __QUEUE_SIZE__);
-	}
-
-	/* establish listen queue */
-	if ( listen(socket_server_fd, __QUEUE_SIZE__) == __SOCKET_ERROR__ )
-	{
-		printf("\nCould not listen\n");
-		return 0;
-	}
-
-	for ( ; ; )
-	{
-		if ( __DEBUG__  || verbose )
-			puts("\nWaiting for a connection\n");
-
-		/* get the connected socket */
-		socket_accept_fd = accept(socket_server_fd, (struct sockaddr *) &(accept_addr), (socklen_t *) &(sockaddr_in_size));
-
-		if ( socket_accept_fd > -1 )
-		{
-			pid = fork();
-			if ( pid == 0 )
-			{
-	if ( !(ctx = SSL_CTX_new(SSLv23_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	if ( SSL_CTX_set_cipher_list(ctx, CIPHER_LIST) < 1 )
-	{
-		printf("Error setting the cipher list.\n");
-		exit(0);
-	}
-
-	//Indicate the certificate file to be used
-	if ( SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the certificate file.\n");
-		exit(0);
-	}
-
-	//Load the password for the Private Key
-	SSL_CTX_set_default_passwd_cb_userdata(ctx, KEY_PASSWD);
-
-	//Indicate the key file to be used
-	if ( SSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) < 1 )
-	{
-		printf("Error setting the key file.\n");
-		exit(0);
-	}
-
-	//Make sure the key and certificate file match
-	if ( !SSL_CTX_check_private_key(ctx) )
-	{
-		printf("Private key does not match the certificate public key\n");
-		exit(0);
-	}
-
-	// Set the list of trusted CAs based on the file and/or directory provided
-	if ( SSL_CTX_load_verify_locations(ctx, CA_FILE, CA_DIR) < 1 )
-	{
-		printf("Error setting verify location\n");
-		exit(0);
-	}
-
-	// Set for server verification
-	SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
-
-				fcntl(socket_accept_fd, F_SETFL, fcntl(socket_accept_fd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-
-				if ( clients == (struct client *) NULL )
-					current = clients;
-				else
-					while ( (current = clients->next) != (struct client *) NULL );
-
-				current				= (struct client *) malloc(sizeof(struct client));
-				current->next		= (struct client *) NULL;
-				current->fd			= socket_accept_fd;
-				current->sockaddr	= accept_addr;
-				current->ctx		= ctx;
-				current->last		= time(NULL);
-
-				pthread_create(&(threads), NULL, handler, (void *) current);
-			}
-		}
-	}
-	pthread_exit(NULL);
-}
-
-void * handler(void * pClient)
-{
-    char buffer_client[__BUFFER_SIZE__],
-		 buffer_jabber[__BUFFER_SIZE__];
-    struct client * client = (struct client *) pClient;
-    int i = 0, err, e;
-	time_t last;
-
-	int tls = 0;
-
-	char ip[46];
-	unsigned short port;
-	inet_ntop(AF_INET, &(client->sockaddr.sin_addr), ip, sizeof (ip));
-	port = ntohs(client->sockaddr.sin_port);
-	printf("\nGot a connection from %s, port %hu\n", ip, port);
-	/*---------------------------------------------------*/
-
-	int client_is_connected = -1;
-	int jabber_is_connected = -1;
-
-	struct sockaddr_in socketaddr;
-	int socketfd,
-		nHostPort;
-
-	char buff[4096];
-	SSL_CTX  *ctx;
-	SSL  *myssl;
-
-	char * old_host,
-		 * replace_host;
-
-	replace_host = (char *) malloc(__BUFFER_SIZE__*sizeof(char));
-
-	if ( (nHostPort = strtol(PORT, 0, 10)) == 0 )
-	{
-		printf("\n<port>\n\n");
-		printf("\ncould not make a socket\n");
-		return 0;
-	}
-
-	socketfd = socket(AF_INET, SOCK_STREAM, 0);
-
-	socketaddr.sin_family = AF_INET;
-	socketaddr.sin_addr.s_addr = inet_addr(IP);
-	socketaddr.sin_port = htons(nHostPort);
-
-	if ( !(ctx = SSL_CTX_new(SSLv23_method())) )
-	{
-		printf("Error creating the context.\n");
-		exit(0);
-	}
-
-	err = connect(socketfd, (struct sockaddr*)&socketaddr, sizeof(socketaddr));
-	fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-
-	if ( err < 0 )
-	{
-		printf("Socket returned error #%d,program terminated\n", err);
-		exit(0);
-	}
-
-	while ( client_is_connected != 0 )
-	{
-		// read from client
-		//puts("\tread - client");
-		bzero(buffer_client, __BUFFER_SIZE__);
-		if ( !tls )
-			client_is_connected = read(client->fd, buffer_client, __BUFFER_SIZE__);
-		else
-			client_is_connected = SSL_read(client->myssl, buffer_client, __BUFFER_SIZE__);
-
-		if ( client_is_connected != 0 )
-		{
-			if ( strlen(buffer_jabber) > 0 )
-			{
-				puts("\twriting - client");
-				printf("\t%s\n\n", buffer_jabber);
-				// write in the client
-				Try
-				{
-					if ( !tls )
-						write(client->fd, buffer_jabber, strlen(buffer_jabber));
-					else
-						SSL_write(client->myssl, buffer_jabber, strlen(buffer_jabber));
-				}
-				Catch(e) fprintf(stderr, "exception %d\n", e);
-				puts("\twrote - client");
-			}
-
-			if ( strstr(buffer_client, "<stream:stream") && (old_host = strstr(buffer_client, "to=")) )
-			{
-				bzero(replace_host, __BUFFER_SIZE__);
-				strncpy(replace_host, buffer_client, (strlen(buffer_client) - strlen(old_host))+4);
-				strcat(replace_host, HOST);
-				old_host = strstr(old_host, " ");
-				old_host--;
-				strcat(replace_host, old_host);
-				bzero(buffer_client, __BUFFER_SIZE__);
-				strcpy(buffer_client, replace_host);
-			}
-		}
-
-		// read from jabber service
-		//puts("\tread - jabber");
-		bzero(buffer_jabber, __BUFFER_SIZE__);
-
-		if ( !tls )
-			jabber_is_connected = read(socketfd, buffer_jabber, __BUFFER_SIZE__);
-		else
-			jabber_is_connected = SSL_read(myssl, buffer_jabber, __BUFFER_SIZE__);
-
-
-		if ( jabber_is_connected != 0 && strlen(buffer_client) > 0 )
-		{
-			puts("\twriting - jabber");
-			printf("\t%s\n\n", buffer_client);
-			// write in the jabber service
-			Try
-			{
-				if ( !tls )
-					write(socketfd, buffer_client, strlen(buffer_client));
-				else
-					SSL_write(myssl, buffer_client, strlen(buffer_client));
-			}
-			Catch(e) fprintf(stderr, "exception %d\n", e);
-			puts("\twrote - jabber");
-		}
-
-		if ( strstr(buffer_jabber, "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") )
-		{
-			puts("\tbegin tls with jabber");
-			fcntl( socketfd, F_SETFL, fcntl( socketfd, F_GETFL ) & ~O_NONBLOCK & ~O_NDELAY);
-			SSL_CTX_set_verify(ctx,SSL_VERIFY_NONE,NULL);
-			//Create new ssl object
-			myssl = SSL_new(ctx);
-
-			if ( !myssl )
-			{
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(myssl, socketfd);
-
-			//Connect to the server, SSL layer.
-			err = SSL_connect(myssl);
-			//printf("SSL error #%d in accept,program terminated\n",err);
-			//Check for error in connect.
-			if ( err < 1 )
-			{
-				err = SSL_get_error(myssl,err);
-				printf("SSL error #%d in accept, program terminated\n",err);
-				printf("%d -- %d\n\n", SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE);
-
-				if(err==5){printf("sockerrno is:\n");}
-
-				SSL_CTX_free(ctx);
-				client_is_connected = 0;
-			}
-
-			fcntl(socketfd, F_SETFL, fcntl(socketfd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-			puts("\tend tls with jabber");
-
-			puts("\twriting proceed in the client");
-			printf("%s - %d\n", buffer_jabber, strlen(buffer_jabber));
-			write(client->fd, buffer_jabber, strlen(buffer_jabber));
-			bzero(buffer_jabber, __BUFFER_SIZE__);
-
-			puts("\tbegin tls with client");
-			fcntl( client->fd, F_SETFL, fcntl( client->fd, F_GETFL ) & ~O_NONBLOCK & ~O_NDELAY );
-
-			//Create new ssl object
-			if( !(client->myssl = SSL_new(client->ctx)) )
-			{
-				printf("Error creating SSL structure.\n");
-				exit(0);
-			}
-
-			//Bind the socket to the SSL structure
-			SSL_set_fd(client->myssl, client->fd);
-
-			//Connect to the server, SSL layer.
-			err = SSL_accept(client->myssl);
-
-			//Check for error in connect.
-			if ( err < 1 )
-			{
-				printf("SSL error #%d in accept,program terminated\n", err);
-				err = SSL_get_error(client->myssl, 0);
-				printf("SSL error #%d in accept,program terminated\n", err);
-
-				switch ( err )
-				{
-					case SSL_ERROR_NONE : puts("SSL_ERROR_NONE");break;
-					case SSL_ERROR_SSL : puts("SSL_ERROR_SSL");break;
-					case SSL_ERROR_WANT_READ : puts("SSL_ERROR_WANT_READ");
-				}
-
-				if ( err == 5 )
-					printf("sockerrno is: %d\n", err);
-
-
-				SSL_CTX_free(client->ctx);
-				client_is_connected = 0;
-			}
-			fcntl(client->fd, F_SETFL, fcntl(client->fd, F_GETFL, 0) | O_NONBLOCK | O_NDELAY);
-			puts("\tend tls with client");
-
-			tls = 1;
-		}
-
-		if ( jabber_is_connected == 0 )
-			client_is_connected = jabber_is_connected;
-
-		//puts("end loop");
-		usleep(1000);
-	}
-	puts("\n=========================\n");
-    if ( close(socketfd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close jabber socket\n");
-        return 0;
-    }
-	//---------------------------------------------------
-    if ( close(client->fd) == __SOCKET_ERROR__ )
-    {
-        printf("\nCould not close socket\n");
-        return 0;
-    }
-
-    fflush(stdin);
-    fflush(stdout);
-	free(client);
-    pthread_exit(NULL);
-}
Index: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server.h
===================================================================
--- trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/server.h	(revision 151)
+++ 	(revision )
@@ -1,114 +1,0 @@
-#include <fcntl.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/bio.h>
-
-#include <pthread.h>
-
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-#include "cexcept.h"
-define_exception_type(int);
-extern struct exception_context the_exception_context[1];
-
-void demo_throw(int fail)
-{
-	//fprintf(stderr, "enter demo_throw(%d)\n", fail);
-	if (fail) Throw 42;
-	//fprintf(stderr, "return from demo_throw(%d)\n", fail);
-}
-
-
-/* define max clients per child */
-#ifndef __CLIENTS__
-   #define __CLIENTS__ 100
-#endif
-
-/* define max clients waiting in the queue for connect */
-#ifndef __QUEUE_SIZE__
-	#define __QUEUE_SIZE__ 10
-#endif
-
-/* __SOCKET_ERROR__ must be -1, don't change this */
-#ifndef __SOCKET_ERROR__
-	#define __SOCKET_ERROR__ -1
-#endif
-
-/* open port when this server is activated */
-#ifndef __DEFAULT_OPEN_PORT__
-	#define __DEFAULT_OPEN_PORT__ 8888
-#endif
-
-/* ip of jabber service */
-#ifndef __DEFAULT_JABBER_PORT__
-	#define __DEFAULT_JABBER_PORT__ 5222
-#endif
-
-/* port to connect on jabber service */
-#ifndef __DEFAULT_JABBER_IP__
-	#define __DEFAULT_JABBER_IP__ "im.celepar.parana"
-#endif
-
-/* the jabber's documentation recommends read the packages of socket with size of 4096 (2^12) KB */
-#ifndef __BUFFER_SIZE__
-	#define __BUFFER_SIZE__ 4096
-#endif
-
-#define MESSAGE			"This is the message I'm sending back and forth"
-
-/* Make these what you want for certificate & key files */
-#define CERT_FILE "mycert.pem"
-#define KEY_FILE  "mycert.pem"
-
-/*Cipher list to be used*/
-#define CIPHER_LIST "RC4-MD5"
-
-/*Trusted CAs location*/
-#define CA_FILE CERT_FILE
-#define CA_DIR NULL
-
-/*Password for the key file*/
-#define KEY_PASSWD ""
-
-#ifndef __CLEAR_SCREEN__
-	#define __CLEAR_SCREEN__ "clear"
-#endif
-
-/* 0 -> false; 1 -> true */
-#ifndef __DEBUG__
-	#define __DEBUG__ 0
-#endif
-
-struct client
-{
-	int fd;
-	struct sockaddr_in sockaddr;
-	pthread_t thread;
-	SSL_CTX  *ctx;
-	SSL * myssl;
-	time_t last;
-	struct client * next;
-};
-
-void * handler(void *);
-
-void usage (void)
-{
-	puts("usage: ./server <PORT>\n\n");
-	exit (-1);
-}
