MuContacts* mu_contacts_new (const gchar *path) { MuContacts *self; g_return_val_if_fail (path, NULL); self = g_new0 (MuContacts, 1); self->_path = g_strdup (path); self->_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)contact_info_destroy); self->_ccache = load_key_file (path); if (!self->_ccache || !set_comment (self->_ccache)) { mu_contacts_destroy (self); return NULL; } deserialize_cache (self); MU_WRITE_LOG("deserialized contacts from cache %s", path); self->_dirty = FALSE; return self; }
static MuError cmd_contacts (ServerContext *ctx, GSList *args, GError **err) { MuContacts *contacts; char *sexp; gboolean personal; time_t after; const char *str; personal = get_bool_from_args (args, "personal", TRUE, NULL); str = get_string_from_args (args, "after", TRUE, NULL); after = str ? (time_t)atoi(str) : 0; contacts = mu_contacts_new (mu_runtime_path (MU_RUNTIME_PATH_CONTACTS)); if (!contacts) { print_error (MU_ERROR_INTERNAL, "failed to open contacts cache"); return MU_OK; } /* dump the contacts cache as a giant sexp */ sexp = contacts_to_sexp (contacts, personal, after); print_expr ("%s\n", sexp); g_free (sexp); mu_contacts_destroy (contacts); return MU_OK; }
static MuError run_cmd_cfind (const char* pattern, MuConfigFormat format, gboolean color, GError **err) { gboolean rv; MuContacts *contacts; size_t num; ECData ecdata; ecdata.format = format; ecdata.color = color; contacts = mu_contacts_new (mu_runtime_path(MU_RUNTIME_PATH_CONTACTS)); if (!contacts) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_CONTACTS_CANNOT_RETRIEVE, "could not retrieve contacts"); return MU_ERROR_CONTACTS_CANNOT_RETRIEVE; } print_header (format); rv = mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact, &ecdata, pattern, &num); mu_contacts_destroy (contacts); if (num == 0) { g_warning ("no matching contacts found"); return MU_ERROR_NO_MATCHES; } return rv ? MU_OK : MU_ERROR_CONTACTS; }