Commit 1609f699 authored by Chris Toshok's avatar Chris Toshok Committed by Chris Toshok

initial addition of s/mime foo.

2003-10-23  Chris Toshok  <toshok@ximian.com>

	* lib/e-cert.[ch], lib/Makefile.am, gui/certificate-manager.[ch],
	gui/Makefile.am, gui/smime-ui.glade, Makefile.am: initial addition
	of s/mime foo.

svn path=/trunk/; revision=23042
parent eca844b0
Makefile
Makefile.in
2003-10-23 Chris Toshok <toshok@ximian.com>
* lib/e-cert.[ch], lib/Makefile.am, gui/certificate-manager.[ch],
gui/Makefile.am, gui/smime-ui.glade, Makefile.am: initial addition
of s/mime foo.
SUBDIRS= lib gui
\ No newline at end of file
Makefile
Makefile.in
INCLUDES = \
-DG_LOG_DOMAIN=\"evolution-smime\" \
-I$(top_srcdir) \
-I$(top_srcdir)/smime/lib \
-I$(top_srcdir)/shell \
-I$(top_builddir) \
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
-DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \
-DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \
-DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
-DEVOLUTION_UIDIR=\""$(evolutionuidir)"\" \
-DPREFIX=\""$(prefix)"\" \
-DG_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
-DLIBGNOME_DISABLE_DEPRECATED \
-DLIBGNOMEUI_DISABLE_DEPRECATED \
$(EVOLUTION_ADDRESSBOOK_CFLAGS) \
$(CAMEL_CFLAGS)
noinst_LTLIBRARIES = libevolution-smime.la
libevolution_smime_la_SOURCES = \
certificate-manager.c
libevolution_smime_la_LIBADD = \
$(top_builddir)/smime/lib/libessmime.la \
$(EVOLUTION_ADDRESSBOOK_LIBS) $(CAMEL_LIBS)
glade_DATA = smime-ui.glade
EXTRA_DIST = \
$(glade_DATA)
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors: Chris Toshok <toshok@ximian.com>
*
* Copyright (C) 2003 Ximian, Inc. (www.ximian.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*
*/
#define GLADE_FILE_NAME "smime-ui.glade"
#include <gtk/gtkcontainer.h>
#include <gtk/gtktreeview.h>
#include <gtk/gtktreestore.h>
#include <gtk/gtktreemodelsort.h>
#include <gtk/gtkcellrenderertext.h>
#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>
#include "evolution-config-control.h"
#include "certificate-manager.h"
#include "e-cert.h"
#include "nss.h"
#include <cms.h>
#include <cert.h>
#include <certdb.h>
#include <pkcs11.h>
#include <pk11func.h>
typedef struct {
GladeXML *gui;
GtkWidget *yourcerts_treeview;
GtkTreeStore *yourcerts_treemodel;
GHashTable *yourcerts_root_hash;
GtkWidget *contactcerts_treeview;
GtkTreeStore *contactcerts_treemodel;
GHashTable *contactcerts_root_hash;
GtkWidget *authoritycerts_treeview;
GtkTreeStore *authoritycerts_treemodel;
GHashTable *authoritycerts_root_hash;
} CertificateManagerData;
typedef enum {
USER_CERT,
CONTACT_CERT,
CA_CERT
} CertType;
static void
initialize_yourcerts_ui (CertificateManagerData *cfm)
{
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->yourcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Certificate Name"),
cell,
"text", 0,
NULL));
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->yourcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Purposes"),
cell,
"text", 1,
NULL));
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->yourcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Serial Number"),
cell,
"text", 2,
NULL));
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->yourcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Expires"),
cell,
"text", 3,
NULL));
cfm->yourcerts_treemodel = gtk_tree_store_new (4,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (cfm->yourcerts_treeview),
GTK_TREE_MODEL (cfm->yourcerts_treemodel));
cfm->yourcerts_root_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static void
initialize_contactcerts_ui (CertificateManagerData *cfm)
{
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->contactcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Certificate Name"),
cell,
"text", 0,
NULL));
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->contactcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("E-Mail Address"),
cell,
"text", 1,
NULL));
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->contactcerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Purposes"),
cell,
"text", 2,
NULL));
cfm->contactcerts_treemodel = gtk_tree_store_new (3,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (cfm->contactcerts_treeview),
GTK_TREE_MODEL (cfm->contactcerts_treemodel));
cfm->contactcerts_root_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static gint
iter_string_compare (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
char *string1, *string2;
gtk_tree_model_get (model, a,
0, &string1,
-1);
gtk_tree_model_get (model, b,
0, &string2,
-1);
return g_utf8_collate (string1, string2);
}
static void
initialize_authoritycerts_ui (CertificateManagerData *cfm)
{
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
gtk_tree_view_append_column (GTK_TREE_VIEW (cfm->authoritycerts_treeview),
gtk_tree_view_column_new_with_attributes (_("Certificate Name"),
cell,
"text", 0,
NULL));
cfm->authoritycerts_treemodel = gtk_tree_store_new (1,
G_TYPE_STRING);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (cfm->authoritycerts_treemodel),
0,
iter_string_compare, NULL, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (cfm->authoritycerts_treemodel),
0,
GTK_SORT_ASCENDING);
gtk_tree_view_set_model (GTK_TREE_VIEW (cfm->authoritycerts_treeview),
GTK_TREE_MODEL (cfm->authoritycerts_treemodel));
cfm->authoritycerts_root_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static CertType
get_cert_type (ECert *cert)
{
const char *nick = e_cert_get_nickname (cert);
const char *email = e_cert_get_email (cert);
if (e_cert_is_ca_cert (cert))
return CA_CERT;
/* XXX more stuff in here */
else
return USER_CERT;
}
typedef void (*AddCertCb)(CertificateManagerData *cfm, ECert *cert);
static void
add_user_cert (CertificateManagerData *cfm, ECert *cert)
{
GtkTreeIter iter;
GtkTreeIter *parent_iter = NULL;
const char *organization = e_cert_get_org (cert);
const char *common_name;
if (organization) {
parent_iter = g_hash_table_lookup (cfm->yourcerts_root_hash, organization);
if (!parent_iter) {
/* create a new toplevel node */
gtk_tree_store_append (GTK_TREE_STORE (cfm->yourcerts_treemodel), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (cfm->yourcerts_treemodel), &iter,
0, organization, -1);
/* now copy it off into parent_iter and insert it into
the hashtable */
parent_iter = gtk_tree_iter_copy (&iter);
g_hash_table_insert (cfm->yourcerts_root_hash, g_strdup (organization), parent_iter);
}
}
gtk_tree_store_append (GTK_TREE_STORE (cfm->yourcerts_treemodel), &iter, parent_iter);
common_name = e_cert_get_cn (cert);
if (common_name) {
gtk_tree_store_set (GTK_TREE_STORE (cfm->yourcerts_treemodel), &iter,
0, common_name, -1);
}
else
gtk_tree_store_set (GTK_TREE_STORE (cfm->yourcerts_treemodel), &iter,
0, e_cert_get_nickname (cert), -1);
}
static void
add_contact_cert (CertificateManagerData *cfm, ECert *cert)
{
/* nothing yet */
}
static void
add_ca_cert (CertificateManagerData *cfm, ECert *cert)
{
GtkTreeIter iter;
GtkTreeIter *parent_iter = NULL;
const char *organization = e_cert_get_org (cert);
const char *common_name;
if (organization) {
parent_iter = g_hash_table_lookup (cfm->authoritycerts_root_hash, organization);
if (!parent_iter) {
/* create a new toplevel node */
gtk_tree_store_append (GTK_TREE_STORE (cfm->authoritycerts_treemodel), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (cfm->authoritycerts_treemodel), &iter,
0, organization, -1);
/* now copy it off into parent_iter and insert it into
the hashtable */
parent_iter = gtk_tree_iter_copy (&iter);
g_hash_table_insert (cfm->authoritycerts_root_hash, g_strdup (organization), parent_iter);
}
}
gtk_tree_store_append (GTK_TREE_STORE (cfm->authoritycerts_treemodel), &iter, parent_iter);
common_name = e_cert_get_cn (cert);
if (common_name) {
gtk_tree_store_set (GTK_TREE_STORE (cfm->authoritycerts_treemodel), &iter,
0, common_name, -1);
}
else
gtk_tree_store_set (GTK_TREE_STORE (cfm->authoritycerts_treemodel), &iter,
0, e_cert_get_nickname (cert), -1);
}
static void
load_certs (CertificateManagerData *cfm,
CertType type,
AddCertCb add_cert)
{
CERTCertList *certList;
CERTCertListNode *node;
certList = PK11_ListCerts (PK11CertListUnique, NULL);
printf ("certList = %p\n", certList);
for (node = CERT_LIST_HEAD(certList);
!CERT_LIST_END(node, certList);
node = CERT_LIST_NEXT(node)) {
ECert *cert = e_cert_new ((CERTCertificate*)node->cert);
if (get_cert_type(cert) == type) {
printf ("cert (nickname = '%s') matches\n", e_cert_get_nickname (cert));
add_cert (cfm, cert);
}
/* XXX we leak cert */
}
}
static void
populate_ui (CertificateManagerData *cfm)
{
load_certs (cfm, USER_CERT, add_user_cert);
load_certs (cfm, CONTACT_CERT, add_contact_cert);
load_certs (cfm, CA_CERT, add_ca_cert);
}
EvolutionConfigControl*
certificate_manager_config_control_new (void)
{
CertificateManagerData *cfm_data = g_new0 (CertificateManagerData, 1);
GtkWidget *control_widget;
/* XXX this should happen someplace else, and shouldn't
reference my default mozilla profile :) */
NSS_InitReadWrite ("/home/toshok/.mozilla/default/xuvq7jx3.slt");
cfm_data->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, NULL, NULL);
cfm_data->yourcerts_treeview = glade_xml_get_widget (cfm_data->gui, "yourcerts-treeview");
cfm_data->contactcerts_treeview = glade_xml_get_widget (cfm_data->gui, "contactcerts-treeview");
cfm_data->authoritycerts_treeview = glade_xml_get_widget (cfm_data->gui, "authoritycerts-treeview");
initialize_yourcerts_ui(cfm_data);
initialize_contactcerts_ui(cfm_data);
initialize_authoritycerts_ui(cfm_data);
populate_ui (cfm_data);
control_widget = glade_xml_get_widget (cfm_data->gui, "cert-manager-notebook");
gtk_widget_ref (control_widget);
gtk_container_remove (GTK_CONTAINER (control_widget->parent), control_widget);
return evolution_config_control_new (control_widget);
}
#ifndef _CERTIFICATE_MANAGER_H_
#define _CERTIFICATE_MANAGER_H
#include "evolution-config-control.h"
EvolutionConfigControl* certificate_manager_config_control_new (void);
#endif /* _CERTIFICATE_MANAGER_H_ */
This diff is collapsed.
Makefile
Makefile.in
*.la
INCLUDES = \
-DG_LOG_DOMAIN=\"evolution-smime\" \
-I$(top_srcdir) \
-I$(top_srcdir)/shell \
-I$(top_builddir) \
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
-DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \
-DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \
-DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
-DEVOLUTION_UIDIR=\""$(evolutionuidir)"\" \
-DPREFIX=\""$(prefix)"\" \
-DG_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
-DLIBGNOME_DISABLE_DEPRECATED \
-DLIBGNOMEUI_DISABLE_DEPRECATED \
$(EVOLUTION_ADDRESSBOOK_CFLAGS) \
$(CAMEL_CFLAGS)
noinst_LTLIBRARIES = libessmime.la
libessmime_la_SOURCES = \
e-cert.c \
e-cert.h
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* e-cert.c
*
* Copyright (C) 2003 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Chris Toshok (toshok@ximian.com)
*/
#include "e-cert.h"
struct _ECertPrivate {
CERTCertificate *cert;
char *org_name;
char *cn;
};
#define PARENT_TYPE G_TYPE_OBJECT
static GObjectClass *parent_class;
static void
e_cert_dispose (GObject *object)
{
ECert *ec = E_CERT (object);
if (!ec->priv)
return;
if (ec->priv->org_name)
PORT_Free (ec->priv->org_name);
if (ec->priv->cn)
PORT_Free (ec->priv->org_name);
g_free (ec->priv);
ec->priv = NULL;
if (G_OBJECT_CLASS (parent_class)->dispose)
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
e_cert_class_init (ECertClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_ref (PARENT_TYPE);
object_class->dispose = e_cert_dispose;
}
static void
e_cert_init (ECert *ec)
{
ec->priv = g_new0 (ECertPrivate, 1);
}
GType
e_cert_get_type (void)
{
static GType cert_type = 0;
if (!cert_type) {
static const GTypeInfo cert_info = {
sizeof (ECertClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) e_cert_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ECert),
0, /* n_preallocs */
(GInstanceInitFunc) e_cert_init,
};
cert_type = g_type_register_static (PARENT_TYPE, "ECert", &cert_info, 0);
}
return cert_type;
}
static void
e_cert_populate (ECert *cert)
{
CERTCertificate *c = cert->priv->cert;
cert->priv->org_name = CERT_GetOrgName (&c->subject);
cert->priv->cn = CERT_GetCommonName (&c->subject);
}
ECert*
e_cert_new (CERTCertificate *cert)
{
ECert *ecert = E_CERT (g_object_new (E_TYPE_CERT, NULL));
ecert->priv->cert = cert;
e_cert_populate (ecert);
return ecert;
}
const char*
e_cert_get_nickname (ECert *cert)
{
return cert->priv->cert->nickname;
}
const char*
e_cert_get_email (ECert *cert)
{
}
const char*
e_cert_get_org (ECert *cert)
{
return cert->priv->org_name;
}
const char*
e_cert_get_cn (ECert *cert)
{
return cert->priv->cn;
}
gboolean
e_cert_is_ca_cert (ECert *cert)
{
return CERT_IsCACert (cert->priv->cert, NULL);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors: Chris Toshok <toshok@ximian.com>
*
* Copyright (C) 2003 Ximian, Inc. (www.ximian.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*
*/
#ifndef _E_CERT_H_
#define _E_CERT_H_
#include <glib-object.h>
#include <cert.h>
#define E_TYPE_CERT (e_cert_get_type ())
#define E_CERT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CERT, ECert))
#define E_CERT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_CERT, ECertClass))
#define E_IS_CERT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CERT))
#define E_IS_CERT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CERT))
#define E_CERT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_CERT, ECertClass))
typedef struct _ECert ECert;
typedef struct _ECertClass ECertClass;
typedef struct _ECertPrivate ECertPrivate;
struct _ECert {
GObject parent;
ECertPrivate *priv;
};
struct _ECertClass {
GObjectClass parent_class;
/* Padding for future expansion */
void (*_ecert_reserved0) (void);
void (*_ecert_reserved1) (void);
void (*_ecert_reserved2) (void);
void (*_ecert_reserved3) (void);
void (*_ecert_reserved4) (void);
};
GType e_cert_get_type (void);
ECert* e_cert_new (CERTCertificate *cert);
const char* e_cert_get_nickname (ECert *cert);
const char* e_cert_get_email (ECert *cert);
const char* e_cert_get_org (ECert *cert);
const char* e_cert_get_cn (ECert *cert);
gboolean e_cert_is_ca_cert (ECert *cert);
#endif /* _E_CERT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment