⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libgadu.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
字号:
/* $Id: libgadu.c 16856 2006-08-19 01:13:25Z evands $ *//* *  (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl> *                          Robert J. Wo糿y <speedy@ziew.org> *                          Arkadiusz Mi秌iewicz <arekm@pld-linux.org> *                          Tomasz Chili駍ki <chilek@chilan.com> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU Lesser General Public License Version *  2.1 as published by the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, *  USA. */#include <sys/types.h>#ifndef _WIN32#include <sys/wait.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#ifdef sun#  include <sys/filio.h>#endif#else#include <io.h>#include <fcntl.h>#include <errno.h>#define SHUT_RDWR SD_BOTH#endif#include "libgadu-config.h"#include <errno.h>#ifndef _WIN32#include <netdb.h>#endif#ifdef __GG_LIBGADU_HAVE_PTHREAD#  include <pthread.h>#endif#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#ifdef __GG_LIBGADU_HAVE_OPENSSL#  include <openssl/err.h>#  include <openssl/rand.h>#endif#include "compat.h"#include "libgadu.h"int gg_debug_level = 0;void (*gg_debug_handler)(int level, const char *format, va_list ap) = NULL;int gg_dcc_port = 0;unsigned long gg_dcc_ip = 0;unsigned long gg_local_ip = 0;/* * zmienne opisuj眂e parametry proxy http. */char *gg_proxy_host = NULL;int gg_proxy_port = 0;int gg_proxy_enabled = 0;int gg_proxy_http_only = 0;char *gg_proxy_username = NULL;char *gg_proxy_password = NULL;#ifndef lint static char rcsid[]#ifdef __GNUC____attribute__ ((unused))#endif= "$Id: libgadu.c 16856 2006-08-19 01:13:25Z evands $";#endif #ifdef _WIN32/** *  Deal with the fact that you can't select() on a win32 file fd. *  This makes it practically impossible to tie into purple's event loop. * *  -This is thanks to Tor Lillqvist. *  XXX - Move this to where the rest of the the win32 compatiblity stuff goes when we push the changes back to libgadu. */static intsocket_pipe (int *fds){	SOCKET temp, socket1 = -1, socket2 = -1;	struct sockaddr_in saddr;	int len;	u_long arg;	fd_set read_set, write_set;	struct timeval tv;	temp = socket(AF_INET, SOCK_STREAM, 0);	if (temp == INVALID_SOCKET) {		goto out0;	}	arg = 1;	if (ioctlsocket(temp, FIONBIO, &arg) == SOCKET_ERROR) {		goto out0;	}	memset(&saddr, 0, sizeof(saddr));	saddr.sin_family = AF_INET;	saddr.sin_port = 0;	saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);	if (bind(temp, (struct sockaddr *)&saddr, sizeof (saddr))) {		goto out0;	}	if (listen(temp, 1) == SOCKET_ERROR) {		goto out0;	}	len = sizeof(saddr);	if (getsockname(temp, (struct sockaddr *)&saddr, &len)) {		goto out0;	}	socket1 = socket(AF_INET, SOCK_STREAM, 0);	if (socket1 == INVALID_SOCKET) {		goto out0;	}	arg = 1;	if (ioctlsocket(socket1, FIONBIO, &arg) == SOCKET_ERROR) {		goto out1;	}	if (connect(socket1, (struct sockaddr  *)&saddr, len) != SOCKET_ERROR ||			WSAGetLastError() != WSAEWOULDBLOCK) {		goto out1;	}	FD_ZERO(&read_set);	FD_SET(temp, &read_set);	tv.tv_sec = 0;	tv.tv_usec = 0;	if (select(0, &read_set, NULL, NULL, NULL) == SOCKET_ERROR) {		goto out1;	}	if (!FD_ISSET(temp, &read_set)) {		goto out1;	}	socket2 = accept(temp, (struct sockaddr *) &saddr, &len);	if (socket2 == INVALID_SOCKET) {		goto out1;	}	FD_ZERO(&write_set);	FD_SET(socket1, &write_set);	tv.tv_sec = 0;	tv.tv_usec = 0;	if (select(0, NULL, &write_set, NULL, NULL) == SOCKET_ERROR) {		goto out2;	}	if (!FD_ISSET(socket1, &write_set)) {		goto out2;	}	arg = 0;	if (ioctlsocket(socket1, FIONBIO, &arg) == SOCKET_ERROR) {		goto out2;	}	arg = 0;	if (ioctlsocket(socket2, FIONBIO, &arg) == SOCKET_ERROR) {		goto out2;	}	fds[0] = socket1;	fds[1] = socket2;	closesocket (temp);	return 0;out2:	closesocket (socket2);out1:	closesocket (socket1);out0:	closesocket (temp);	errno = EIO;            /* XXX */	return -1;}#endif/* * gg_libgadu_version() * * zwraca wersj

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -