adium.1-4: 48c2553e: Plucks authorized by Zac West:
rekkanoryo at pidgin.im
rekkanoryo at pidgin.im
Sat Mar 13 23:08:27 EST 2010
-----------------------------------------------------------------
Revision: 48c2553ef4b46482b26f021c97d2569c1b053227
Ancestor: e6348335d02982e12c2be1a30517d7ea46569c51
Author: rekkanoryo at pidgin.im
Date: 2010-03-14T03:30:19
Branch: im.pidgin.adium.1-4
URL: http://d.pidgin.im/viewmtn/revision/info/48c2553ef4b46482b26f021c97d2569c1b053227
Modified files:
libpurple/protocols/gg/Makefile.mingw
libpurple/protocols/gg/buddylist.c
libpurple/protocols/gg/gg.c
libpurple/protocols/gg/lib/common.c
libpurple/protocols/gg/lib/dcc.c
libpurple/protocols/gg/lib/dcc7.c
libpurple/protocols/gg/lib/events.c
libpurple/protocols/gg/lib/http.c
libpurple/protocols/gg/lib/libgadu.c
libpurple/protocols/gg/lib/libgadu.h
libpurple/protocols/gg/lib/pubdir.c
libpurple/protocols/gg/lib/resolver.c
libpurple/protocols/gg/lib/resolver.h
ChangeLog:
Plucks authorized by Zac West:
*** Plucked rev 6f6e595b90a5219711898b80e49ca2ee8f781ed3 (rekkanoryo at pidgin.im):
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
handle all the stuff in resolver.c for DNS resolution. I couldn't quite see how
to reconcile our earlier stuff with this new code. Hopefully a more skilled
Win32 developer can finish this.
*** Plucked rev d21119dede49bb8c2a1cfb45634f4d976f6f0e8b (rekkanoryo at pidgin.im):
Oops, I forgot this. This is done internally in libgadu, and not doing it
produces a ton of warnings in libgadu itself. This does have the unfortunate
side effect of masking the warnings in our Gadu-Gadu prpl, but we can worry
about that once this stuff works everywhere we need it to. Refs #10542.
*** Plucked rev ac8ee7f3a708dfc1481e15258fe9b5c71a7920e7 (kkszysiu at gmail.com):
Finish making libgadu compile on Windows. Fixes #10542 finally!
-------------- next part --------------
============================================================
--- libpurple/protocols/gg/Makefile.mingw 9016708650c8b5beae3603a2d60b409acd92b476
+++ libpurple/protocols/gg/Makefile.mingw 45784aef6932ec04084ccedde84ba868e6757df9
@@ -8,7 +8,7 @@ TARGET = libgg
include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak
TARGET = libgg
-CFLAGS += -include win32dep.h
+CFLAGS += -include win32dep.h -DGG_IGNORE_DEPRECATED
TYPE = PLUGIN
# Static or Plugin...
@@ -50,6 +50,7 @@ C_SRC = \
lib/pubdir.c \
lib/pubdir50.c \
lib/resolver.c \
+ lib/sha1.c \
buddylist.c \
confer.c \
gg.c \
============================================================
--- libpurple/protocols/gg/buddylist.c 98a59485a17634d7a305d42bf324e7f90321cdb4
+++ libpurple/protocols/gg/buddylist.c 76f8244f7c77043a549248df73ed41e8f8e85b38
@@ -82,7 +82,7 @@ void ggp_buddylist_load(PurpleConnection
gchar **users_tbl;
int i;
char *utf8buddylist = charset_convert(buddylist, "CP1250", "UTF-8");
-
+
/* Don't limit the number of records in a buddylist. */
users_tbl = g_strsplit(utf8buddylist, "\r\n", -1);
============================================================
--- libpurple/protocols/gg/gg.c c82da15b84a5ac4ae87b78730b343504530515b2
+++ libpurple/protocols/gg/gg.c 290818cfe57c199e476630452cb9c843ca2af558
@@ -1000,8 +1000,8 @@ static void ggp_generic_status_handler(P
int status, const char *descr)
{
gchar *from;
+ gchar *msg;
const char *st;
- gchar *msg;
gchar *avatarurl;
PurpleUtilFetchUrlData *url_data;
@@ -1018,29 +1018,37 @@ static void ggp_generic_status_handler(P
switch (status) {
case GG_STATUS_NOT_AVAIL:
case GG_STATUS_NOT_AVAIL_DESCR:
- st = "offline";
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE);
break;
+ case GG_STATUS_FFC:
+ case GG_STATUS_FFC_DESCR:
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE);
+ break;
case GG_STATUS_AVAIL:
case GG_STATUS_AVAIL_DESCR:
- st = "available";
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE);
break;
case GG_STATUS_BUSY:
case GG_STATUS_BUSY_DESCR:
- st = "away";
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY);
break;
+ case GG_STATUS_DND:
+ case GG_STATUS_DND_DESCR:
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_UNAVAILABLE);
case GG_STATUS_BLOCKED:
/* user is blocking us.... */
st = "blocked";
break;
default:
- st = "available";
+ st = purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE);
purple_debug_info("gg",
"GG_EVENT_NOTIFY: Unknown status: %d\n", status);
break;
}
purple_debug_info("gg", "st = %s\n", st);
- msg = charset_convert(descr, "CP1250", "UTF-8");
+ //msg = charset_convert(descr, "CP1250", "UTF-8");
+ msg = g_strdup_printf("%s", descr);
purple_prpl_got_user_status(purple_connection_get_account(gc),
from, st, "message", msg, NULL);
g_free(from);
@@ -1078,6 +1086,12 @@ static const char *ggp_status_by_id(unsi
case GG_STATUS_AVAIL_DESCR:
st = _("Available");
break;
+ case GG_STATUS_FFC:
+ case GG_STATUS_FFC_DESCR:
+ return _("Chatty");
+ case GG_STATUS_DND:
+ case GG_STATUS_DND_DESCR:
+ return _("Do Not Disturb");
case GG_STATUS_BUSY:
case GG_STATUS_BUSY_DESCR:
st = _("Away");
@@ -1347,8 +1361,11 @@ static void ggp_recv_message_handler(Pur
from = g_strdup_printf("%lu", (unsigned long int)ev->event.msg.sender);
+ /*
tmp = charset_convert((const char *)ev->event.msg.message,
"CP1250", "UTF-8");
+ */
+ tmp = g_strdup_printf("%s", ev->event.msg.message);
purple_str_strip_char(tmp, '\r');
msg = g_markup_escape_text(tmp, -1);
g_free(tmp);
@@ -1562,7 +1579,7 @@ static void ggp_callback_recv(gpointer _
purple_debug_info("gg", "notify_pre: (%d) status: %d\n",
ev->event.notify->uin,
- ev->event.notify->status);
+ GG_S(ev->event.notify->status));
n = (ev->type == GG_EVENT_NOTIFY) ? ev->event.notify
: ev->event.notify_descr.notify;
@@ -1573,17 +1590,17 @@ static void ggp_callback_recv(gpointer _
purple_debug_info("gg",
"notify: (%d) status: %d; descr: %s\n",
- n->uin, n->status, descr ? descr : "(null)");
+ n->uin, GG_S(n->status), descr ? descr : "(null)");
ggp_generic_status_handler(gc,
- n->uin, n->status, descr);
+ n->uin, GG_S(n->status), descr);
}
}
break;
case GG_EVENT_NOTIFY60:
purple_debug_info("gg",
"notify60_pre: (%d) status=%d; version=%d; descr=%s\n",
- ev->event.notify60->uin, ev->event.notify60->status,
+ ev->event.notify60->uin, GG_S(ev->event.notify60->status),
ev->event.notify60->version,
ev->event.notify60->descr ? ev->event.notify60->descr : "(null)");
@@ -1602,7 +1619,7 @@ static void ggp_callback_recv(gpointer _
break;
case GG_EVENT_STATUS:
purple_debug_info("gg", "status: (%d) status=%d; descr=%s\n",
- ev->event.status.uin, ev->event.status.status,
+ ev->event.status.uin, GG_S(ev->event.status.status),
ev->event.status.descr ? ev->event.status.descr : "(null)");
ggp_generic_status_handler(gc, ev->event.status.uin,
@@ -1611,12 +1628,12 @@ static void ggp_callback_recv(gpointer _
case GG_EVENT_STATUS60:
purple_debug_info("gg",
"status60: (%d) status=%d; version=%d; descr=%s\n",
- ev->event.status60.uin, ev->event.status60.status,
+ ev->event.status60.uin, GG_S(ev->event.status60.status),
ev->event.status60.version,
ev->event.status60.descr ? ev->event.status60.descr : "(null)");
ggp_generic_status_handler(gc, ev->event.status60.uin,
- ev->event.status60.status, ev->event.status60.descr);
+ GG_S(ev->event.status60.status), ev->event.status60.descr);
break;
case GG_EVENT_USERLIST:
if (ev->event.userlist.type == GG_USERLIST_GET_REPLY) {
@@ -1829,6 +1846,16 @@ static GList *ggp_status_types(PurpleAcc
NULL);
types = g_list_append(types, type);
+ /*
+ * New statuses for GG 8.0 like PoGGadaj ze mna (not yet because
+ * libpurple can't support Chatty status) and Nie przeszkadzac
+ */
+ type = purple_status_type_new_with_attrs(
+ PURPLE_STATUS_UNAVAILABLE, NULL, NULL, TRUE, TRUE, FALSE,
+ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING),
+ NULL);
+ types = g_list_append(types, type);
+
/*
* This status is necessary to display guys who are blocking *us*.
*/
@@ -1930,6 +1957,9 @@ static void ggp_login(PurpleAccount *acc
presence = purple_account_get_presence(account);
status = purple_presence_get_active_status(presence);
+ glp->encoding = GG_ENCODING_UTF8;
+ glp->protocol_features = (GG_FEATURE_STATUS80|GG_FEATURE_DND_FFC);
+
glp->async = 1;
glp->status = ggp_to_gg_status(status, &glp->status_descr);
glp->tls = 0;
@@ -2100,8 +2130,11 @@ static int ggp_send_im(PurpleConnection
plain = purple_unescape_html(msg);
}
+ /*
tmp = charset_convert(plain, "UTF-8", "CP1250");
-
+ */
+ tmp = g_strdup_printf("%s", plain);
+
if (tmp && (format_length - sizeof(struct gg_msg_richtext))) {
if(gg_send_message_richtext(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), (unsigned char *)tmp, format, format_length) < 0) {
ret = -1;
@@ -2160,6 +2193,9 @@ static int ggp_to_gg_status(PurpleStatus
} else if (strcmp(status_id, "away") == 0) {
new_status = GG_STATUS_BUSY;
new_status_descr = GG_STATUS_BUSY_DESCR;
+ } else if (strcmp(status_id, "unavailable") == 0) {
+ new_status = GG_STATUS_DND;
+ new_status_descr = GG_STATUS_DND_DESCR;
} else if (strcmp(status_id, "invisible") == 0) {
new_status = GG_STATUS_INVISIBLE;
new_status_descr = GG_STATUS_INVISIBLE_DESCR;
@@ -2177,9 +2213,12 @@ static int ggp_to_gg_status(PurpleStatus
new_msg = purple_status_get_attr_string(status, "message");
if(new_msg) {
+ /*
char *tmp = purple_markup_strip_html(new_msg);
*msg = charset_convert(tmp, "UTF-8", "CP1250");
g_free(tmp);
+ */
+ *msg = purple_markup_strip_html(new_msg);
return new_status_descr;
} else {
@@ -2279,7 +2318,8 @@ static int ggp_chat_send(PurpleConnectio
GGPInfo *info = gc->proto_data;
GGPChat *chat = NULL;
GList *l;
- char *msg, *plain;
+ /* char *msg, *plain; */
+ gchar *msg;
uin_t *uins;
int count = 0;
@@ -2310,9 +2350,12 @@ static int ggp_chat_send(PurpleConnectio
uins[count++] = uin;
}
+ /*
plain = purple_unescape_html(message);
msg = charset_convert(plain, "UTF-8", "CP1250");
g_free(plain);
+ */
+ msg = purple_unescape_html(message);
gg_send_message_confer(info->session, GG_CLASS_CHAT, count, uins,
(unsigned char *)msg);
g_free(msg);
============================================================
--- libpurple/protocols/gg/lib/common.c a333f8fc06cb82eb7ddf704db071f4b13af7ad70
+++ libpurple/protocols/gg/lib/common.c 665a2a017a163a481f8c5527e08fde52ca82fb45
@@ -47,27 +47,34 @@
*
* \brief Funkcje wykorzystywane przez r??ne modu?y biblioteki
*/
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#ifdef sun
-# include <sys/filio.h>
+
+#include "libgadu.h"
+#include "libgadu-internal.h"
+
+#ifndef _WIN32
+# include <sys/types.h>
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# ifdef sun
+# include <sys/filio.h>
+# endif
#endif
#include <errno.h>
#include <fcntl.h>
-#include <netdb.h>
+
+#ifndef _WIN32
+# include <netdb.h>
+#endif
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "libgadu.h"
-#include "libgadu-internal.h"
-
/**
* Plik, do kt?rego b?d? przekazywane informacje odpluskwiania.
*
============================================================
--- libpurple/protocols/gg/lib/dcc.c c7ac957798f90e5ac8b8ccd1a43ecb9656d8cff1
+++ libpurple/protocols/gg/lib/dcc.c f99696afc880d8895d8fc08e525e7f6f978f7559
@@ -25,15 +25,19 @@
*
* \brief Obs?uga po??cze? bezpo?rednich do wersji Gadu-Gadu 6.x
*/
+#include "libgadu.h"
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#ifdef sun
-# include <sys/filio.h>
+
+#ifndef _WIN32
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# ifdef sun
+# include <sys/filio.h>
+# endif
#endif
#include <ctype.h>
@@ -46,7 +50,6 @@
#include <unistd.h>
#include "compat.h"
-#include "libgadu.h"
#ifndef GG_DEBUG_DISABLE
============================================================
--- libpurple/protocols/gg/lib/dcc7.c 7e301bb7bd0d1c4a4ee8a627590a1d8b4b50aaad
+++ libpurple/protocols/gg/lib/dcc7.c ce8661d817dd5e93633c54b7defee710c5eb5fe6
@@ -28,15 +28,21 @@
* \brief Obs?uga po??cze? bezpo?rednich od wersji Gadu-Gadu 7.x
*/
+#include "libgadu.h"
+
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#ifdef sun
-# include <sys/filio.h>
+
+#ifndef _WIN32
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# ifdef sun
+# include <sys/filio.h>
+# endif
#endif
+
#include <time.h>
#include <ctype.h>
@@ -49,7 +55,6 @@
#include <unistd.h>
#include "compat.h"
-#include "libgadu.h"
#define gg_debug_dcc(dcc, fmt...) \
gg_debug_session((dcc) ? (dcc)->sess : NULL, fmt)
@@ -942,7 +947,7 @@ struct gg_event *gg_dcc7_watch_fd(struct
{
struct sockaddr_in sin;
int fd, one = 1;
- unsigned int sin_len = sizeof(sin);
+ socklen_t sin_len = sizeof(sin);
gg_debug_dcc(dcc, GG_DEBUG_MISC, "// gg_dcc7_watch_fd() GG_STATE_LISTENING\n");
============================================================
--- libpurple/protocols/gg/lib/events.c fdb0fc390bc39635a6393ac441b5971c397f94d4
+++ libpurple/protocols/gg/lib/events.c cb6479253caf6df38fdbd7b648a11849a2fb9ec0
@@ -27,16 +27,20 @@
* \brief Obs?uga zdarze?
*/
+#include "libgadu.h"
+#include "libgadu-internal.h"
+
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef _WIN32
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
+
#include "compat.h"
-#include "libgadu.h"
#include "protocol.h"
-#include "libgadu-internal.h"
#include <errno.h>
#include <stdio.h>
@@ -1139,13 +1143,12 @@ static int gg_watch_fd_connected(struct
case GG_NOTIFY_REPLY80:
{
struct gg_notify_reply80 *n = (void*) p;
- unsigned int length = h->length, i = 0;
+ int length = h->length, i = 0;
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd_connected() received a notify reply\n");
e->type = GG_EVENT_NOTIFY60;
e->event.notify60 = malloc(sizeof(*e->event.notify60));
-
if (!e->event.notify60) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd_connected() not enough memory for notify data\n");
goto fail;
@@ -1156,7 +1159,7 @@ static int gg_watch_fd_connected(struct
while (length >= sizeof(struct gg_notify_reply80)) {
uint32_t descr_len;
char *tmp;
-
+
e->event.notify60[i].uin = gg_fix32(n->uin);
e->event.notify60[i].status = gg_fix32(n->status);
e->event.notify60[i].remote_ip = n->remote_ip;
@@ -1166,6 +1169,7 @@ static int gg_watch_fd_connected(struct
e->event.notify60[i].version = 0x00; /* not-supported */
e->event.notify60[i].time = 0; /* not-supported */
+
descr_len = gg_fix32(n->descr_len);
length -= sizeof(struct gg_notify_reply80);
@@ -1534,7 +1538,7 @@ struct gg_event *gg_watch_fd(struct gg_s
{
char buf[1024], *client, *auth;
int res = 0;
- unsigned int res_size = sizeof(res);
+ socklen_t res_size = sizeof(res);
const char *host;
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() GG_STATE_CONNECTING_HUB\n");
@@ -1752,7 +1756,7 @@ struct gg_event *gg_watch_fd(struct gg_s
case GG_STATE_CONNECTING_GG:
{
int res = 0;
- unsigned int res_size = sizeof(res);
+ socklen_t res_size = sizeof(res);
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() GG_STATE_CONNECTING_GG\n");
@@ -2054,7 +2058,7 @@ struct gg_event *gg_watch_fd(struct gg_s
if (gg_dcc_ip == (unsigned long) inet_addr("255.255.255.255")) {
struct sockaddr_in sin;
- unsigned int sin_len = sizeof(sin);
+ socklen_t sin_len = sizeof(sin);
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() detecting address\n");
============================================================
--- libpurple/protocols/gg/lib/http.c 7846a9ed5275969a45c31e2ccdabae2ea9e29569
+++ libpurple/protocols/gg/lib/http.c 882d007b9c52dbbfa77b6a55fce3568428927425
@@ -24,18 +24,26 @@
* \brief Obs?uga po??cze? HTTP
*/
+#include "libgadu.h"
+
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef _WIN32
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
+
#include "compat.h"
-#include "libgadu.h"
#include "resolver.h"
#include <ctype.h>
#include <errno.h>
-#include <netdb.h>
+
+#ifndef _WIN32
+# include <netdb.h>
+#endif
+
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -230,7 +238,7 @@ int gg_http_watch_fd(struct gg_http *h)
if (h->state == GG_STATE_CONNECTING) {
int res = 0;
- unsigned int res_size = sizeof(res);
+ socklen_t res_size = sizeof(res);
if (h->async && (getsockopt(h->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) {
gg_debug(GG_DEBUG_MISC, "=> http, async connection failed (errno=%d, %s)\n", (res) ? res : errno , strerror((res) ? res : errno));
@@ -249,7 +257,7 @@ int gg_http_watch_fd(struct gg_http *h)
}
if (h->state == GG_STATE_SENDING_QUERY) {
- int res;
+ ssize_t res;
if ((res = write(h->fd, h->query, strlen(h->query))) < 1) {
gg_debug(GG_DEBUG_MISC, "=> http, write() failed (len=%d, res=%d, errno=%d)\n", strlen(h->query), res, errno);
============================================================
--- libpurple/protocols/gg/lib/libgadu.c bd29701f580355495b583cdaff5d7d9837e0bb51
+++ libpurple/protocols/gg/lib/libgadu.c b4de84d7b5028adcbc13e81d0dacbc27814b8f72
@@ -28,22 +28,35 @@
* \brief G??wny modu? biblioteki
*/
+#include "libgadu.h"
+#include "libgadu-config.h"
+#include "libgadu-internal.h"
+
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#ifdef sun
-# include <sys/filio.h>
+
+#ifdef _WIN32
+# include <io.h>
+# include <fcntl.h>
+# include <errno.h>
+# define SHUT_RDWR SD_BOTH
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# ifdef sun
+# include <sys/filio.h>
+# endif
#endif
#include "compat.h"
-#include "libgadu.h"
#include "protocol.h"
#include "resolver.h"
-#include "libgadu-internal.h"
-#include <errno.h>
-#include <netdb.h>
+#ifndef _WIN32
+# include <errno.h> /* on Win32 this is included above */
+# include <netdb.h>
+#endif
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -399,8 +412,7 @@ void *gg_recv_packet(struct gg_session *
{
struct gg_header h;
char *buf = NULL;
- int ret = 0;
- unsigned int offset, size = 0;
+ int ret = 0, offset, size = 0;
gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess);
@@ -597,7 +609,7 @@ int gg_send_packet(struct gg_session *se
h->length = gg_fix32(tmp_length - sizeof(struct gg_header));
if ((gg_debug_level & GG_DEBUG_DUMP)) {
- unsigned int i;
+ int i;
gg_debug_session(sess, GG_DEBUG_DUMP, "// gg_send_packet(0x%.2x)", gg_fix32(h->type));
for (i = 0; i < tmp_length; ++i)
============================================================
--- libpurple/protocols/gg/lib/libgadu.h 46fc0a49b72bc5496a96bc77c409d8db0e4fda88
+++ libpurple/protocols/gg/lib/libgadu.h b3013ad5d0e774ec2279f972b2d95ddb4be5a059
@@ -179,6 +179,7 @@ typedef enum {
GG_RESOLVER_DEFAULT = 0, /**< Domy?lny spos?b rozwi?zywania nazw (jeden z poni?szych) */
GG_RESOLVER_FORK, /**< Rozwi?zywanie nazw bazuj?ce na procesach */
GG_RESOLVER_PTHREAD, /**< Rozwi?zywanie nazw bazuj?ce na w?tkach */
+ GG_RESOLVER_WIN32,
GG_RESOLVER_CUSTOM, /**< Funkcje rozwi?zywania nazw dostarczone przed aplikacj? */
GG_RESOLVER_INVALID = -1 /**< Nieprawid?owy spos?b rozwi?zywania nazw (wynik \c gg_session_get_resolver) */
} gg_resolver_t;
============================================================
--- libpurple/protocols/gg/lib/pubdir.c 28a76bb68aa2380804d02e89c6c83485eb23d487
+++ libpurple/protocols/gg/lib/pubdir.c acbb640332cb13edd6a5ace8ce907236657e089c
@@ -26,6 +26,9 @@
* \brief Obs?uga katalogu publicznego
*/
+#include "libgadu.h"
+#include "libgadu-config.h"
+
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
@@ -34,8 +37,6 @@
#include <string.h>
#include <unistd.h>
-#include "libgadu.h"
-
/**
* Rejestruje nowego u?ytkownika.
*
============================================================
--- libpurple/protocols/gg/lib/resolver.c 48326d4fd8687a81f7ab4ca06866c7d4d644b14a
+++ libpurple/protocols/gg/lib/resolver.c 0f9fc890ab9c40208b1a79fd8097cda62e463dbf
@@ -28,15 +28,18 @@
* \brief Funkcje rozwi?zywania nazw
*/
-#include <sys/wait.h>
-#include <netdb.h>
+#ifndef _WIN32
+# include <sys/wait.h>
+# include <netdb.h>
+# include <signal.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include "libgadu.h"
#include "resolver.h"
@@ -212,7 +215,281 @@ struct gg_resolver_fork_data {
int pid; /*< Identyfikator procesu */
};
+
+
+#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 int
+socket_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
+
+
+
+#ifdef _WIN32
+struct gg_resolve_win32thread_data {
+ char *hostname;
+ int fd;
+};
+
+static DWORD WINAPI gg_resolve_win32thread_thread(LPVOID arg)
+{
+ struct gg_resolve_win32thread_data *d = arg;
+ struct in_addr a;
+
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_thread() host: %s, fd: %i called\n", d->hostname, d->fd);
+
+ if ((a.s_addr = inet_addr(d->hostname)) == INADDR_NONE) {
+ /* W przypadku b??du gg_gethostbyname_real() zwr?ci -1
+ * i nie zmieni &addr. Tam jest ju? INADDR_NONE,
+ * wi?c nie musimy robi? nic wi?cej. */
+ gg_gethostbyname_real(d->hostname, &a, 0);
+ }
+
+ // if ((a.s_addr = inet_addr(d->hostname)) == INADDR_NONE) {
+ // struct in_addr *hn;
+
+ // if (!(hn = gg_gethostbyname(d->hostname)))
+ // a.s_addr = INADDR_NONE;
+ // else {
+ // a.s_addr = hn->s_addr;
+ // free(hn);
+ // }
+ // }
+
+ write(d->fd, &a, sizeof(a));
+ close(d->fd);
+
+ free(d->hostname);
+ d->hostname = NULL;
+
+ free(d);
+
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_thread() done\n");
+
+ return 0;
+}
+
+
+static int gg_resolve_win32thread(int *fd, void **resolver, const char *hostname)
+{
+ struct gg_resolve_win32thread_data *d = NULL;
+ HANDLE h;
+ DWORD dwTId;
+ int pipes[2], new_errno;
+
+ gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve_win32thread(%p, %p, \"%s\");\n", fd, resolver, hostname);
+
+ if (!resolver || !fd || !hostname) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() invalid arguments\n");
+ errno = EFAULT;
+ return -1;
+ }
+
+ if (socket_pipe(pipes) == -1) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create pipes (errno=%d, %s)\n", errno, strerror(errno));
+ return -1;
+ }
+
+ if (!(d = malloc(sizeof(*d)))) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n");
+ new_errno = errno;
+ goto cleanup;
+ }
+
+ d->hostname = NULL;
+
+ if (!(d->hostname = strdup(hostname))) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n");
+ new_errno = errno;
+ goto cleanup;
+ }
+
+ d->fd = pipes[1];
+
+ h = CreateThread(NULL, 0, gg_resolve_win32thread_thread,
+ d, 0, &dwTId);
+
+ if (h == NULL) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create thread\n");
+ new_errno = errno;
+ goto cleanup;
+ }
+
+ *resolver = h;
+ *fd = pipes[0];
+
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() done\n");
+
+ return 0;
+
+cleanup:
+ if (d) {
+ free(d->hostname);
+ free(d);
+ }
+
+ close(pipes[0]);
+ close(pipes[1]);
+
+ errno = new_errno;
+
+ return -1;
+
+}
+
+static void gg_resolve_win32thread_cleanup(void **priv_data, int force)
+{
+ struct gg_resolve_win32thread_data *data;
+
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_cleanup() force: %i called\n", force);
+
+ if (priv_data == NULL || *priv_data == NULL)
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_cleanup() priv_data: NULL\n");
+ return;
+
+ data = (struct gg_resolve_win32thread_data*) *priv_data;
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_cleanup() data: %s called\n", data->hostname);
+ *priv_data = NULL;
+
+ if (force) {
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_cleanup() force called\n", force);
+ //pthread_cancel(data->thread);
+ //pthread_join(data->thread, NULL);
+ }
+
+ free(data->hostname);
+ data->hostname = NULL;
+
+ if (data->fd != -1) {
+ close(data->fd);
+ data->fd = -1;
+ }
+ gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread_cleanup() done\n");
+ free(data);
+}
+#endif
+
+#ifndef _WIN32
+/**
* \internal Rozwi?zuje nazw? serwera w osobnym procesie.
*
* Po??czenia asynchroniczne nie mog? blokowa? procesu w trakcie rozwi?zywania
@@ -325,6 +602,7 @@ void gg_resolver_fork_cleanup(void **pri
free(data);
}
+#endif
#ifdef GG_CONFIG_HAVE_PTHREAD
@@ -505,19 +783,31 @@ int gg_session_set_resolver(struct gg_se
return 0;
}
-#if !defined(GG_CONFIG_HAVE_PTHREAD) || !defined(GG_CONFIG_PTHREAD_DEFAULT)
+#ifdef _WIN32
+ type = GG_RESOLVER_WIN32;
+#else
type = GG_RESOLVER_FORK;
-#else
+#endif
+
+#if defined(GG_CONFIG_HAVE_PTHREAD) || defined(GG_CONFIG_PTHREAD_DEFAULT)
type = GG_RESOLVER_PTHREAD;
#endif
}
switch (type) {
- case GG_RESOLVER_FORK:
+#ifdef _WIN32
+ case GG_RESOLVER_WIN32:
gs->resolver_type = type;
+ gs->resolver_start = gg_resolve_win32thread;
+ gs->resolver_cleanup = gg_resolve_win32thread_cleanup;
+ return 0;
+#else
+ case GG_RESOLVER_FORK:
+ gs->resolver_type = type;
gs->resolver_start = gg_resolver_fork_start;
gs->resolver_cleanup = gg_resolver_fork_cleanup;
return 0;
+#endif
#ifdef GG_CONFIG_HAVE_PTHREAD
case GG_RESOLVER_PTHREAD:
@@ -596,19 +886,31 @@ int gg_http_set_resolver(struct gg_http
return 0;
}
-#if !defined(GG_CONFIG_HAVE_PTHREAD) || !defined(GG_CONFIG_PTHREAD_DEFAULT)
+#ifdef _WIN32
+ type = GG_RESOLVER_WIN32;
+#else
type = GG_RESOLVER_FORK;
-#else
+#endif
+
+#if defined(GG_CONFIG_HAVE_PTHREAD) || defined(GG_CONFIG_PTHREAD_DEFAULT)
type = GG_RESOLVER_PTHREAD;
#endif
}
switch (type) {
- case GG_RESOLVER_FORK:
+#ifdef _WIN32
+ case GG_RESOLVER_WIN32:
gh->resolver_type = type;
+ gh->resolver_start = gg_resolve_win32thread;
+ gh->resolver_cleanup = gg_resolve_win32thread_cleanup;
+ return 0;
+#else
+ case GG_RESOLVER_FORK:
+ gh->resolver_type = type;
gh->resolver_start = gg_resolver_fork_start;
gh->resolver_cleanup = gg_resolver_fork_cleanup;
return 0;
+#endif
#ifdef GG_CONFIG_HAVE_PTHREAD
case GG_RESOLVER_PTHREAD:
@@ -680,12 +982,22 @@ int gg_global_set_resolver(gg_resolver_t
gg_global_resolver_cleanup = NULL;
return 0;
+#ifndef _WIN32
case GG_RESOLVER_FORK:
gg_global_resolver_type = type;
gg_global_resolver_start = gg_resolver_fork_start;
gg_global_resolver_cleanup = gg_resolver_fork_cleanup;
return 0;
-
+#endif
+
+#ifdef _WIN32
+ case GG_RESOLVER_WIN32:
+ gg_global_resolver_type = type;
+ gg_global_resolver_start = gg_resolve_win32thread;
+ gg_global_resolver_cleanup = gg_resolve_win32thread_cleanup;
+ return 0;
+#endif
+
#ifdef GG_CONFIG_HAVE_PTHREAD
case GG_RESOLVER_PTHREAD:
gg_global_resolver_type = type;
============================================================
--- libpurple/protocols/gg/lib/resolver.h a02b61e069991489c5f0b2804ef8bf3708e198a4
+++ libpurple/protocols/gg/lib/resolver.h 57a6c4768ba359942b87bbd010aee3ab9f1a8c1f
@@ -21,7 +21,9 @@
#ifndef LIBGADU_RESOLVER_H
#define LIBGADU_RESOLVER_H
-#include <arpa/inet.h>
+#ifndef _WIN32
+# include <arpa/inet.h>
+#endif
int gg_gethostbyname_real(const char *hostname, struct in_addr *result, int pthread);
More information about the Commits
mailing list