From: Vsevolod Stakhov Date: Sat, 24 Sep 2016 12:11:53 +0000 (+0100) Subject: [Minor] Fix build with glib < 2.40 X-Git-Tag: 1.4.0~382 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=215a57a76656098ba81f44d7e7033f4de0badf78;p=rspamd.git [Minor] Fix build with glib < 2.40 --- diff --git a/src/libserver/spf.c b/src/libserver/spf.c index dd7843eae..2459ee7cc 100644 --- a/src/libserver/spf.c +++ b/src/libserver/spf.c @@ -1802,20 +1802,20 @@ spf_dns_callback (struct rdns_reply *reply, gpointer arg) && rec->dns_requests == 0) { resolved = rspamd_spf_new_addr_list (rec, rec->sender_domain); struct spf_addr *addr; - addr = g_slice_alloc0 (sizeof (*addr)); + addr = g_slice_alloc0 (sizeof(*addr)); addr->flags = 0; addr->flags |= RSPAMD_SPF_FLAG_NA; - g_ptr_array_insert(resolved->elts, 0, addr); + g_ptr_array_insert (resolved->elts, 0, addr); } - + if (!spf_process_txt_record (rec, resolved, reply)) { if (rec->dns_requests == 0) { - resolved = g_ptr_array_index (rec->resolved, 0); + resolved = g_ptr_array_index(rec->resolved, 0); struct spf_addr *addr; - addr = g_slice_alloc0 (sizeof (*addr)); + addr = g_slice_alloc0 (sizeof(*addr)); addr->flags = 0; addr->flags |= RSPAMD_SPF_FLAG_NA; - g_ptr_array_insert(resolved->elts, 0, addr); + g_ptr_array_insert (resolved->elts, 0, addr); } } diff --git a/src/libutil/util.c b/src/libutil/util.c index 7e7614005..9ca5bbce8 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1424,6 +1424,29 @@ g_queue_free_full (GQueue *queue, GDestroyNotify free_func) } #endif +#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40)) +void +g_ptr_array_insert (GPtrArray *array, gint index_, gpointer data) +{ + g_return_if_fail (array); + g_return_if_fail (index_ >= -1); + g_return_if_fail (index_ <= (gint )array->len); + + g_ptr_array_set_size (array, array->len + 1); + + if (index_ < 0) { + index_ = array->len; + } + + if (index_ < array->len) { + memmove (&(array->pdata[index_ + 1]), &(array->pdata[index_]), + (array->len - index_) * sizeof(gpointer)); + } + + array->pdata[index_] = data; +} +#endif + gint rspamd_fallocate (gint fd, off_t offset, off_t len) { diff --git a/src/libutil/util.h b/src/libutil/util.h index 564d00b12..946d9f09a 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -186,6 +186,9 @@ void g_queue_clear (GQueue *queue); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32)) void g_queue_free_full (GQueue *queue, GDestroyNotify free_func); #endif +#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40)) +void g_ptr_array_insert (GPtrArray *array, gint index_, gpointer data) +#endif /* * Convert milliseconds to timeval fields