[balsa] address: Remove libbalsa_address_get_addr_list()
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] address: Remove libbalsa_address_get_addr_list()
- Date: Mon, 24 Jun 2019 14:11:45 +0000 (UTC)
commit 7d5c5f0882c24c125edabd8b020b8910d263fe3e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon Jun 24 10:10:55 2019 -0400
address: Remove libbalsa_address_get_addr_list()
Second and final step in keeping address->addr_list private.
* libbalsa/address.c (libbalsa_address_get_n_addrs),
(libbalsa_address_get_nth_addr): new functions to provide access
to the addr-list;
* libbalsa/address-book-extern.c
(libbalsa_address_book_externq_add_address):
* libbalsa/address-book-gpe.c (gpe_read_address):
* libbalsa/address-book-ldif.c (lbab_ldif_write_addresses):
* libbalsa/address-book-osmo.c
(libbalsa_address_book_osmo_alias_complete):
* libbalsa/address-book-rubrica.c (lbab_rubrica_load_xml),
(lbab_insert_address_node), (extract_cards), (extract_net):
* libbalsa/address-book-text.c (lbab_text_load_file):
* libbalsa/address-book-vcard.c (lbab_vcard_write_addresses):
* libbalsa/address.h:
* libbalsa/rfc6350.c (rfc6350_parse_from_stream):
* src/ab-main.c (bab_load_cb):
* src/ab-window.c (balsa_ab_window_load_cb): Use them.
ChangeLog | 24 ++++++++++++++++++++++++
libbalsa/address-book-extern.c | 6 +++---
libbalsa/address-book-gpe.c | 15 ++++++++-------
libbalsa/address-book-ldif.c | 8 ++++----
libbalsa/address-book-osmo.c | 13 +++++++------
libbalsa/address-book-rubrica.c | 38 ++++++++++++++++++++++----------------
libbalsa/address-book-text.c | 20 +++++++++++---------
libbalsa/address-book-vcard.c | 11 +++++++----
libbalsa/address.c | 14 +++++++++++---
libbalsa/address.h | 3 ++-
libbalsa/rfc6350.c | 2 +-
src/ab-main.c | 14 ++++++++------
src/ab-window.c | 20 ++++++++++----------
13 files changed, 118 insertions(+), 70 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 46f8a92c3..c5984ad01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2019-06-24 Peter Bloomfield <pbloomfield bellsouth net>
+
+ address: Remove libbalsa_address_get_addr_list()
+
+ Second and final step in keeping address->addr_list private.
+
+ * libbalsa/address.c (libbalsa_address_get_n_addrs),
+ (libbalsa_address_get_nth_addr): new functions to provide access
+ to the addr-list;
+ * libbalsa/address-book-extern.c
+ (libbalsa_address_book_externq_add_address):
+ * libbalsa/address-book-gpe.c (gpe_read_address):
+ * libbalsa/address-book-ldif.c (lbab_ldif_write_addresses):
+ * libbalsa/address-book-osmo.c
+ (libbalsa_address_book_osmo_alias_complete):
+ * libbalsa/address-book-rubrica.c (lbab_rubrica_load_xml),
+ (lbab_insert_address_node), (extract_cards), (extract_net):
+ * libbalsa/address-book-text.c (lbab_text_load_file):
+ * libbalsa/address-book-vcard.c (lbab_vcard_write_addresses):
+ * libbalsa/address.h:
+ * libbalsa/rfc6350.c (rfc6350_parse_from_stream):
+ * src/ab-main.c (bab_load_cb):
+ * src/ab-window.c (balsa_ab_window_load_cb): Use them.
+
2019-06-23 Peter Bloomfield <pbloomfield bellsouth net>
address: Remove libbalsa_address_set_addr_list()
diff --git a/libbalsa/address-book-extern.c b/libbalsa/address-book-extern.c
index 47bcd82ef..ef33c2701 100644
--- a/libbalsa/address-book-extern.c
+++ b/libbalsa/address-book-extern.c
@@ -276,15 +276,15 @@ libbalsa_address_book_externq_add_address(LibBalsaAddressBook * ab,
ab_externq = LIBBALSA_ADDRESS_BOOK_EXTERNQ(ab);
if (ab_externq->save != NULL) {
- GList *addr_list;
+ const gchar *addr;
const gchar *full_name;
- addr_list = libbalsa_address_get_addr_list(new_address);
+ addr = libbalsa_address_get_addr(new_address);
full_name = libbalsa_address_get_full_name(new_address);
g_snprintf(command, sizeof(command), "%s \"%s\" \"%s\" \"%s\"",
ab_externq->save,
- (gchar *) addr_list->data,
+ addr,
full_name, "TODO");
if ((gc = popen(command, "r")) == NULL)
return LBABERR_CANNOT_WRITE;
diff --git a/libbalsa/address-book-gpe.c b/libbalsa/address-book-gpe.c
index a0227a5b9..a73feecb3 100644
--- a/libbalsa/address-book-gpe.c
+++ b/libbalsa/address-book-gpe.c
@@ -299,7 +299,7 @@ gpe_read_address(void *arg, int argc, char **argv, char **names)
gpe_read_attr, address, NULL, uid);
#endif /* HAVE_SQLITE3 */
- if (libbalsa_address_get_addr_list(address) == NULL) {
+ if (libbalsa_address_get_addr(address) == NULL) {
/* entry without address: ignore! */
g_object_unref(address);
return 0;
@@ -728,9 +728,9 @@ gpe_read_completion(void *arg, int argc, char **argv, char **names)
struct gpe_completion_closure *gc = arg;
LibBalsaAddress *address = libbalsa_address_new();
InternetAddress *ia;
- GList *addr_list;
- GList *l;
guint uid = atoi(argv[0]);
+ guint n_addrs;
+ guint n;
#ifdef HAVE_SQLITE3
gchar *sql;
@@ -747,8 +747,8 @@ gpe_read_completion(void *arg, int argc, char **argv, char **names)
gpe_read_attr, address, NULL, uid);
#endif /* HAVE_SQLITE3 */
- addr_list = libbalsa_address_get_addr_list(address);
- if (addr_list == NULL) {
+ n_addrs = libbalsa_address_get_n_addrs(address);
+ if (n_addrs == 0) {
/* entry without address: ignore! */
g_object_unref(address);
return 0;
@@ -766,9 +766,10 @@ gpe_read_completion(void *arg, int argc, char **argv, char **names)
g_free(full_name);
}
- for (l = addr_list; l != NULL; l = l->next) {
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
const gchar *full_name = libbalsa_address_get_full_name(address);
- ia = internet_address_mailbox_new(full_name, (gchar *) l->data);
+ ia = internet_address_mailbox_new(full_name, addr);
gc->res = g_list_prepend(gc->res, ia);
}
diff --git a/libbalsa/address-book-ldif.c b/libbalsa/address-book-ldif.c
index 28ca8f453..cdf1639a4 100644
--- a/libbalsa/address-book-ldif.c
+++ b/libbalsa/address-book-ldif.c
@@ -299,11 +299,11 @@ lbab_ldif_write_dn(FILE * stream, LibBalsaAddress * address)
static void
lbab_ldif_write_addresses(FILE * stream, LibBalsaAddress * address)
{
- GList *list;
+ guint n_addrs, n;
- for (list = libbalsa_address_get_addr_list(address);
- list != NULL; list = list->next) {
- const gchar *mail = list->data;
+ n_addrs = libbalsa_address_get_n_addrs(address);
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *mail = libbalsa_address_get_nth_addr(address, n);
if (mail != NULL && mail[0] != '\0') {
gchar *value_spec = string_to_value_spec(mail);
diff --git a/libbalsa/address-book-osmo.c b/libbalsa/address-book-osmo.c
index 5c79399a1..a20e39291 100644
--- a/libbalsa/address-book-osmo.c
+++ b/libbalsa/address-book-osmo.c
@@ -246,20 +246,21 @@ libbalsa_address_book_osmo_alias_complete(LibBalsaAddressBook *ab,
utf8_filter = g_utf8_casefold(prefix, -1);
for (p = addresses; p != NULL; p = p->next) {
LibBalsaAddress *this_addr = LIBBALSA_ADDRESS(p->data);
- GList *this_mail;
gboolean names_match;
+ guint n_addrs;
+ guint n;
names_match = utf8_lba_strstr(this_addr, utf8_filter);
- for (this_mail = libbalsa_address_get_addr_list(this_addr);
- this_mail != NULL; this_mail = this_mail->next) {
- const gchar *mail_addr = (gchar *) this_mail->data;
+ n_addrs = libbalsa_address_get_n_addrs(this_addr);
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *mail_addr =
+ libbalsa_address_get_nth_addr(this_addr, n);
if (names_match || (strstr(mail_addr, prefix) != NULL)) {
const gchar *full_name;
InternetAddress *addr;
- full_name =
- libbalsa_address_get_full_name(this_addr),
+ full_name = libbalsa_address_get_full_name(this_addr);
g_debug("%s: found %s <%s>", __func__,
full_name, mail_addr);
addr = internet_address_mailbox_new(full_name,
diff --git a/libbalsa/address-book-rubrica.c b/libbalsa/address-book-rubrica.c
index ebb1962bc..d94a0a0e3 100644
--- a/libbalsa/address-book-rubrica.c
+++ b/libbalsa/address-book-rubrica.c
@@ -77,7 +77,7 @@ static GSList *extract_cards(xmlNodePtr card);
static void extract_data(xmlNodePtr entry, gchar ** first_name,
gchar ** last_name, gchar ** nick_name);
static void extract_work(xmlNodePtr entry, gchar ** org);
-static gint extract_net(xmlNodePtr entry, LibBalsaAddress *address);
+static guint extract_net(xmlNodePtr entry, LibBalsaAddress *address);
static gchar *xml_node_get_attr(xmlNodePtr node, const xmlChar * attname);
static gchar *xml_node_get_text(xmlNodePtr node);
@@ -452,23 +452,24 @@ lbab_rubrica_load_xml(LibBalsaAddressBookRubrica * ab_rubrica,
completion_list = NULL;
for (list = libbalsa_address_book_text_get_item_list(ab_text); list != NULL; list = list->next) {
LibBalsaAddress *address = LIBBALSA_ADDRESS(list->data);
- GList *addr_list;
+ guint n_addrs;
if (address == NULL)
continue;
- addr_list = libbalsa_address_get_addr_list(address);
+ n_addrs = libbalsa_address_get_n_addrs(address);
if (libbalsa_address_book_get_dist_list_mode(ab)
- && addr_list != NULL && addr_list->next != NULL) {
+ && n_addrs > 1) {
/* Create a group address. */
- GList *l;
InternetAddress *ia =
internet_address_group_new(libbalsa_address_get_full_name(address));
InternetAddressGroup *group = (InternetAddressGroup *) ia;
+ guint n;
- for (l = addr_list; l != NULL; l = l->next) {
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
InternetAddress *member =
- internet_address_mailbox_new(NULL, l->data);
+ internet_address_mailbox_new(NULL, addr);
internet_address_group_add_member(group, member);
g_object_unref(member);
}
@@ -477,11 +478,12 @@ lbab_rubrica_load_xml(LibBalsaAddressBookRubrica * ab_rubrica,
g_object_unref(ia);
} else {
/* Create name addresses. */
- GList *l;
+ guint n;
- for (l = addr_list; l != NULL; l = l->next) {
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
InternetAddress *ia =
- internet_address_mailbox_new(libbalsa_address_get_full_name(address), l->data);
+ internet_address_mailbox_new(libbalsa_address_get_full_name(address), addr);
cmp_data = completion_data_new(ia, libbalsa_address_get_nick_name(address));
completion_list =
g_list_prepend(completion_list, cmp_data);
@@ -504,7 +506,8 @@ lbab_insert_address_node(LibBalsaAddress * address,
{
xmlNodePtr new_addr;
xmlNodePtr new_data;
- GList *l;
+ guint n_addrs;
+ guint n;
/* create a new card */
new_addr = xmlNewChild(parent, NULL, CXMLCHARP("Card"), NULL);
@@ -526,10 +529,13 @@ lbab_insert_address_node(LibBalsaAddress * address,
/* create the Net section of the card */
new_data = xmlNewChild(new_addr, NULL, CXMLCHARP("Net"), NULL);
- for (l = libbalsa_address_get_addr_list(address); l != NULL; l = l->next) {
+
+ n_addrs = libbalsa_address_get_n_addrs(address);
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
xmlNodePtr new_mail =
xmlNewChild(new_data, NULL, CXMLCHARP("Uri"),
- CXMLCHARP(l->data));
+ CXMLCHARP(addr));
xmlNewProp(new_mail, CXMLCHARP("type"), CXMLCHARP("email"));
}
}
@@ -563,7 +569,7 @@ extract_cards(xmlNodePtr card)
LibBalsaAddress *address = libbalsa_address_new();
xmlNodePtr children;
gchar *full_name;
- gint n_addrs = 0;
+ guint n_addrs = 0;
full_name = xml_node_get_attr(card, CXMLCHARP("name"));
libbalsa_address_set_full_name(address, full_name);
@@ -688,10 +694,10 @@ extract_work(xmlNodePtr entry, gchar ** org)
}
-static gint
+static guint
extract_net(xmlNodePtr entry, LibBalsaAddress *address)
{
- gint n_addrs = 0;
+ guint n_addrs = 0;
while (entry) {
gchar *uri_type = NULL;
diff --git a/libbalsa/address-book-text.c b/libbalsa/address-book-text.c
index 07045b56a..93fce05e5 100644
--- a/libbalsa/address-book-text.c
+++ b/libbalsa/address-book-text.c
@@ -332,22 +332,23 @@ lbab_text_load_file(LibBalsaAddressBookText * ab_text, FILE * stream)
#if MAKE_GROUP_BY_ORGANIZATION
gchar **groups, **group;
#endif /* MAKE_GROUP_BY_ORGANIZATION */
- GList *addr_list;
+ guint n_addrs;
if (address == NULL)
continue;
- addr_list = libbalsa_address_get_addr_list(address);
+ n_addrs = libbalsa_address_get_n_addrs(address);
if (libbalsa_address_book_get_dist_list_mode(ab)
- && addr_list != NULL && addr_list->next != NULL) {
+ && n_addrs > 1) {
/* Create a group address. */
InternetAddress *ia =
internet_address_group_new(libbalsa_address_get_full_name(address));
- GList *l;
+ guint n;
- for (l = addr_list; l != NULL; l = l->next) {
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
InternetAddress *member =
- internet_address_mailbox_new(NULL, l->data);
+ internet_address_mailbox_new(NULL, addr);
internet_address_group_add_member((InternetAddressGroup *)ia, member);
g_object_unref(member);
}
@@ -356,12 +357,13 @@ lbab_text_load_file(LibBalsaAddressBookText * ab_text, FILE * stream)
g_object_unref(ia);
} else {
/* Create name addresses. */
- GList *l;
+ guint n;
- for (l = addr_list; l != NULL; l = l->next) {
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
InternetAddress *ia =
internet_address_mailbox_new(libbalsa_address_get_full_name(address),
- l->data);
+ addr);
cmp_data =
completion_data_new(ia, libbalsa_address_get_nick_name(address));
completion_list =
diff --git a/libbalsa/address-book-vcard.c b/libbalsa/address-book-vcard.c
index c14b8fadf..1b9750628 100644
--- a/libbalsa/address-book-vcard.c
+++ b/libbalsa/address-book-vcard.c
@@ -164,11 +164,14 @@ lbab_vcard_write_org(FILE * stream, LibBalsaAddress * address)
static void
lbab_vcard_write_addresses(FILE * stream, LibBalsaAddress * address)
{
- GList *list;
+ guint n_addrs;
+ guint n;
- for (list = libbalsa_address_get_addr_list(address);
- list != NULL; list = list->next)
- fprintf(stream, "EMAIL;INTERNET:%s\n", (gchar *) list->data);
+ n_addrs = libbalsa_address_get_n_addrs(address);
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
+ fprintf(stream, "EMAIL;INTERNET:%s\n", addr);
+ }
}
static void
diff --git a/libbalsa/address.c b/libbalsa/address.c
index 9439c2001..a2669a9f4 100644
--- a/libbalsa/address.c
+++ b/libbalsa/address.c
@@ -1173,12 +1173,20 @@ libbalsa_address_get_addr(LibBalsaAddress * address)
return address->addr_list != NULL ? address->addr_list->data : NULL;
}
-GList *
-libbalsa_address_get_addr_list(LibBalsaAddress * address)
+guint
+libbalsa_address_get_n_addrs(LibBalsaAddress * address)
+{
+ g_return_val_if_fail(LIBBALSA_IS_ADDRESS(address), 0U);
+
+ return g_list_length(address->addr_list);
+}
+
+const gchar *
+libbalsa_address_get_nth_addr(LibBalsaAddress * address, guint n)
{
g_return_val_if_fail(LIBBALSA_IS_ADDRESS(address), NULL);
- return address->addr_list;
+ return (const gchar *) g_list_nth_data(address->addr_list, n);
}
/*
diff --git a/libbalsa/address.h b/libbalsa/address.h
index 5f3729299..b93528958 100644
--- a/libbalsa/address.h
+++ b/libbalsa/address.h
@@ -101,7 +101,8 @@ const gchar * libbalsa_address_get_last_name (LibBalsaAddress * address);
const gchar * libbalsa_address_get_nick_name (LibBalsaAddress * address);
const gchar * libbalsa_address_get_organization(LibBalsaAddress * address);
const gchar * libbalsa_address_get_addr (LibBalsaAddress * address);
-GList * libbalsa_address_get_addr_list (LibBalsaAddress * address);
+guint libbalsa_address_get_n_addrs (LibBalsaAddress * address);
+const gchar * libbalsa_address_get_nth_addr (LibBalsaAddress * address, guint n);
/*
* Setters
diff --git a/libbalsa/rfc6350.c b/libbalsa/rfc6350.c
index c2d07546a..5965bb76a 100644
--- a/libbalsa/rfc6350.c
+++ b/libbalsa/rfc6350.c
@@ -105,7 +105,7 @@ rfc6350_parse_from_stream(GDataInputStream *stream,
/* ignore items without an Email address, fill empty full name if necessary */
if (result != NULL) {
- if (libbalsa_address_get_addr_list(result) == NULL) {
+ if (libbalsa_address_get_addr(result) == NULL) {
g_object_unref(result);
result = NULL;
} else if (libbalsa_address_get_full_name(result) == NULL) {
diff --git a/src/ab-main.c b/src/ab-main.c
index 9fd8053f5..63b3d0aea 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -122,16 +122,16 @@ bab_load_cb(LibBalsaAddressBook *libbalsa_ab,
LibBalsaAddress *address, GtkTreeModel *model)
{
GtkTreeIter iter;
- GList *addr_list;
+ guint n_addrs;
g_return_if_fail(LIBBALSA_IS_ADDRESS_BOOK(libbalsa_ab));
if (address == NULL)
return;
- addr_list = libbalsa_address_get_addr_list(address);
+ n_addrs = libbalsa_address_get_n_addrs(address);
if (libbalsa_address_book_get_dist_list_mode(libbalsa_ab)
- && addr_list != NULL && addr_list->next != NULL) {
+ && n_addrs > 1) {
gchar *address_string = libbalsa_address_to_gchar(address, -1);
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
@@ -144,16 +144,18 @@ bab_load_cb(LibBalsaAddressBook *libbalsa_ab,
g_free(address_string);
} else {
- GList *l;
+ guint n;
+
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
- for (l = addr_list; l != NULL; l = l->next) {
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
/* GtkListStore refs address once for each address in
* the list, and unrefs it the same number of times when
* cleared */
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
LIST_COLUMN_NAME, libbalsa_address_get_full_name(address),
- LIST_COLUMN_ADDRSPEC, l->data,
+ LIST_COLUMN_ADDRSPEC, addr,
LIST_COLUMN_ADDRESS, address,
-1);
}
diff --git a/src/ab-window.c b/src/ab-window.c
index 36fb3531f..6852a0bbb 100644
--- a/src/ab-window.c
+++ b/src/ab-window.c
@@ -751,8 +751,7 @@ balsa_ab_window_load_cb(LibBalsaAddressBook *libbalsa_ab,
{
GtkTreeModel *model;
GtkTreeIter iter;
- GList *addr_list;
- gint count;
+ guint n_addrs;
const gchar *full_name;
g_return_if_fail(BALSA_IS_AB_WINDOW(ab));
@@ -764,9 +763,9 @@ balsa_ab_window_load_cb(LibBalsaAddressBook *libbalsa_ab,
full_name = libbalsa_address_get_full_name(address);
model = gtk_tree_view_get_model(GTK_TREE_VIEW(ab->address_list));
- addr_list = libbalsa_address_get_addr_list(address);
+ n_addrs = libbalsa_address_get_n_addrs(address);
if (libbalsa_address_book_get_dist_list_mode(libbalsa_ab)
- && addr_list != NULL && addr_list->next != NULL) {
+ && n_addrs > 1) {
gchar *address_string = libbalsa_address_to_gchar(address, -1);
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
@@ -780,19 +779,20 @@ balsa_ab_window_load_cb(LibBalsaAddressBook *libbalsa_ab,
g_free(address_string);
} else {
- for (count = 0, addr_list = libbalsa_address_get_addr_list(address);
- addr_list != NULL;
- ++count, addr_list = addr_list->next) {
+ guint n;
+
+ for (n = 0; n < n_addrs; ++n) {
+ const gchar *addr = libbalsa_address_get_nth_addr(address, n);
+
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
/* GtkListStore refs address once for each address in
* the list, and unrefs it the same number of times when
* cleared */
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
LIST_COLUMN_NAME, full_name,
- LIST_COLUMN_ADDRESS_STRING,
- addr_list->data,
+ LIST_COLUMN_ADDRESS_STRING, addr,
LIST_COLUMN_ADDRESS, address,
- LIST_COLUMN_WHICH, count,
+ LIST_COLUMN_WHICH, n,
-1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]