pidgin/pidgin

Convert zephyr to gio

2020-12-11, Elliott Sales de Andrade
1c9bdf8d3e85
Parents 18050336a45f
Children ac06f8981825
Convert zephyr to gio

Remove `SO_BSDCOMPAT` which has been obsolete for 15+ years.
Remove unused `from` parameter in ZCheckAuthorization.
Make `zuid_addr` into its plain integral type, not `struct in_addr`.
Make `__HM_addr` into a `GSocketAddress`.
Use `GSocketAddress` for `Z_InputQ->from`.
Make `__My_addr` a `guint32` instead of `struct in_addr`.
Change `__Zephyr_port` into a `gint`.
Convert zephyr to `GSocket`.
Remove `hostaddr` argument to `ZhmStat`, as it's always `NULL`.
Use gio to determine self-address.
Use gio to print out bad packet information.
Cleanup remaining indents.

Testing Done:
compile only

Reviewed at https://reviews.imfreedom.org/r/261/
--- a/libpurple/protocols/zephyr/ZAsyncLocate.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZAsyncLocate.c Fri Dec 11 04:12:45 2020 -0600
@@ -21,9 +21,12 @@
ZNotice_t notice;
size_t userlen, versionlen;
- if (ZGetFD() < 0)
- if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE)
- return (retval);
+ if (ZGetSocket() == NULL) {
+ retval = ZOpenPort(NULL);
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
+ }
(void) memset((char *)&notice, 0, sizeof(notice));
notice.z_kind = kind;
--- a/libpurple/protocols/zephyr/ZCkAuth.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZCkAuth.c Fri Dec 11 04:12:45 2020 -0600
@@ -18,7 +18,7 @@
When not using Kerberos, return true if the notice claims to be authentic.
*/
Code_t
-ZCheckAuthentication(ZNotice_t *notice, struct sockaddr_in *from)
+ZCheckAuthentication(ZNotice_t *notice)
{
#ifdef ZEPHYR_USES_KERBEROS
int result;
--- a/libpurple/protocols/zephyr/ZCkIfNot.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZCkIfNot.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZCheckIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
+ZCheckIfNotice(ZNotice_t *notice, GSocketAddress **from,
register int (*predicate)(ZNotice_t *, void *), void *args)
{
ZNotice_t tmpnotice;
@@ -32,8 +32,9 @@
if (!(buffer = (char *) malloc((unsigned) qptr->packet_len)))
return (ENOMEM);
(void) memcpy(buffer, qptr->packet, qptr->packet_len);
- if (from)
- *from = qptr->from;
+ if (from) {
+ *from = g_object_ref(qptr->from);
+ }
if ((retval = ZParseNotice(buffer, qptr->packet_len,
notice)) != ZERR_NONE) {
free(buffer);
--- a/libpurple/protocols/zephyr/ZClosePort.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZClosePort.c Fri Dec 11 04:12:45 2020 -0600
@@ -13,11 +13,8 @@
Code_t
ZClosePort(void)
{
- if (__Zephyr_fd >= 0) {
- (void) close(__Zephyr_fd);
- }
+ g_clear_object(&__Zephyr_socket);
+ ZSetDestAddr(NULL);
- __Zephyr_fd = -1;
-
- return (ZERR_NONE);
+ return ZERR_NONE;
}
--- a/libpurple/protocols/zephyr/ZIfNotice.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZIfNotice.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
+ZIfNotice(ZNotice_t *notice, GSocketAddress **from,
int (*predicate)(ZNotice_t *, void *), void *args)
{
ZNotice_t tmpnotice;
@@ -33,8 +33,9 @@
if (!(buffer = (char *) malloc((unsigned) qptr->packet_len)))
return (ENOMEM);
(void) memcpy(buffer, qptr->packet, qptr->packet_len);
- if (from)
- *from = qptr->from;
+ if (from) {
+ *from = g_object_ref(qptr->from);
+ }
if ((retval = ZParseNotice(buffer, qptr->packet_len,
notice)) != ZERR_NONE) {
free(buffer);
--- a/libpurple/protocols/zephyr/ZInit.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZInit.c Fri Dec 11 04:12:45 2020 -0600
@@ -32,35 +32,26 @@
Code_t
ZInitialize(void)
{
- struct servent *hmserv;
- struct hostent *hostent;
- char addr[4], hostname[MAXHOSTNAMELEN];
- struct in_addr servaddr;
- struct sockaddr_in sin;
- int s;
- socklen_t sinsize = sizeof(sin);
- Code_t code;
- ZNotice_t notice;
+ struct servent *hmserv;
+ GResolver *resolver = NULL;
+ GList *hosts = NULL;
+ guint32 servaddr;
+ guint16 port;
+ Code_t code;
+ ZNotice_t notice;
#ifdef ZEPHYR_USES_KERBEROS
- char *krealm = NULL;
- int krbval;
- char d1[ANAME_SZ], d2[INST_SZ];
+ gchar *krealm = NULL;
+ gint krbval;
+ gchar d1[ANAME_SZ], d2[INST_SZ];
#endif
- (void) memset((char *)&__HM_addr, 0, sizeof(__HM_addr));
-
- __HM_addr.sin_family = AF_INET;
+ g_clear_object(&__HM_addr);
- /* Set up local loopback address for HostManager */
- addr[0] = 127;
- addr[1] = 0;
- addr[2] = 0;
- addr[3] = 1;
+ hmserv = (struct servent *)getservbyname(HM_SVCNAME, "udp");
+ port = hmserv ? hmserv->s_port : HM_SVC_FALLBACK;
- hmserv = (struct servent *)getservbyname(HM_SVCNAME, "udp");
- __HM_addr.sin_port = (hmserv) ? hmserv->s_port : HM_SVC_FALLBACK;
-
- (void) memcpy((char *)&__HM_addr.sin_addr, addr, 4);
+ /* Set up local loopback address for HostManager */
+ __HM_addr = g_inet_socket_address_new_from_string("127.0.0.1", port);
/* Initialize the input queue */
g_queue_init(&Z_input_queue);
@@ -69,12 +60,12 @@
* not be "right", but this is is ok, since none of the servers call
* krb_rd_req. */
- servaddr.s_addr = INADDR_NONE;
+ servaddr = INADDR_NONE;
if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
return code;
}
- if ((code = ZhmStat(NULL, &notice)) != ZERR_NONE) {
+ if ((code = ZhmStat(&notice)) != ZERR_NONE) {
return code;
}
@@ -87,63 +78,103 @@
#ifdef ZEPHYR_USES_KERBEROS
krealm = krb_realmofhost(notice.z_message);
#endif
- hostent = gethostbyname(notice.z_message);
- if (hostent && hostent->h_addrtype == AF_INET) {
- memcpy(&servaddr, hostent->h_addr, sizeof(servaddr));
+ resolver = g_resolver_get_default();
+ hosts = g_resolver_lookup_by_name(resolver, notice.z_message, NULL, NULL);
+ while (hosts) {
+ GInetAddress *host_addr = hosts->data;
+ if (g_inet_address_get_family(host_addr) == G_SOCKET_FAMILY_IPV4) {
+ memcpy(&servaddr, g_inet_address_to_bytes(host_addr),
+ sizeof(servaddr));
+ g_list_free_full(hosts, g_object_unref);
+ hosts = NULL;
+ break;
+ }
+ g_object_unref(host_addr);
+ hosts = g_list_delete_link(hosts, hosts);
}
ZFreeNotice(&notice);
#ifdef ZEPHYR_USES_KERBEROS
- if (krealm) {
- g_strlcpy(__Zephyr_realm, krealm, REALM_SZ);
- } else if ((krb_get_tf_fullname(TKT_FILE, d1, d2, __Zephyr_realm)
- != KSUCCESS) &&
- ((krbval = krb_get_lrealm(__Zephyr_realm, 1)) != KSUCCESS)) {
- return (krbval);
- }
+ if (krealm) {
+ g_strlcpy(__Zephyr_realm, krealm, REALM_SZ);
+ } else if ((krb_get_tf_fullname(TKT_FILE, d1, d2, __Zephyr_realm) !=
+ KSUCCESS) &&
+ ((krbval = krb_get_lrealm(__Zephyr_realm, 1)) != KSUCCESS)) {
+ g_object_unref(resolver);
+ return krbval;
+ }
#else
- g_strlcpy(__Zephyr_realm, "local-realm", REALM_SZ);
+ g_strlcpy(__Zephyr_realm, "local-realm", REALM_SZ);
#endif
- __My_addr.s_addr = INADDR_NONE;
- if (servaddr.s_addr != INADDR_NONE) {
- /* Try to get the local interface address by connecting a UDP
- * socket to the server address and getting the local address.
- * Some broken operating systems (e.g. Solaris 2.0-2.5) yield
- * INADDR_ANY (zero), so we have to check for that. */
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s != -1) {
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- memcpy(&sin.sin_addr, &servaddr, sizeof(servaddr));
- sin.sin_port = HM_SRV_SVC_FALLBACK;
- if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) == 0
- && getsockname(s, (struct sockaddr *) &sin, &sinsize) == 0
- && sin.sin_addr.s_addr != 0)
- memcpy(&__My_addr, &sin.sin_addr, sizeof(__My_addr));
- close(s);
+ __My_addr = INADDR_NONE;
+ if (servaddr != INADDR_NONE) {
+ /* Try to get the local interface address by connecting a UDP
+ * socket to the server address and getting the local address.
+ * Some broken operating systems (e.g. Solaris 2.0-2.5) yield
+ * INADDR_ANY (zero), so we have to check for that. */
+ GSocket *s = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
+ G_SOCKET_PROTOCOL_DEFAULT, NULL);
+ if (s != NULL) {
+ GSocketAddress *remote_addr = NULL;
+ GInetAddress *inet_addr = NULL;
+
+ inet_addr = g_inet_address_new_from_bytes((const guint8 *)&servaddr,
+ G_SOCKET_FAMILY_IPV4);
+ remote_addr =
+ g_inet_socket_address_new(inet_addr, HM_SRV_SVC_FALLBACK);
+ g_object_unref(inet_addr);
+
+ if (g_socket_connect(s, remote_addr, NULL, NULL)) {
+ GSocketAddress *local_addr =
+ g_socket_get_local_address(s, NULL);
+ if (local_addr) {
+ inet_addr = g_inet_socket_address_get_address(
+ G_INET_SOCKET_ADDRESS(local_addr));
+ if (inet_addr) {
+ memcpy(&__My_addr, g_inet_address_to_bytes(inet_addr),
+ sizeof(__My_addr));
+ g_object_unref(inet_addr);
+ }
+ g_object_unref(local_addr);
+ }
+ }
+ g_object_unref(remote_addr);
+ g_object_unref(s);
+ }
}
- }
- if (__My_addr.s_addr == INADDR_NONE) {
- /* We couldn't figure out the local interface address by the
- * above method. Try by resolving the local hostname. (This
- * is a pretty broken thing to do, and unfortunately what we
- * always do on server machines.) */
- if (gethostname(hostname, sizeof(hostname)) == 0) {
- hostent = gethostbyname(hostname);
- if (hostent && hostent->h_addrtype == AF_INET)
- memcpy(&__My_addr, hostent->h_addr, sizeof(__My_addr));
+ if (__My_addr == INADDR_NONE) {
+ /* We couldn't figure out the local interface address by the
+ * above method. Try by resolving the local hostname. (This
+ * is a pretty broken thing to do, and unfortunately what we
+ * always do on server machines.) */
+ const gchar *hostname = g_get_host_name();
+ hosts = g_resolver_lookup_by_name(resolver, hostname, NULL, NULL);
+ while (hosts) {
+ GInetAddress *host_addr = hosts->data;
+ if (g_inet_address_get_family(host_addr) == G_SOCKET_FAMILY_IPV4) {
+ memcpy(&servaddr, g_inet_address_to_bytes(host_addr),
+ sizeof(servaddr));
+ g_list_free_full(hosts, g_object_unref);
+ hosts = NULL;
+ break;
+ }
+ g_object_unref(host_addr);
+ hosts = g_list_delete_link(hosts, hosts);
+ }
}
- }
- /* If the above methods failed, zero out __My_addr so things will
- * sort of kind of work. */
- if (__My_addr.s_addr == INADDR_NONE)
- __My_addr.s_addr = 0;
+ /* If the above methods failed, zero out __My_addr so things will sort
+ * of kind of work. */
+ if (__My_addr == INADDR_NONE) {
+ __My_addr = 0;
+ }
- /* Get the sender so we can cache it */
- (void) ZGetSender();
+ g_object_unref(resolver);
- return (ZERR_NONE);
+ /* Get the sender so we can cache it */
+ ZGetSender();
+
+ return ZERR_NONE;
}
--- a/libpurple/protocols/zephyr/ZOpenPort.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZOpenPort.c Fri Dec 11 04:12:45 2020 -0600
@@ -19,55 +19,49 @@
Code_t
ZOpenPort(unsigned short *port)
{
- struct sockaddr_in bindin;
- socklen_t len;
+ GSocketAddress *bindin = NULL;
+ GError *error = NULL;
- (void) ZClosePort();
- memset(&bindin, 0, sizeof(bindin));
-
- if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- __Zephyr_fd = -1;
- return (errno);
- }
+ ZClosePort();
-#ifdef SO_BSDCOMPAT
- {
- int on = 1;
-
- if (setsockopt(__Zephyr_fd, SOL_SOCKET, SO_BSDCOMPAT,
- (char *)&on, sizeof(on)) != 0)
- {
- purple_debug_warning("zephyr", "couldn't setsockopt\n");
- }
+ __Zephyr_socket = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
+ G_SOCKET_PROTOCOL_DEFAULT, &error);
+ if (__Zephyr_socket == NULL) {
+ purple_debug_error("zephyr", "Failed to open socket: %s",
+ error->message);
+ g_error_free(error);
+ return ZERR_INTERNAL;
}
-#endif
-
- bindin.sin_family = AF_INET;
- if (port && *port)
- bindin.sin_port = *port;
- else
- bindin.sin_port = 0;
-
- bindin.sin_addr.s_addr = INADDR_ANY;
-
- if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) {
- if (errno == EADDRINUSE && port && *port)
- return (ZERR_PORTINUSE);
- else
- return (errno);
- }
+ bindin = g_inet_socket_address_new_from_string("0.0.0.0", port ? *port : 0);
+ if (!g_socket_bind(__Zephyr_socket, bindin, FALSE, &error)) {
+ gint err = ZERR_INTERNAL;
+ if (error->code == G_IO_ERROR_ADDRESS_IN_USE && port && *port) {
+ err = ZERR_PORTINUSE;
+ }
+ purple_debug_error("zephyr", "Failed to bind socket to port %d: %s",
+ port ? *port : 0, error->message);
+ g_error_free(error);
+ g_object_unref(bindin);
+ g_clear_object(&__Zephyr_socket);
+ return err;
+ }
+ g_object_unref(bindin);
- if (!bindin.sin_port) {
- len = sizeof(bindin);
- if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len))
- return (errno);
- }
+ bindin = g_socket_get_local_address(__Zephyr_socket, &error);
+ if (bindin == NULL) {
+ purple_debug_error("zephyr", "Failed to get bound socket port: %s",
+ error->message);
+ g_error_free(error);
+ g_clear_object(&__Zephyr_socket);
+ return ZERR_INTERNAL;
+ }
+ __Zephyr_port =
+ g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(bindin));
+ if (port) {
+ *port = __Zephyr_port;
+ }
+ g_object_unref(bindin);
- __Zephyr_port = bindin.sin_port;
-
- if (port)
- *port = bindin.sin_port;
-
- return (ZERR_NONE);
+ return ZERR_NONE;
}
--- a/libpurple/protocols/zephyr/ZParseNot.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZParseNot.c Fri Dec 11 04:12:45 2020 -0600
@@ -10,6 +10,8 @@
#include "internal.h"
+#include <gio/gio.h>
+
#include <purple.h>
/* Assume that strlen is efficient on this machine... */
@@ -111,15 +113,23 @@
/*XXX 3 */
numfields -= 2; /* numfields, version, and checksum */
if (numfields < 0) {
+ GInetAddress *inet_addr = NULL;
+ gchar *inet_addr_str = NULL;
badpkt:
-#if 0
+ inet_addr = g_inet_address_new_from_bytes(
+ (const guint8 *)&notice->z_uid.zuid_addr,
+ G_SOCKET_FAMILY_IPV4);
+ inet_addr_str = g_inet_address_to_string(inet_addr);
#ifdef __LINE__
lineno = __LINE__;
- purple_debug_error("zephyr", "ZParseNotice: bad packet from %s/%d (line %d)", inet_ntoa (notice->z_uid.zuid_addr.s_addr), notice->z_port, lineno);
+ purple_debug_error("zephyr", "ZParseNotice: bad packet from %s/%d (line %d)",
+ inet_addr_str, notice->z_port, lineno);
#else
- purple_debug_error("zephyr", "ZParseNotice: bad packet from %s/%d", inet_ntoa (notice->z_uid.zuid_addr.s_addr), notice->z_port);
+ purple_debug_error("zephyr", "ZParseNotice: bad packet from %s/%d",
+ inet_addr_str, notice->z_port);
#endif
-#endif
+ g_free(inet_addr_str);
+ g_object_unref(inet_addr);
return ZERR_BADPKT;
}
--- a/libpurple/protocols/zephyr/ZPeekNot.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZPeekNot.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZPeekNotice(ZNotice_t *notice, struct sockaddr_in *from)
+ZPeekNotice(ZNotice_t *notice, GSocketAddress **from)
{
char *buffer;
int len;
--- a/libpurple/protocols/zephyr/ZPeekPkt.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZPeekPkt.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZPeekPacket(char **buffer, int *ret_len, struct sockaddr_in *from)
+ZPeekPacket(char **buffer, int *ret_len, GSocketAddress **from)
{
Code_t retval;
Z_InputQ *nextq;
@@ -28,8 +28,9 @@
(void) memcpy(*buffer, nextq->packet, *ret_len);
- if (from)
- *from = nextq->from;
+ if (from) {
+ *from = g_object_ref(nextq->from);
+ }
return (ZERR_NONE);
}
--- a/libpurple/protocols/zephyr/ZPending.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZPending.c Fri Dec 11 04:12:45 2020 -0600
@@ -15,7 +15,7 @@
{
int retval;
- if (ZGetFD() < 0) {
+ if (ZGetSocket() == NULL) {
errno = ZERR_NOPORT;
return (-1);
}
--- a/libpurple/protocols/zephyr/ZRecvNot.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZRecvNot.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZReceiveNotice(ZNotice_t *notice, struct sockaddr_in *from)
+ZReceiveNotice(ZNotice_t *notice, GSocketAddress **from)
{
char *buffer;
Z_InputQ *nextq;
@@ -31,8 +31,9 @@
if (!(buffer = (char *) malloc((unsigned) len)))
return (ENOMEM);
- if (from)
- *from = nextq->from;
+ if (from) {
+ *from = g_object_ref(nextq->from);
+ }
(void) memcpy(buffer, nextq->packet, len);
--- a/libpurple/protocols/zephyr/ZRecvPkt.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZRecvPkt.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,7 +11,7 @@
#include "internal.h"
Code_t
-ZReceivePacket(ZPacket_t buffer, int *ret_len, struct sockaddr_in *from)
+ZReceivePacket(ZPacket_t buffer, int *ret_len, GSocketAddress **from)
{
Code_t retval;
Z_InputQ *nextq;
@@ -27,8 +27,9 @@
(void) memcpy(buffer, nextq->packet, *ret_len);
- if (from)
- *from = nextq->from;
+ if (from) {
+ *from = g_object_ref(nextq->from);
+ }
Z_RemQueue(nextq);
--- a/libpurple/protocols/zephyr/ZRetSubs.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZRetSubs.c Fri Dec 11 04:12:45 2020 -0600
@@ -49,9 +49,12 @@
if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS)
return (retval);
- if (ZGetFD() < 0)
- if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE)
- return (retval);
+ if (ZGetSocket() == NULL) {
+ retval = ZOpenPort(NULL);
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
+ }
notice->z_kind = ACKED;
notice->z_port = __Zephyr_port;
--- a/libpurple/protocols/zephyr/ZSendPkt.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZSendPkt.c Fri Dec 11 04:12:45 2020 -0600
@@ -8,6 +8,8 @@
* "mit-copyright.h".
*/
+#include <purple.h>
+
#include "internal.h"
#ifdef WIN32
#include <winsock.h>
@@ -20,39 +22,50 @@
Code_t
ZSendPacket(char *packet, int len, int waitforack)
{
- Code_t retval;
- struct sockaddr_in dest;
- ZNotice_t notice, acknotice;
+ GError *error = NULL;
+ Code_t retval;
+ ZNotice_t notice, acknotice;
- if (!packet || len < 0)
- return (ZERR_ILLVAL);
+ if (packet == NULL || len < 0) {
+ return ZERR_ILLVAL;
+ }
- if (len > Z_MAXPKTLEN)
- return (ZERR_PKTLEN);
+ if (len > Z_MAXPKTLEN) {
+ return ZERR_PKTLEN;
+ }
- if (ZGetFD() < 0)
- if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE)
- return (retval);
-
- dest = ZGetDestAddr();
+ if (ZGetSocket() == NULL) {
+ retval = ZOpenPort(NULL);
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
+ }
- if (sendto(ZGetFD(), packet, len, 0, (struct sockaddr *)&dest,
- sizeof(dest)) < 0)
- return (errno);
+ if (g_socket_send_to(ZGetSocket(), ZGetDestAddr(), packet, len, NULL,
+ &error) < 0) {
+ purple_debug_error("zephyr", "Failed to send packet of size %d: %s",
+ len, error->message);
+ g_error_free(error);
+ return ZERR_INTERNAL;
+ }
- if (!waitforack)
- return (ZERR_NONE);
+ if (!waitforack) {
+ return ZERR_NONE;
+ }
- if ((retval = ZParseNotice(packet, len, &notice)) != ZERR_NONE)
- return (retval);
+ if ((retval = ZParseNotice(packet, len, &notice)) != ZERR_NONE) {
+ return retval;
+ }
- retval = Z_WaitForNotice (&acknotice, wait_for_hmack, &notice.z_uid,
- HM_TIMEOUT);
- if (retval == ETIMEDOUT)
- return ZERR_HMDEAD;
- if (retval == ZERR_NONE)
- ZFreeNotice (&acknotice);
- return retval;
+ retval = Z_WaitForNotice(&acknotice, wait_for_hmack, &notice.z_uid,
+ HM_TIMEOUT);
+ if (retval == ETIMEDOUT) {
+ return ZERR_HMDEAD;
+ }
+ if (retval == ZERR_NONE) {
+ ZFreeNotice(&acknotice);
+ }
+ return retval;
}
static int wait_for_hmack(ZNotice_t *notice, void *uid)
--- a/libpurple/protocols/zephyr/ZSetDest.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZSetDest.c Fri Dec 11 04:12:45 2020 -0600
@@ -11,9 +11,9 @@
#include "internal.h"
Code_t
-ZSetDestAddr(struct sockaddr_in *addr)
+ZSetDestAddr(GSocketAddress *addr)
{
- __HM_addr = *addr;
+ g_set_object(&__HM_addr, addr);
- return (ZERR_NONE);
+ return ZERR_NONE;
}
--- a/libpurple/protocols/zephyr/ZSubs.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZSubs.c Fri Dec 11 04:12:45 2020 -0600
@@ -162,10 +162,11 @@
if (retval != ZERR_NONE)
return (retval);
- if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
- ZCompareUIDPred, (char *)&notice->z_uid)) !=
- ZERR_NONE)
- return (retval);
+ retval = ZIfNotice(&retnotice, NULL, ZCompareUIDPred,
+ (char *)&notice->z_uid);
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
if (retnotice.z_kind == SERVNAK) {
ZFreeNotice(&retnotice);
return (ZERR_SERVNAK);
--- a/libpurple/protocols/zephyr/ZWait4Not.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZWait4Not.c Fri Dec 11 04:12:45 2020 -0600
@@ -19,40 +19,44 @@
Z_WaitForNotice(ZNotice_t *notice, int (*pred)(ZNotice_t *, void *), void *arg,
int timeout)
{
- Code_t retval;
- gint64 t0, tdiff;
- struct timeval tv;
- fd_set fdmask;
- int i, fd;
+ Code_t retval;
+ gint64 t0, tdiff, timeout_us;
+ GError *error = NULL;
- retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
- (char *) arg);
- if (retval == ZERR_NONE)
- return ZERR_NONE;
- if (retval != ZERR_NONOTICE)
- return retval;
+ retval = ZCheckIfNotice(notice, NULL, pred, (char *)arg);
+ if (retval == ZERR_NONE) {
+ return ZERR_NONE;
+ }
+ if (retval != ZERR_NONOTICE) {
+ return retval;
+ }
- fd = ZGetFD ();
- FD_ZERO (&fdmask);
- tv.tv_sec = timeout;
- tv.tv_usec = 0;
- t0 = g_get_monotonic_time() + timeout * G_USEC_PER_SEC;
- while (1) {
- FD_SET (fd, &fdmask);
- i = select (fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tv);
- if (i == 0)
- return ETIMEDOUT;
- if (i < 0 && errno != EINTR)
- return errno;
- if (i > 0) {
- retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
- (char *) arg);
- if (retval != ZERR_NONOTICE) /* includes ZERR_NONE */
- return retval;
- }
+ timeout_us = timeout * G_USEC_PER_SEC;
+ t0 = g_get_monotonic_time() + timeout_us;
+ while (TRUE) {
+ if (!g_socket_condition_timed_wait(ZGetSocket(), G_IO_IN, timeout_us,
+ NULL, &error)) {
+ gint ret = ZERR_INTERNAL;
+ if (error->code == G_IO_ERROR_TIMED_OUT) {
+ ret = ETIMEDOUT;
+ }
+ g_error_free(error);
+ return ret;
+ }
+
+ retval = ZCheckIfNotice(notice, NULL, pred, (char *)arg);
+ if (retval != ZERR_NONOTICE) {
+ /* includes ZERR_NONE */
+ return retval;
+ }
+
tdiff = t0 - g_get_monotonic_time();
- tv.tv_sec = tdiff / G_USEC_PER_SEC;
- tv.tv_usec = tdiff - tv.tv_sec * G_USEC_PER_SEC;
- }
- /*NOTREACHED*/
+ if (tdiff < 0) {
+ return ETIMEDOUT;
+ }
+ /* g_socket_condition_timed_wait requires timeout to be an integral
+ * number of milliseconds. */
+ timeout_us = (tdiff / 1000 + 1) * 1000;
+ }
+ /* NOTREACHED */
}
--- a/libpurple/protocols/zephyr/ZhmStat.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/ZhmStat.c Fri Dec 11 04:12:45 2020 -0600
@@ -16,59 +16,57 @@
#include <sys/socket.h>
#endif
-#ifndef INADDR_LOOPBACK
-#define INADDR_LOOPBACK 0x7f000001
-#endif
-
Code_t
-ZhmStat(struct in_addr *hostaddr, ZNotice_t *notice)
+ZhmStat(ZNotice_t *notice)
{
- struct servent *sp;
- struct sockaddr_in sin;
- ZNotice_t req;
- Code_t code;
- struct timeval tv;
- fd_set readers;
+ struct servent *sp;
+ GInetAddress *inet_addr = NULL;
+ GSocketAddress *addr = NULL;
+ ZNotice_t req;
+ Code_t code;
+ GError *error = NULL;
- (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in));
+ sp = getservbyname(HM_SVCNAME, "udp");
- sp = getservbyname(HM_SVCNAME, "udp");
-
- sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
- sin.sin_family = AF_INET;
-
- if (hostaddr)
- sin.sin_addr = *hostaddr;
- else
- sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ memset(&req, 0, sizeof(req));
+ req.z_kind = STAT;
+ req.z_port = 0;
+ req.z_class = HM_STAT_CLASS;
+ req.z_class_inst = HM_STAT_CLIENT;
+ req.z_opcode = HM_GIMMESTATS;
+ req.z_sender = "";
+ req.z_recipient = "";
+ req.z_default_format = "";
+ req.z_message_len = 0;
- (void) memset((char *)&req, 0, sizeof(req));
- req.z_kind = STAT;
- req.z_port = 0;
- req.z_class = HM_STAT_CLASS;
- req.z_class_inst = HM_STAT_CLIENT;
- req.z_opcode = HM_GIMMESTATS;
- req.z_sender = "";
- req.z_recipient = "";
- req.z_default_format = "";
- req.z_message_len = 0;
+ inet_addr = g_inet_address_new_loopback(G_SOCKET_FAMILY_IPV4);
+ addr = g_inet_socket_address_new(inet_addr,
+ sp ? sp->s_port : HM_SVC_FALLBACK);
+ code = ZSetDestAddr(addr);
+ g_object_unref(inet_addr);
+ g_object_unref(addr);
+ if (code != ZERR_NONE) {
+ return code;
+ }
- if ((code = ZSetDestAddr(&sin)) != ZERR_NONE)
- return(code);
+ if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) {
+ return code;
+ }
- if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE)
- return(code);
+ /* Wait up to ten seconds for a response. */
+ if (!g_socket_condition_timed_wait(ZGetSocket(), G_IO_IN,
+ 10 * G_USEC_PER_SEC, NULL, &error)) {
+ gint ret = ZERR_INTERNAL;
+ if (error->code == G_IO_ERROR_TIMED_OUT) {
+ ret = ETIMEDOUT;
+ }
+ g_error_free(error);
+ return ret;
+ }
- /* Wait up to ten seconds for a response. */
- FD_ZERO(&readers);
- FD_SET(ZGetFD(), &readers);
- tv.tv_sec = 10;
- tv.tv_usec = 0;
- code = select(ZGetFD() + 1, &readers, NULL, NULL, &tv);
- if (code < 0 && errno != EINTR)
- return(errno);
- if (code == 0 || (code < 0 && errno == EINTR) || ZPending() == 0)
- return(ZERR_HMDEAD);
+ if (ZPending() == 0) {
+ return ZERR_HMDEAD;
+ }
- return(ZReceiveNotice(notice, (struct sockaddr_in *) 0));
+ return ZReceiveNotice(notice, NULL);
}
--- a/libpurple/protocols/zephyr/Zinternal.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/Zinternal.c Fri Dec 11 04:12:45 2020 -0600
@@ -9,6 +9,8 @@
* "mit-copyright.h".
*/
+#include <purple.h>
+
#include "internal.h"
#ifdef WIN32
#include <winsock2.h>
@@ -17,14 +19,13 @@
#include <sys/socket.h>
#endif
-int __Zephyr_fd = -1;
-int __Zephyr_port = -1;
-struct in_addr __My_addr;
+GSocket *__Zephyr_socket = NULL;
+gint __Zephyr_port = -1;
+guint32 __My_addr;
int __Q_CompleteLength;
int __Q_Size;
GQueue Z_input_queue = G_QUEUE_INIT;
-struct sockaddr_in __HM_addr;
-struct sockaddr_in __HM_addr_real;
+GSocketAddress *__HM_addr;
ZLocations_t *__locate_list;
int __locate_num;
int __locate_next;
@@ -112,21 +113,6 @@
return 0;
}
-
-/* Return 1 if there is a packet waiting, 0 otherwise */
-
-static int Z_PacketWaiting(void)
-{
- struct timeval tv;
- fd_set read;
-
- tv.tv_sec = tv.tv_usec = 0;
- FD_ZERO(&read);
- FD_SET(ZGetFD(), &read);
- return (select(ZGetFD() + 1, &read, NULL, NULL, &tv));
-}
-
-
/* Wait for a complete notice to become available */
Code_t Z_WaitForComplete(void)
@@ -149,16 +135,18 @@
Code_t
Z_ReadEnqueue(void)
{
- Code_t retval;
-
- if (ZGetFD() < 0)
- return (ZERR_NOPORT);
+ if (ZGetSocket() == NULL) {
+ return ZERR_NOPORT;
+ }
- while (Z_PacketWaiting())
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
+ while (g_socket_condition_check(ZGetSocket(), G_IO_IN)) {
+ Code_t retval = Z_ReadWait();
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
+ }
- return (ZERR_NONE);
+ return ZERR_NONE;
}
@@ -208,49 +196,52 @@
Z_Hole *hole = NULL;
ZNotice_t notice;
ZPacket_t packet;
- struct sockaddr_in olddest, from;
+ GSocketAddress *from = NULL;
int packet_len, zvlen, part, partof;
- socklen_t from_len;
char *slash;
Code_t retval;
- fd_set fds;
- struct timeval tv;
+ GError *error = NULL;
- if (ZGetFD() < 0)
- return (ZERR_NOPORT);
+ if (ZGetSocket() == NULL) {
+ return ZERR_NOPORT;
+ }
- FD_ZERO(&fds);
- FD_SET(ZGetFD(), &fds);
- tv.tv_sec = 60;
- tv.tv_usec = 0;
-
- if (select(ZGetFD() + 1, &fds, NULL, NULL, &tv) < 0)
- return (errno);
- if (!FD_ISSET(ZGetFD(), &fds))
- return ETIMEDOUT;
-
- from_len = sizeof(struct sockaddr_in);
+ if (!g_socket_condition_timed_wait(ZGetSocket(), G_IO_IN,
+ 60 * G_USEC_PER_SEC, NULL, &error)) {
+ gint ret = ZERR_INTERNAL;
+ if (error->code == G_IO_ERROR_TIMED_OUT) {
+ ret = ETIMEDOUT;
+ }
+ g_error_free(error);
+ return ret;
+ }
- packet_len = recvfrom(ZGetFD(), packet, sizeof(packet) - 1, 0,
- (struct sockaddr *)&from, &from_len);
-
- if (packet_len < 0)
- return (errno);
-
- if (!packet_len)
- return (ZERR_EOF);
+ packet_len = g_socket_receive_from(ZGetSocket(), &from, packet,
+ sizeof(packet) - 1, NULL, &error);
+ if (packet_len < 0) {
+ purple_debug_error("zephyr", "Unable to receive from socket: %s",
+ error->message);
+ g_error_free(error);
+ return ZERR_INTERNAL;
+ }
- packet[packet_len] = '\0';
+ if (packet_len == 0) {
+ return ZERR_EOF;
+ }
+
+ packet[packet_len] = '\0';
- /* Ignore obviously non-Zephyr packets. */
- zvlen = sizeof(ZVERSIONHDR) - 1;
- if (packet_len < zvlen || memcmp(packet, ZVERSIONHDR, zvlen) != 0) {
- Z_discarded_packets++;
- return (ZERR_NONE);
- }
+ /* Ignore obviously non-Zephyr packets. */
+ zvlen = sizeof(ZVERSIONHDR) - 1;
+ if (packet_len < zvlen || memcmp(packet, ZVERSIONHDR, zvlen) != 0) {
+ Z_discarded_packets++;
+ g_object_unref(from);
+ return ZERR_NONE;
+ }
/* Parse the notice */
if ((retval = ZParseNotice(packet, packet_len, &notice)) != ZERR_NONE) {
+ g_object_unref(from);
return retval;
}
@@ -258,6 +249,7 @@
* whoever sent it to say we got it. */
if (notice.z_kind != HMACK && notice.z_kind != SERVACK &&
notice.z_kind != SERVNAK && notice.z_kind != CLIENTACK) {
+ GSocketAddress *olddest = NULL;
ZNotice_t tmpnotice;
ZPacket_t pkt;
int len;
@@ -268,19 +260,24 @@
olddest = __HM_addr;
__HM_addr = from;
if ((retval = ZFormatSmallRawNotice(&tmpnotice, pkt, &len)) != ZERR_NONE) {
+ __HM_addr = olddest;
+ g_object_unref(from);
return retval;
}
if ((retval = ZSendPacket(pkt, len, 0)) != ZERR_NONE) {
+ __HM_addr = olddest;
+ g_object_unref(from);
return retval;
}
__HM_addr = olddest;
}
if (find_or_insert_uid(&notice.z_uid, notice.z_kind)) {
+ g_object_unref(from);
return ZERR_NONE;
}
/* Check authentication on the notice. */
- notice.z_checked_auth = ZCheckAuthentication(&notice, &from);
+ notice.z_checked_auth = ZCheckAuthentication(&notice);
/*
* Parse apart the z_multinotice field - if the field is blank for
@@ -300,9 +297,11 @@
partof = notice.z_message_len;
}
- /* Too big a packet...just ignore it! */
- if (partof > Z_MAXNOTICESIZE)
- return (ZERR_NONE);
+ /* Too big a packet...just ignore it! */
+ if (partof > Z_MAXNOTICESIZE) {
+ g_object_unref(from);
+ return ZERR_NONE;
+ }
/* If we can find a notice in the queue with the same multiuid field,
* insert the current fragment as appropriate. */
@@ -319,8 +318,9 @@
regarding failure/success)
*/
if (!ZCompareUID(&notice.z_multiuid, &notice.z_uid)) {
- /* they're not the same... throw away this packet. */
- return(ZERR_NONE);
+ /* they're not the same... throw away this packet. */
+ g_object_unref(from);
+ return ZERR_NONE;
}
/* fall thru & process it */
default:
@@ -334,6 +334,7 @@
qptr->header_len = packet_len - notice.z_message_len;
qptr->header = g_memdup(packet, qptr->header_len);
}
+ g_object_unref(from);
return Z_AddNoticeToEntry(qptr, &notice, part);
}
}
@@ -341,6 +342,7 @@
/* We'll have to create a new entry...make sure the queue isn't going
* to get too big. */
if (__Q_Size + partof > Z_MAXQUEUESIZE) {
+ g_object_unref(from);
return ZERR_NONE;
}
@@ -351,11 +353,11 @@
/* Insert the entry at the end of the queue */
g_queue_push_tail(&Z_input_queue, qptr);
- /* Copy the from field, multiuid, kind, and checked authentication. */
- qptr->from = from;
- qptr->uid = notice.z_multiuid;
- qptr->kind = notice.z_kind;
- qptr->auth = notice.z_checked_auth;
+ /* Copy the from field, multiuid, kind, and checked authentication. */
+ qptr->from = from;
+ qptr->uid = notice.z_multiuid;
+ qptr->kind = notice.z_kind;
+ qptr->auth = notice.z_checked_auth;
/* If this is the first part of the notice, we take the header from it.
* We only take it if this is the first fragment so that the Unique
@@ -501,28 +503,38 @@
Z_FormatHeader(ZNotice_t *notice, char *buffer, int buffer_len, int *len,
Z_AuthProc cert_routine)
{
- Code_t retval;
- static char version[BUFSIZ]; /* default init should be all \0 */
+ static char version[BUFSIZ]; /* default init should be all \0 */
gint64 realtime;
- struct sockaddr_in name;
- socklen_t namelen = sizeof(name);
- if (!notice->z_sender)
- notice->z_sender = ZGetSender();
+ if (!notice->z_sender) {
+ notice->z_sender = ZGetSender();
+ }
+
+ if (notice->z_port == 0) {
+ GSocketAddress *addr = NULL;
+ GError *error = NULL;
- if (notice->z_port == 0) {
- if (ZGetFD() < 0) {
- retval = ZOpenPort((unsigned short *)0);
- if (retval != ZERR_NONE)
- return (retval);
+ if (ZGetSocket() == NULL) {
+ Code_t retval = ZOpenPort(NULL);
+ if (retval != ZERR_NONE) {
+ return retval;
+ }
+ }
+
+ addr = g_socket_get_local_address(ZGetSocket(), &error);
+ if (addr == NULL) {
+ purple_debug_error("zephyr",
+ "Unable to determine socket local address: %s",
+ error->message);
+ g_error_free(error);
+ return ZERR_INTERNAL;
+ }
+ notice->z_port =
+ g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(addr));
+ g_object_unref(addr);
}
- retval = getsockname(ZGetFD(), (struct sockaddr *) &name, &namelen);
- if (retval != 0)
- return (retval);
- notice->z_port = name.sin_port;
- }
- notice->z_multinotice = "";
+ notice->z_multinotice = "";
realtime = g_get_real_time();
notice->z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC;
@@ -533,14 +545,14 @@
memcpy(&notice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr));
- notice->z_multiuid = notice->z_uid;
+ notice->z_multiuid = notice->z_uid;
- if (!version[0])
- (void) sprintf(version, "%s%d.%d", ZVERSIONHDR, ZVERSIONMAJOR,
- ZVERSIONMINOR);
- notice->z_version = version;
+ if (!version[0]) {
+ sprintf(version, "%s%d.%d", ZVERSIONHDR, ZVERSIONMAJOR, ZVERSIONMINOR);
+ }
+ notice->z_version = version;
- return Z_FormatAuthHeader(notice, buffer, buffer_len, len, cert_routine);
+ return Z_FormatAuthHeader(notice, buffer, buffer_len, len, cert_routine);
}
Code_t
@@ -728,6 +740,8 @@
g_free(qptr->msg);
g_free(qptr->packet);
+ g_clear_object(&qptr->from);
+
g_slist_free_full(qptr->holelist, g_free);
g_queue_remove(&Z_input_queue, qptr);
@@ -765,8 +779,7 @@
htonl((unsigned long)partnotice.z_uid.tv.tv_sec);
partnotice.z_uid.tv.tv_usec =
htonl((unsigned long)partnotice.z_uid.tv.tv_usec);
- (void) memcpy((char *)&partnotice.z_uid.zuid_addr, &__My_addr,
- sizeof(__My_addr));
+ memcpy(&partnotice.z_uid.zuid_addr, &__My_addr, sizeof(__My_addr));
}
message_len = MIN(notice->z_message_len - offset, fragsize);
partnotice.z_message = (char*)notice->z_message+offset;
--- a/libpurple/protocols/zephyr/zephyr.c Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/zephyr.c Fri Dec 11 04:12:45 2020 -0600
@@ -790,7 +790,8 @@
/* Called when the server notifies us a message couldn't get sent */
-static void message_failed(PurpleConnection *gc, ZNotice_t *notice, struct sockaddr_in from)
+static void
+message_failed(PurpleConnection *gc, ZNotice_t *notice)
{
if (g_ascii_strcasecmp(notice->z_class, "message")) {
gchar* chat_failed = g_strdup_printf(
@@ -948,17 +949,18 @@
gcc = purple_conversations_find_chat_with_account(
zt2->name, purple_connection_get_account(gc));
-#ifndef INET_ADDRSTRLEN
-#define INET_ADDRSTRLEN 16
-#endif
if (!purple_chat_conversation_has_user(gcc, stripped_sender)) {
- gchar ipaddr[INET_ADDRSTRLEN];
-#ifdef HAVE_INET_NTOP
- inet_ntop(AF_INET, &notice.z_sender_addr.s_addr, ipaddr, sizeof(ipaddr));
-#else
- memcpy(ipaddr,inet_ntoa(notice.z_sender_addr),sizeof(ipaddr));
-#endif
- purple_chat_conversation_add_user(gcc, stripped_sender, ipaddr, PURPLE_CHAT_USER_NONE, TRUE);
+ GInetAddress *inet_addr = NULL;
+ gchar *ipaddr = NULL;
+
+ inet_addr = g_inet_address_new_from_bytes(
+ (const guint8 *)&notice.z_sender_addr,
+ G_SOCKET_FAMILY_IPV4);
+ ipaddr = g_inet_address_to_string(inet_addr);
+ purple_chat_conversation_add_user(gcc, stripped_sender, ipaddr,
+ PURPLE_CHAT_USER_NONE, TRUE);
+ g_free(ipaddr);
+ g_object_unref(inet_addr);
}
purple_serv_got_chat_in(gc, zt2->id, send_inst_utf8,
PURPLE_MESSAGE_RECV, buf3, time(NULL));
@@ -1279,10 +1281,9 @@
PurpleConnection *gc = (PurpleConnection*) data;
while (ZPending()) {
ZNotice_t notice;
- struct sockaddr_in from;
/* XXX add real error reporting */
- z_call_r(ZReceiveNotice(&notice, &from));
+ z_call_r(ZReceiveNotice(&notice, NULL));
switch (notice.z_kind) {
case UNSAFE:
@@ -1292,7 +1293,7 @@
break;
case SERVACK:
if (!(g_ascii_strcasecmp(notice.z_message, ZSRVACK_NOTSENT))) {
- message_failed(gc, &notice, from);
+ message_failed(gc, &notice);
}
break;
case CLIENTACK:
--- a/libpurple/protocols/zephyr/zephyr_internal.h Fri Dec 11 01:48:49 2020 -0600
+++ b/libpurple/protocols/zephyr/zephyr_internal.h Fri Dec 11 04:12:45 2020 -0600
@@ -16,6 +16,7 @@
#endif
#include <glib.h>
+#include <gio/gio.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -61,9 +62,9 @@
#define ZAUTH_YES 1
#define ZAUTH_NO 0
-#define SERVER_SVC_FALLBACK htons((unsigned short) 2103)
-#define HM_SVC_FALLBACK htons((unsigned short) 2104)
-#define HM_SRV_SVC_FALLBACK htons((unsigned short) 2105)
+#define SERVER_SVC_FALLBACK (2103)
+#define HM_SVC_FALLBACK (2104)
+#define HM_SRV_SVC_FALLBACK (2105)
#define ZAUTH_UNSET (-3) /* Internal to client library. */
#define Z_MAXFRAGS 500 /* Max number of packet fragments */
@@ -82,7 +83,7 @@
/* Unique ID format */
typedef struct {
- struct in_addr zuid_addr;
+ guint32 zuid_addr;
struct timeval tv;
} ZUnique_Id_t;
@@ -151,7 +152,7 @@
gint packet_len;
gchar *packet;
gboolean complete;
- struct sockaddr_in from;
+ GSocketAddress *from;
GSList *holelist; /* element-type: Z_Hole* */
ZUnique_Id_t uid;
int auth;
@@ -173,7 +174,7 @@
Code_t ZSetVariable(char *var, char *value);
Code_t ZUnsetVariable(char *var);
int ZGetWGPort(void);
-Code_t ZSetDestAddr(struct sockaddr_in *);
+Code_t ZSetDestAddr(GSocketAddress *);
Code_t ZFormatNoticeList(ZNotice_t *, char **, int, char **, int *, Z_AuthProc);
Code_t ZParseNotice(char *, int, ZNotice_t *);
Code_t ZReadAscii(char *, int, unsigned char *, int);
@@ -191,15 +192,15 @@
Code_t ZLocateUser(char *, int *, Z_AuthProc);
Code_t ZRequestLocations(const char *, ZAsyncLocateData_t *, ZNotice_Kind_t,
Z_AuthProc);
-Code_t ZhmStat(struct in_addr *, ZNotice_t *);
+Code_t ZhmStat(ZNotice_t *);
Code_t ZInitialize(void);
Code_t ZFormatSmallRawNotice(ZNotice_t *, ZPacket_t, int *);
int ZCompareUID(ZUnique_Id_t *, ZUnique_Id_t *);
Code_t ZMakeAscii(char *, int, unsigned char *, int);
Code_t ZMakeAscii32(char *, int, unsigned long);
Code_t ZMakeAscii16(char *, int, unsigned int);
-Code_t ZReceivePacket(ZPacket_t, int *, struct sockaddr_in *);
-Code_t ZCheckAuthentication(ZNotice_t *, struct sockaddr_in *);
+Code_t ZReceivePacket(ZPacket_t, int *, GSocketAddress **);
+Code_t ZCheckAuthentication(ZNotice_t *);
Code_t ZSetLocation(char *exposure);
Code_t ZUnsetLocation(void);
Code_t ZFlushMyLocations(void);
@@ -215,12 +216,12 @@
char **user);
int ZCompareALDPred(ZNotice_t *notice, void *zald);
void ZFreeALD(register ZAsyncLocateData_t *zald);
-Code_t ZCheckIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
+Code_t ZCheckIfNotice(ZNotice_t *notice, GSocketAddress **from,
register int (*predicate)(ZNotice_t *, void *),
void *args);
-Code_t ZPeekPacket(char **buffer, int *ret_len, struct sockaddr_in *from);
-Code_t ZPeekNotice(ZNotice_t *notice, struct sockaddr_in *from);
-Code_t ZIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
+Code_t ZPeekPacket(char **buffer, int *ret_len, GSocketAddress **from);
+Code_t ZPeekNotice(ZNotice_t *notice, GSocketAddress **from);
+Code_t ZIfNotice(ZNotice_t *notice, GSocketAddress **from,
int (*predicate)(ZNotice_t *, void *), void *args);
Code_t ZSubscribeTo(ZSubscription_t *sublist, int nitems, unsigned int port);
Code_t ZSubscribeToSansDefaults(ZSubscription_t *sublist, int nitems,
@@ -228,7 +229,7 @@
Code_t ZUnsubscribeTo(ZSubscription_t *sublist, int nitems, unsigned int port);
Code_t ZCancelSubscriptions(unsigned int port);
int ZPending(void);
-Code_t ZReceiveNotice(ZNotice_t *notice, struct sockaddr_in *from);
+Code_t ZReceiveNotice(ZNotice_t *notice, GSocketAddress **from);
typedef Code_t (*Z_SendProc)(ZNotice_t *, char *, int, int);
@@ -259,15 +260,15 @@
extern int __subscriptions_num;
extern int __subscriptions_next;
-extern int __Zephyr_port; /* Port number */
-extern struct in_addr __My_addr;
+extern gint __Zephyr_port; /* Port number */
+extern guint32 __My_addr;
/* Macros to retrieve Zephyr library values. */
-extern int __Zephyr_fd;
+extern GSocket *__Zephyr_socket;
extern int __Q_CompleteLength;
-extern struct sockaddr_in __HM_addr;
+extern GSocketAddress *__HM_addr;
extern char __Zephyr_realm[];
-#define ZGetFD() __Zephyr_fd
+#define ZGetSocket() __Zephyr_socket
#define ZQLength() __Q_CompleteLength
#define ZGetDestAddr() __HM_addr
#define ZGetRealm() __Zephyr_realm