diff --git a/lib/gibber/asyncns.c b/lib/gibber/asyncns.c index 4088ce7..ad0f705 100755 --- a/lib/gibber/asyncns.c +++ b/lib/gibber/asyncns.c @@ -27,19 +27,29 @@ #include #include #include + +#ifndef WIN32 #include #include +#endif #include #include #include #include + +#ifndef WIN32 #include +#endif + #include + +#ifndef WIN32 #include #include #include #include #include +#endif #if HAVE_ARPA_NAMESER_COMPAT_H #include diff --git a/lib/gibber/asyncns.h b/lib/gibber/asyncns.h index 9f2cbd6..726b7d8 100755 --- a/lib/gibber/asyncns.h +++ b/lib/gibber/asyncns.h @@ -21,9 +21,11 @@ . ***/ +#ifndef WIN32 #include #include #include +#endif /** \mainpage * diff --git a/lib/gibber/gibber-fd-transport.c b/lib/gibber/gibber-fd-transport.c index 4837c11..c5d81fb 100755 --- a/lib/gibber/gibber-fd-transport.c +++ b/lib/gibber/gibber-fd-transport.c @@ -20,7 +20,24 @@ #include #include + +#ifdef WIN32 +#include +#endif +#ifndef WIN32 #include +#else +#include +#include +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +# ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +# endif +# ifndef STDERR_FILENO +# define STDERR_FILENO 2 +# endif +#endif #include #include #include @@ -418,12 +435,19 @@ gibber_fd_transport_read (GibberFdTransport *transport, void gibber_fd_transport_set_fd (GibberFdTransport *self, int fd) { +#ifdef WIN32 + unsigned long mode = 1; +#endif GibberFdTransportPrivate *priv = GIBBER_FD_TRANSPORT_GET_PRIVATE (self); g_assert (self->fd == -1 && fd >= 0); self->fd = fd; +#ifndef WIN32 fcntl (fd, F_SETFL, O_NONBLOCK); +#else + ioctlsocket(fd, FIONBIO, &mode); +#endif priv->channel = g_io_channel_unix_new (fd); g_io_channel_set_close_on_unref (priv->channel, TRUE); g_io_channel_set_encoding (priv->channel, NULL, NULL); diff --git a/lib/gibber/gibber-fd-transport.h b/lib/gibber/gibber-fd-transport.h index 28727aa..8141db2 100755 --- a/lib/gibber/gibber-fd-transport.h +++ b/lib/gibber/gibber-fd-transport.h @@ -23,9 +23,17 @@ #include -#include -#include +#ifndef G_OS_WIN32 +include +include +#else +#include +#include +#endif + +#ifndef G_OS_WIN32 #include +#endif #include "gibber-transport.h" diff --git a/lib/gibber/gibber-linklocal-transport.c b/lib/gibber/gibber-linklocal-transport.c index cc02169..ec1ac5a 100755 --- a/lib/gibber/gibber-linklocal-transport.c +++ b/lib/gibber/gibber-linklocal-transport.c @@ -20,7 +20,22 @@ #include #include + +#ifndef WIN32 #include +#else +#include +#include +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif +#endif + #include #include #include diff --git a/lib/gibber/gibber-listener.c b/lib/gibber/gibber-listener.c index 6b15446..7338aa8 100755 --- a/lib/gibber/gibber-listener.c +++ b/lib/gibber/gibber-listener.c @@ -20,12 +20,24 @@ #include #include #include + +#ifndef WIN32 #include #include #include +#else +#include +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EADDRINUSE WSAEADDRINUSE +#define snprintf sprintf_s +#endif + +#ifndef WIN32 #include #include #include +#endif + #include #include @@ -33,7 +45,10 @@ #include "gibber-listener.h" #include "gibber-fd-transport.h" + +#ifndef WIN32 #include "gibber-unix-transport.h" +#endif #include "gibber-util.h" #define DEBUG_FLAG DEBUG_NET @@ -44,6 +59,13 @@ G_DEFINE_TYPE (GibberListener, gibber_listener, \ G_TYPE_OBJECT); +#ifdef WIN32 +struct sockaddr_un{ + short sun_family; /*AF_UNIX*/ + char sun_path[108]; /*path name */ +}; +#endif + /* signals */ enum { @@ -189,6 +211,7 @@ listener_io_in_cb (GIOChannel *source, if (addr.ss_family == AF_UNIX) { +#ifndef WIN32 // assuming there's no unix sockets in windows transport = GIBBER_FD_TRANSPORT (gibber_unix_transport_new_from_fd (nfd)); /* UNIX sockets doesn't have port */ @@ -197,6 +220,7 @@ listener_io_in_cb (GIOChannel *source, NI_NUMERICHOST); port[0] = '\0'; +#endif } else { diff --git a/lib/gibber/gibber-resolver.c b/lib/gibber/gibber-resolver.c index 627e308..aedcbf8 100755 --- a/lib/gibber/gibber-resolver.c +++ b/lib/gibber/gibber-resolver.c @@ -22,11 +22,50 @@ #include #include +#ifndef WIN32 #include #include #include -#include #include +#else +#include +#include +// stdint.h +typedef unsigned short int uint16_t; + +// arpa/nameser.h +#define QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define C_IN 1 /* the arpa internet */ +#define T_SRV 33 /* Server selection */ + + + +typedef struct { + unsigned id :16; /* query identification number */ + + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritative answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ + + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; +#endif + +#include #include @@ -657,6 +696,8 @@ gibber_resolver_nameinfo_result (GibberResolver *resolver, #define ANSWER_BUFSIZE 10240 + +#ifndef WIN32 GList * gibber_resolver_res_query_to_list (guchar *answer, int length) { @@ -712,6 +753,37 @@ failed: gibber_resolver_srv_list_free (list); return NULL; } +#else +GList * +gibber_resolver_res_query_to_list (PDNS_RECORD answer) +{ + GList *list = NULL; + char name[256]; + guint16 port; + guint16 priority; + guint16 weight; + PDNS_RECORD tmp; + + for (tmp = answer; tmp != NULL; tmp = tmp->pNext) + { + //struct osip_srv_entry *srventry; + DNS_SRV_DATA * data; + if (tmp->wType != DNS_TYPE_SRV) + continue; + + strcpy(name, tmp->pName); // don't know if this is safe or right, or should use the + // snprintf(name, 256, "%s", tmp->Data.SRV.pNameTarget); + // be used, feel free to fix it + port = tmp->Data.SRV.wPort; + priority = tmp->Data.SRV.wPriority; + weight = tmp->Data.SRV.wWeight; + + list = g_list_prepend (list, + gibber_resolver_srv_record_new (name, port, priority, weight)); + } + return list; +} +#endif GError * gibber_resolver_gai_error_to_g_error (int error) @@ -735,11 +807,14 @@ gibber_resolver_gai_error_to_g_error (int error) break; case EAI_MEMORY: +#ifndef WIN32 case EAI_OVERFLOW: +#endif code = GIBBER_RESOLVER_ERROR_MEMORY; break; - +#ifndef WIN32 case EAI_SYSTEM: +#endif default: code = GIBBER_RESOLVER_ERROR_UNKNOWN; } @@ -788,6 +863,11 @@ resolver_resolv_srv (GibberResolver *resolver, const char *service, GibberResolverServiceType type) { +#ifdef WIN32 + DNS_STATUS dns_status; + PDNS_RECORD dns_record; +#endif + gchar *srv_str; int ret; GList *entries = NULL; @@ -797,6 +877,7 @@ resolver_resolv_srv (GibberResolver *resolver, srv_str = g_strdup_printf ("_%s._%s.%s", service, type == GIBBER_RESOLVER_SERVICE_TYPE_TCP ? "tcp" : "udp", service_name); +#ifndef WIN32 ret = res_query (srv_str, C_IN, T_SRV, answer, ANSWER_BUFSIZE); if (ret < 0) @@ -808,14 +889,30 @@ resolver_resolv_srv (GibberResolver *resolver, error = g_error_new (GIBBER_RESOLVER_ERROR, GIBBER_RESOLVER_ERROR_RESOLVE_FAILURE, "Invalid reply received"); } +#else + dns_status = DnsQuery_A(srv_str, DNS_TYPE_SRV, DNS_QUERY_BYPASS_CACHE, NULL, &dns_record, NULL); + if (dns_status != NO_ERROR) { + error = gibber_resolver_h_error_to_g_error (dns_record); + } else { + // convert dns_record list to GList entries + entries = gibber_resolver_res_query_to_list (dns_record); + if (entries == NULL) + error = g_error_new (GIBBER_RESOLVER_ERROR, + GIBBER_RESOLVER_ERROR_RESOLVE_FAILURE, + "Invalid reply received"); + } +#endif gibber_resolver_srv_result (resolver, id, entries, error); if (error != NULL) g_error_free (error); - g_free (srv_str); +#ifdef WIN32 + if( dns_record ) {DnsRecordListFree( dns_record, DnsFreeRecordList );} +#endif + return FALSE; } diff --git a/lib/gibber/gibber-resolver.h b/lib/gibber/gibber-resolver.h index 4046756..233ebaf 100755 --- a/lib/gibber/gibber-resolver.h +++ b/lib/gibber/gibber-resolver.h @@ -23,8 +23,12 @@ #include +#ifndef WIN32 #include #include +#else +#include +#endif G_BEGIN_DECLS diff --git a/lib/gibber/gibber-tcp-transport.c b/lib/gibber/gibber-tcp-transport.c index 32f2379..d837093 100755 --- a/lib/gibber/gibber-tcp-transport.c +++ b/lib/gibber/gibber-tcp-transport.c @@ -25,7 +25,14 @@ #include #include #include + +#ifndef WIN32 #include +#else +// would be located errno.h in linux +#define EALREADY 120 /* Socket already connected */ +#define EINPROGRESS 119 /* Connection already in progress */ +#endif #include "gibber-tcp-transport.h" @@ -201,6 +208,10 @@ _channel_io (GIOChannel *source, static void new_connect_attempt (GibberTCPTransport *self) { +#ifdef WIN32 + unsigned long mode = 1; +#endif + GibberTCPTransportPrivate *priv = GIBBER_TCP_TRANSPORT_GET_PRIVATE ( self); int fd; @@ -227,8 +238,12 @@ new_connect_attempt (GibberTCPTransport *self) DEBUG("socket failed: %s", strerror (errno)); goto failed; } +#ifndef WIN32 + fcntl (fd, F_SETFL, O_NONBLOCK); +#else + ioctlsocket(fd, FIONBIO, &mode); +#endif - fcntl (fd, F_SETFL, O_NONBLOCK); priv->channel = g_io_channel_unix_new (fd); g_io_channel_set_close_on_unref (priv->channel, FALSE); g_io_channel_set_encoding (priv->channel, NULL, NULL); diff --git a/lib/gibber/gibber-transport.c b/lib/gibber/gibber-transport.c index 82ad73b..b592452 100755 --- a/lib/gibber/gibber-transport.c +++ b/lib/gibber/gibber-transport.c @@ -37,7 +37,7 @@ enum CONNECTING, DISCONNECTED, DISCONNECTING, - ERROR, + ERROR_, BUFFER_EMPTY, LAST_SIGNAL }; @@ -119,7 +119,7 @@ gibber_transport_class_init (GibberTransportClass *gibber_transport_class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals[ERROR] = + signals[ERROR_] = g_signal_new ("error", G_OBJECT_CLASS_TYPE (gibber_transport_class), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, @@ -213,7 +213,7 @@ void gibber_transport_emit_error (GibberTransport *transport, GError *error) { DEBUG ("Transport error: %s", error->message); - g_signal_emit (transport, signals[ERROR], 0, + g_signal_emit (transport, signals[ERROR_], 0, error->domain, error->code, error->message); } diff --git a/lib/gibber/gibber-transport.h b/lib/gibber/gibber-transport.h index cf9b435..f6191a7 100755 --- a/lib/gibber/gibber-transport.h +++ b/lib/gibber/gibber-transport.h @@ -23,7 +23,12 @@ #include +#ifndef WIN32 #include +#else +#include +#include +#endif G_BEGIN_DECLS diff --git a/lib/gibber/gibber-unix-transport.c b/lib/gibber/gibber-unix-transport.c index 244f468..92f2370 100755 --- a/lib/gibber/gibber-unix-transport.c +++ b/lib/gibber/gibber-unix-transport.c @@ -24,13 +24,31 @@ #include #include +#ifdef HAVE_UNISTD_H #include +#else +#include +#include +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +# ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +# endif +# ifndef STDERR_FILENO +# define STDERR_FILENO 2 +# endif +#endif + #include #include #include #include +#ifdef HAVE_UNISTD_H #include #include +#else +#include +#endif #include "gibber-unix-transport.h" #include "gibber-util.h" @@ -138,7 +156,11 @@ gibber_unix_transport_connect (GibberUnixTransport *transport, GError **error) { union { +#ifdef WIN32 + struct sockaddr_in un; +#else struct sockaddr_un un; +#endif struct sockaddr addr; } addr; int fd; diff --git a/lib/gibber/gibber-unix-transport.h b/lib/gibber/gibber-unix-transport.h index b89a0dd..73095f5 100755 --- a/lib/gibber/gibber-unix-transport.h +++ b/lib/gibber/gibber-unix-transport.h @@ -28,11 +28,64 @@ #include #include #include + +#ifndef WIN32 #include #include #include #include +#else +#include +#include +#define IFNAMSIZ 16 +#define SIZE_INTERFACES 100 + +struct ifmap + { + unsigned long int mem_start; + unsigned long int mem_end; + unsigned short int base_addr; + unsigned char irq; + unsigned char dma; + unsigned char port; + /* 3 bytes spare */ + }; + +struct ifreq + { + char ifr_name[IFNAMSIZ]; /* Interface name */ + union { + struct sockaddr ifr_addr; + struct sockaddr ifr_dstaddr; + struct sockaddr ifr_broadaddr; + struct sockaddr ifr_netmask; + struct sockaddr ifr_hwaddr; + short ifr_flags; + int ifr_ifindex; + int ifr_metric; + int ifr_mtu; + struct ifmap ifr_map; + char ifr_slave[IFNAMSIZ]; + char ifr_newname[IFNAMSIZ]; + char * ifr_data; + }; + }; + +struct ifconf + { + int ifc_len; /* size of buffer */ + union { + char * ifc_buf; /* buffer address */ + struct ifreq * ifc_req; /* array of structures */ + }; + }; +#define SIOCGIFCONF SIO_GET_INTERFACE_LIST +#define SIOCGIFFLAGS SIO_GET_INTERFACE_LIST +#endif + +#ifndef WIN32 #include +#endif #include "gibber-fd-transport.h" @@ -90,9 +143,15 @@ gboolean gibber_unix_transport_send_credentials (GibberUnixTransport *transport, const guint8 *data, gsize size); typedef struct { +#ifndef WIN32 pid_t pid; uid_t uid; gid_t gid; +#else + signed int pid; + unsigned int uid; + unsigned short gid; +#endif } GibberCredentials; typedef void (*GibberUnixTransportRecvCredentialsCb) ( diff --git a/lib/gibber/gibber-util.c b/lib/gibber/gibber-util.c index 679406a..942ad17 100755 --- a/lib/gibber/gibber-util.c +++ b/lib/gibber/gibber-util.c @@ -19,7 +19,21 @@ #include +#ifndef WIN32 #include +#else +#include +#include +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif +#endif + #include #include diff --git a/lib/gibber/gibber-util.h b/lib/gibber/gibber-util.h index c6a4e75..92d5865 100755 --- a/lib/gibber/gibber-util.h +++ b/lib/gibber/gibber-util.h @@ -20,9 +20,13 @@ #ifndef __GIBBER_UTIL_H__ #define __GIBBER_UTIL_H__ +#ifndef WIN32 #include #include #include +#else +#include +#endif #include diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c index f4c452b..ff1ff06 100755 --- a/src/bytestream-socks5.c +++ b/src/bytestream-socks5.c @@ -21,23 +21,82 @@ #include "config.h" #include "bytestream-socks5.h" +#ifndef WIN32 #include #include #include #include #include #include +#endif #include +#ifndef WIN32 #include #include #include #include - +#else +#include +#include + #define IFNAMSIZ 16 +#define SIZE_INTERFACES 100 + + +struct ifmap + { + unsigned long int mem_start; + unsigned long int mem_end; + unsigned short int base_addr; + unsigned char irq; + unsigned char dma; + unsigned char port; + /* 3 bytes spare */ + }; + +struct ifreq + { + char ifr_name[IFNAMSIZ]; /* Interface name */ + union { + struct sockaddr ifr_addr; + struct sockaddr ifr_dstaddr; + struct sockaddr ifr_broadaddr; + struct sockaddr ifr_netmask; + struct sockaddr ifr_hwaddr; + short ifr_flags; + int ifr_ifindex; + int ifr_metric; + int ifr_mtu; + struct ifmap ifr_map; + char ifr_slave[IFNAMSIZ]; + char ifr_newname[IFNAMSIZ]; + char * ifr_data; + }; + }; + +struct ifconf + { + int ifc_len; /* size of buffer */ + union { + char * ifc_buf; /* buffer address */ + struct ifreq * ifc_req; /* array of structures */ + }; + }; +#define SIOCGIFCONF SIO_GET_INTERFACE_LIST +#define SIOCGIFFLAGS SIO_GET_INTERFACE_LIST +#endif + #ifdef HAVE_GETIFADDRS +#ifndef WIN32 #include #endif +#endif #include + +#ifdef interface +#undef interface +#endif + #include #include @@ -1713,11 +1772,33 @@ get_local_interfaces_ips (void) { gint sockfd; gint size = 0; + +#ifdef WIN32 + int winsize = 0; + int i, len, n, timeout; + unsigned long br = 0; + INTERFACE_INFO ifo[SIZE_INTERFACES]; + INTERFACE_INFO intInfo; +#endif + struct ifreq *ifr; +#ifndef WIN32 struct ifconf ifc; +#endif struct sockaddr_in *sa; GSList *ips = NULL; +#ifndef WIN32 + struct ifconf ifc; +#else + WSADATA info; + /* start up winsock */ + if ((i = WSAStartup(MAKEWORD(1,1), &info)) < 0 ) { + DEBUG ("Error on WSAStartup()"); + return(i); + } +#endif + /* FIXME: add IPv6 addresses */ if ((sockfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { @@ -1725,9 +1806,12 @@ get_local_interfaces_ips (void) return NULL; } +#ifndef WIN32 ifc.ifc_len = 0; ifc.ifc_req = NULL; +#endif +#ifndef WIN32 /* Loop and get each interface the system has, one by one... */ do { @@ -1751,6 +1835,17 @@ get_local_interfaces_ips (void) } } while (size <= ifc.ifc_len); + #else + memset(&ifo[0], 0, sizeof(ifo)); + //DeviceIoControl + //WSAIoctl(s, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned, lpOverlapped, pCompletionRoutine) + if (( WSAIoctl (sockfd, SIO_GET_INTERFACE_LIST, NULL, 0, &ifo[0], sizeof(ifo), &br, NULL, NULL) ) != 0) { + DEBUG("SIO_GET_INTERFACE_LIST error"); + return(WSAGetLastError()); + } + #endif + +#ifndef WIN32 /* Loop throught the interface list and get the IP address of each IF */ for (ifr = ifc.ifc_req; (gchar *) ifr < (gchar *) ifc.ifc_req + ifc.ifc_len; @@ -1780,6 +1875,9 @@ get_local_interfaces_ips (void) free (ifc.ifc_req); return ips; +#else + return NULL; +#endif } #endif /* ! HAVE_GETIFADDRS */ diff --git a/src/debug.c b/src/debug.c index 1555eb6..903df8b 100755 --- a/src/debug.c +++ b/src/debug.c @@ -3,7 +3,9 @@ #include "debug.h" #include +#ifndef WIN32 #include +#endif #include #include #include diff --git a/src/ft-channel.c b/src/ft-channel.c index 2b4c4cd..d644eda 100755 --- a/src/ft-channel.c +++ b/src/ft-channel.c @@ -23,12 +23,18 @@ #include #include #include + +#ifndef WIN32 #include +#endif #include #include + +#ifndef WIN32 #include #include - +#else +#endif #define DEBUG_FLAG GABBLE_DEBUG_FT #include "debug.h" diff --git a/src/ft-manager.c b/src/ft-manager.c index c47f97c..eaf3bf0 100755 --- a/src/ft-manager.c +++ b/src/ft-manager.c @@ -1,4 +1,4 @@ -/* + /* * ft-manager.c - Source for GabbleFtManager * Copyright (C) 2009 Collabora Ltd. * @author: Guillaume Desmottes @@ -28,6 +28,11 @@ #include #include +#ifdef WIN32 +#include +#include +#endif + #include "caps-channel-manager.h" #include "connection.h" #include "ft-manager.h" @@ -82,6 +87,19 @@ struct _GabbleFtManagerPrivate gchar *tmp_dir; }; +#ifdef WIN32 +char* +mkdtemp(char *templt) { + // In windows we dont have the mkstemp or mkdtemp function + // _mktemp is almost similar for creating unique file name, + // but does not create the folder, and we dont know method for creating unique folder name + FILE *f; + _mktemp(templt); + mkdir(templt); + return templt; +} +#endif + static void gabble_ft_manager_init (GabbleFtManager *obj) { diff --git a/src/gabble.c b/src/gabble.c index dc86d0d..279510a 100755 --- a/src/gabble.c +++ b/src/gabble.c @@ -21,7 +21,16 @@ #include "config.h" #include "gabble.h" -#include +#ifndef WIN32 + #include +#else +# ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +# endif +# ifndef STDERR_FILENO +# define STDERR_FILENO 2 +# endif +#endif #include #include @@ -84,7 +93,11 @@ stamp_log (const gchar *log_domain, GTimeVal now; gchar now_str[32]; gchar *tmp; +#ifndef WIN32 struct tm tm; +#else + struct tm* tm; +#endif /* Only use the GLib default log handler on non-LM messages as they will completely overwhelm and are not entirely useful most of the time. Still @@ -92,8 +105,13 @@ stamp_log (const gchar *log_domain, if (tp_strdiff (log_domain, "LM")) { g_get_current_time (&now); +#ifndef WIN32 localtime_r (&(now.tv_sec), &tm); strftime (now_str, 32, "%Y-%m-%d %H:%M:%S", &tm); +#else + tm = localtime(&(now.tv_sec)); + strftime (now_str, 32, "%Y-%m-%d %H:%M:%S", tm); +#endif tmp = g_strdup_printf ("%s.%06ld: %s", now_str, now.tv_usec, message); g_log_default_handler (log_domain, log_level, tmp, NULL); g_free (tmp); diff --git a/src/jingle-content.c b/src/jingle-content.c index ce0b01e..93fcf73 100755 --- a/src/jingle-content.c +++ b/src/jingle-content.c @@ -395,9 +395,15 @@ produce_senders (JingleContentSenders senders) } +#ifndef WIN32 #define SET_BAD_REQ(txt...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_BAD_REQUEST, txt) #define SET_OUT_ORDER(txt) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_JINGLE_OUT_OF_ORDER, txt) #define SET_CONFLICT(txt...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_CONFLICT, txt) +#else +#define SET_BAD_REQ(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_BAD_REQUEST, __VA_ARGS__) +#define SET_OUT_ORDER(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_JINGLE_OUT_OF_ORDER, __VA_ARGS__) +#define SET_CONFLICT(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_CONFLICT, __VA_ARGS__) +#endif static void new_transport_candidates_cb (GabbleJingleTransportIface *trans, diff --git a/src/jingle-transport-google.c b/src/jingle-transport-google.c index a17deb2..6274d4a 100755 --- a/src/jingle-transport-google.c +++ b/src/jingle-transport-google.c @@ -221,9 +221,15 @@ gabble_jingle_transport_google_class_init (GabbleJingleTransportGoogleClass *cls } +#ifndef WIN32 #define SET_BAD_REQ(txt...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_BAD_REQUEST, txt) #define SET_OUT_ORDER(txt...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_JINGLE_OUT_OF_ORDER, txt) #define SET_CONFLICT(txt...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_CONFLICT, txt) +#else +#define SET_BAD_REQ(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_BAD_REQUEST, __VA_ARGS__) +#define SET_OUT_ORDER(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_JINGLE_OUT_OF_ORDER, __VA_ARGS__) +#define SET_CONFLICT(...) g_set_error (error, GABBLE_XMPP_ERROR, XMPP_ERROR_CONFLICT, __VA_ARGS__ +#endif static void parse_candidates (GabbleJingleTransportIface *obj, diff --git a/src/message-util.c b/src/message-util.c index 94ce48b..28eafe7 100755 --- a/src/message-util.c +++ b/src/message-util.c @@ -37,6 +37,90 @@ #include "namespaces.h" #include "util.h" +#ifdef WIN32 + +// convert String to tm struct in Windows, untested +static int +_string_to_tm (char *pszTime, + struct tm * tm1) +{ + char szTime[64] = ""; + char szTmpDate[32] = ""; + char szTmpTime[32] = ""; + char * p = NULL; + strncpy(szTime, pszTime, sizeof(szTime)); + + //split time and date (date) + if ((p = strtok(szTime,"T")) != NULL) + { + strcpy(szTmpDate,p); + } else { + return 0; + } + //split time and date (time) + if ((p = strtok(NULL,".")) != NULL) + { + strcpy(szTmpTime,p); + } else { + return 0; + } + //split date (year) + if ((p = strtok(szTmpDate,"-")) != NULL) + { + tm1->tm_year = atoi(p); + } else { + return 0; + } + + //split date (month) + if ((p = strtok(NULL,"-")) != NULL) + { + tm1->tm_mon = atoi(p); + } + else + { + return 0; + } + + //split date (day) + if ((p = strtok(NULL,"-")) != NULL) + { + tm1->tm_mday = atoi(p); + } + else + { + return 0; + } + + //split time (hour) + if ((p = strtok(szTmpTime,":")) != NULL) + { + tm1->tm_hour = atoi(p); + } + else + { + return 0; + } + //split time (minute) + if ((p = strtok(NULL,":")) != NULL) + { + tm1->tm_min = atoi(p); + } else { + return 0; + } + + //split time (second) + if ((p = strtok(NULL,"\0")) != NULL) + { + tm1->tm_sec = atoi(p); + } + else + { + return 0; + } + return 1; +} +#endif static void _add_chat_state (LmMessage *msg, @@ -100,6 +184,7 @@ gabble_message_util_send_message (GObject *obj, gchar *id = NULL; guint n_parts; +#ifndef WIN32 #define INVALID_ARGUMENT(msg, args...) \ G_STMT_START { \ DEBUG (msg , ## args); \ @@ -107,6 +192,14 @@ gabble_message_util_send_message (GObject *obj, msg , ## args); \ goto despair_island; \ } G_STMT_END +#else +#define INVALID_ARGUMENT(msg, ...) \ + G_STMT_START { \ + DEBUG (msg , __VA_ARGS__); \ + g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, msg, __VA_ARGS__); \ + goto despair_island; \ + } G_STMT_END +#endif part = tp_message_peek (message, 0); @@ -370,11 +463,15 @@ gabble_message_util_parse_incoming_message (LmMessage *message, if (node != NULL) { const gchar *stamp_str, *p; +#ifdef WIN32 + int ret; +#endif struct tm stamp_tm = { 0, }; stamp_str = lm_message_node_get_attribute (node, "stamp"); if (stamp_str != NULL) { +#ifndef WIN32 p = strptime (stamp_str, "%Y%m%dT%T", &stamp_tm); if (p == NULL || *p != '\0') { @@ -385,6 +482,18 @@ gabble_message_util_parse_incoming_message (LmMessage *message, { *stamp = timegm (&stamp_tm); } +#else + int ret = _string_to_tm(stamp_str, &stamp_tm); + if(ret==0) + { + DEBUG ("%s: malformed date string '%s' for jabber:x:delay", + G_STRFUNC, stamp_str); + } + else + { + *stamp = difftime(mktime(gmtime(time(&stamp_tm))), mktime( localtime( time(&stamp_tm)))); + } +#endif } } diff --git a/src/tube-stream.c b/src/tube-stream.c index b90b8f9..f9a5916 100755 --- a/src/tube-stream.c +++ b/src/tube-stream.c @@ -21,13 +21,22 @@ #include "tube-stream.h" #include +#ifndef WIN32 #include #include #include #include +#else +#include +#include +#include +#include +#endif #include #include +#ifndef G_OS_WIN32 #include +#endif #include #include @@ -100,6 +109,7 @@ static const gchar *gabble_tube_stream_interfaces[] = { /* Linux glibc bits/socket.h suggests that struct sockaddr_storage is * not guaranteed to be big enough for AF_UNIX addresses */ + #ifndef WIN32 typedef union { /* we'd call this unix, but gcc predefines that. Thanks, gcc */ @@ -107,6 +117,7 @@ typedef union struct sockaddr_in ipv4; struct sockaddr_in6 ipv6; } SockAddr; +#endif /* signals */ enum @@ -630,11 +641,24 @@ credentials_received_cb (GibberUnixTransport *transport, goto credentials_received_cb_out; } +#ifndef WIN32 if (credentials->uid != getuid ()) { DEBUG ("Wrong uid (%u). Rejecting", credentials->uid); goto credentials_received_cb_out; } +#else + { + unsigned int puid; + DWORD processID = GetCurrentProcessId(); + puid = processID; + if (credentials->uid != puid) + { + DEBUG ("Wrong uid (%u). Rejecting", credentials->uid); + goto credentials_received_cb_out; + } + } +#endif DEBUG ("Connection properly authentificated"); @@ -664,12 +688,19 @@ check_incoming_connection (GabbleTubeStream *self, } else if (priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS) { +#ifndef WIN32 if (!gibber_unix_transport_recv_credentials ( GIBBER_UNIX_TRANSPORT (transport), credentials_received_cb, self)) { DEBUG ("Can't receive credentials. Closing transport"); return FALSE; } +#else + { + DEBUG ("Not implemented Can't receive credentials. Closing transport"); + return FALSE; + } +#endif /* Temporarly unblock the transport to be able to receive credentials */ gibber_transport_block_receiving (transport, FALSE); @@ -789,12 +820,19 @@ set_credentials_access_control_param (GValue *access_control_param, /* The Credentials access control would have be rejected earlier if the * socket type wasn't UNIX. */ +#ifndef WIN32 if (!gibber_unix_transport_send_credentials ( GIBBER_UNIX_TRANSPORT (transport), &credentials, sizeof (guint8))) { DEBUG ("send_credentials failed"); return FALSE; } +#else + { + DEBUG ("send_credentials not implemented"); + return FALSE; + } +#endif g_value_init (access_control_param, G_TYPE_UCHAR); @@ -947,9 +985,11 @@ new_connection_to_socket (GabbleTubeStream *self, array = g_value_get_boxed (priv->address); DEBUG ("Will try to connect to socket: %s", (const gchar *) array->data); +#ifndef WIN32 transport = GIBBER_TRANSPORT (gibber_unix_transport_new ()); gibber_unix_transport_connect (GIBBER_UNIX_TRANSPORT (transport), array->data, NULL); +#endif } else if (priv->address_type == TP_SOCKET_ADDRESS_TYPE_IPV4 || priv->address_type == TP_SOCKET_ADDRESS_TYPE_IPV6) @@ -2027,6 +2067,17 @@ gabble_tube_stream_add_bytestream (GabbleTubeIface *tube, } } +#ifdef WIN32 +static gboolean +check_unix_params (TpSocketAddressType address_type, + const GValue *address, + TpSocketAccessControl access_control, + const GValue *access_control_param, + GError **error) +{ + return NULL; +} +#else static gboolean check_unix_params (TpSocketAddressType address_type, const GValue *address, @@ -2109,6 +2160,7 @@ check_unix_params (TpSocketAddressType address_type, "%u socket access control is not supported", access_control); return FALSE; } +#endif static gboolean check_ip_params (TpSocketAddressType address_type, diff --git a/src/tubes-channel.c b/src/tubes-channel.c index fcbf36b..121c2b2 100755 --- a/src/tubes-channel.c +++ b/src/tubes-channel.c @@ -25,7 +25,16 @@ #include #include #include +#ifndef WIN32 #include +#else +# ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +# endif +# ifndef STDERR_FILENO +# define STDERR_FILENO 2 +# endif +#endif #include #include @@ -1426,7 +1435,9 @@ tube_msg_close (GabbleTubesChannel *self, close_node = lm_message_node_get_child_with_namespace (msg->node, "close", NS_TUBES); +#ifndef WIN32 g_assert (close != NULL); +#endif tmp = lm_message_node_get_attribute (close_node, "tube"); if (tmp == NULL) diff --git a/tools/glib-ginterface-gen.py b/tools/glib-ginterface-gen.py index 9eb7af5..340157f 100755 --- a/tools/glib-ginterface-gen.py +++ b/tools/glib-ginterface-gen.py @@ -272,11 +272,17 @@ class Generator(object): % (self.prefix_, node_name_lc)) method_blob, offsets = self.get_method_glue(methods) - + + c = 0 for method, offset in zip(methods, offsets): - self.do_method_glue(method, offset) + self.do_method_glue(method, offset) + c += 1 + + if ( c == 0): + self.b('0};') + else : + self.b('};'); - self.b('};') self.b('') self.b('static const DBusGObjectInfo _%s%s_object_info = {'