--- a/libpurple/protocols/zephyr/Zinternal.c Mon Nov 23 01:41:50 2020 -0600
+++ b/libpurple/protocols/zephyr/Zinternal.c Mon Nov 23 01:51:33 2020 -0600
@@ -203,6 +203,7 @@
register struct _Z_InputQ *qptr;
struct sockaddr_in olddest, from;
@@ -387,7 +388,7 @@
if (part == 0 && notice.z_message_len == partof) {
- qptr->holelist = (struct _Z_Hole *) 0;
/* allocate a msg buf for this piece */
if (notice.z_message_len == 0)
@@ -417,28 +418,43 @@
- * Well, it's a fragmented notice...allocate a hole list and
- * initialize it to the full packet size. Then insert the
- if (!(qptr->holelist = (struct _Z_Hole *)
- malloc(sizeof(struct _Z_Hole))))
- qptr->holelist->next = (struct _Z_Hole *) 0;
- qptr->holelist->first = 0;
- qptr->holelist->last = partof-1;
- return (Z_AddNoticeToEntry(qptr, ¬ice, part));
+ * Well, it's a fragmented notice...allocate a hole list and + * initialize it to the full packet size. Then insert the + hole = g_new0(Z_Hole, 1); + hole->last = partof - 1; + qptr->holelist = g_slist_prepend(qptr->holelist, hole); + return Z_AddNoticeToEntry(qptr, ¬ice, part); /* Fragment management routines - compliments, more or less, of RFC815 */
+find_hole(gconstpointer element, gconstpointer data) + Z_Hole *thishole = (Z_Hole *)element; + Z_Hole *tofind = (Z_Hole *)data; + if (tofind->first <= thishole->last && tofind->last >= thishole->first) { Z_AddNoticeToEntry(struct _Z_InputQ *qptr, ZNotice_t *notice, int part)
- int last, oldfirst, oldlast;
- struct _Z_Hole *hole, *lasthole;
/* Incorporate this notice's checked authentication. */
if (notice->z_checked_auth == ZAUTH_FAILED) {
@@ -449,103 +465,62 @@
qptr->time = g_get_monotonic_time();
- last = part+notice->z_message_len-1;
+ last = part + notice->z_message_len - 1;
- lasthole = (struct _Z_Hole *) 0;
- /* copy in the message body */
- (void) memcpy(qptr->msg+part, notice->z_message, notice->z_message_len);
+ /* copy in the message body */ + (void)memcpy(qptr->msg + part, notice->z_message, notice->z_message_len); - /* Search for a hole that overlaps with the current fragment */
- if (part <= hole->last && last >= hole->first)
+ /* Search for a hole that overlaps with the current fragment */ + hole = g_new(Z_Hole, 1); + thishole = g_slist_find_custom(qptr->holelist, hole, find_hole); + /* If we found one, delete it and reconstruct a new hole */ + gint oldfirst, oldlast; + hole = (Z_Hole *)thishole->data; + oldfirst = hole->first; + qptr->holelist = g_slist_delete_link(qptr->holelist, thishole); - /* If we found one, delete it and reconstruct a new hole */
- oldfirst = hole->first;
- lasthole->next = hole->next;
- qptr->holelist = hole->next;
- * Now create a new hole that is the original hole without the
- /* Search for the end of the hole list */
- lasthole = (struct _Z_Hole *) 0;
- struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ));
- lasthole->next = (struct _Z_Hole *)inputq;
- struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ));
- qptr->holelist = (struct _Z_Hole *)inputq;
- hole->first = oldfirst;
+ * Now create a new hole that is the original hole without the + hole = g_new0(Z_Hole, 1); + qptr->holelist = g_slist_prepend(qptr->holelist, hole); + hole->first = oldfirst; + hole = g_new0(Z_Hole, 1); + qptr->holelist = g_slist_prepend(qptr->holelist, hole); + hole->first = last + 1;
- /* Search for the end of the hole list */
- lasthole = (struct _Z_Hole *) 0;
- struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ));
- lasthole->next = (struct _Z_Hole *)inputq;
- struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ));
- qptr->holelist = (struct _Z_Hole *)inputq;
- hole->next = (struct _Z_Hole *) 0;
+ /* If there are no more holes, the packet is complete. */ + if (qptr->holelist == NULL) { + qptr->time = 0; /* don't time out anymore */ + qptr->packet_len = qptr->header_len + qptr->msg_len; + if (!(qptr->packet = (char *)malloc((unsigned)qptr->packet_len))) { + (void)memcpy(qptr->packet, qptr->header, qptr->header_len); + (void)memcpy(qptr->packet + qptr->header_len, qptr->msg, qptr->msg_len);
- qptr->time = 0; /* don't time out anymore */
- qptr->packet_len = qptr->header_len+qptr->msg_len;
- if (!(qptr->packet = (char *) malloc((unsigned) qptr->packet_len)))
- (void) memcpy(qptr->packet, qptr->header, qptr->header_len);
- (void) memcpy(qptr->packet+qptr->header_len, qptr->msg,
@@ -769,8 +744,6 @@
Z_RemQueue(struct _Z_InputQ *qptr)
- struct _Z_Hole *hole, *nexthole;
@@ -780,12 +753,7 @@
+ g_slist_free_full(qptr->holelist, g_free); if (qptr == __Q_Head && __Q_Head == __Q_Tail) {
--- a/libpurple/protocols/zephyr/internal.h Mon Nov 23 01:41:50 2020 -0600
+++ b/libpurple/protocols/zephyr/internal.h Mon Nov 23 01:51:33 2020 -0600
@@ -54,11 +54,10 @@
#define Z_NOTICETIMELIMIT 30 /* Time to wait for fragments */
#define Z_INITFILTERSIZE 30 /* Starting size of uid filter */
@@ -69,7 +68,7 @@
- struct _Z_Hole *holelist;
+ GSList *holelist; /* element-type: Z_Hole* */