# HG changeset patch # User William Ehlhardt # Date 1186125992 0 # Node ID d224a1e4b919263e0da77357c8e4a1a4348d4682 # Parent 7ccb5ab3e07eba485e5cf859a7c95d1f2e3f442d - x509_nss get_subject_name (x509_common_name) diff -r 7ccb5ab3e07e -r d224a1e4b919 libpurple/plugins/ssl/ssl-nss.c --- a/libpurple/plugins/ssl/ssl-nss.c Fri Aug 03 07:11:06 2007 +0000 +++ b/libpurple/plugins/ssl/ssl-nss.c Fri Aug 03 07:26:32 2007 +0000 @@ -479,7 +479,33 @@ static gchar * x509_common_name (PurpleCertificate *crt) { - return NULL; + CERTCertificate *crt_dat; + char *nss_cn; + gchar *ret_cn; + + g_return_val_if_fail(crt, NULL); + g_return_val_if_fail(crt->scheme == &x509_nss, NULL); + + crt_dat = X509_NSS_DATA(crt); + g_return_val_if_fail(crt_dat, NULL); + + /* Q: + Why get a newly allocated string out of NSS, strdup it, and then + return the new copy? + + A: + The NSS LXR docs state that I should use the NSPR free functions on + the strings that the NSS cert functions return. Since the libpurple + API expects a g_free()-able string, we make our own copy and return + that. + + NSPR is something of a prima donna. */ + + nss_cn = CERT_GetCommonName( &(crt_dat->subject) ); + ret_cn = g_strdup(nss_cn); + PORT_Free(nss_cn); + + return ret_cn; } static gboolean