static UserAttribute *edit_person_attrib_edit(gboolean *error, UserAttribute *attrib) { UserAttribute *retVal = NULL; gchar *sName, *sValue, *sName_, *sValue_; gint index; *error = TRUE; index = gtk_combo_box_get_active(GTK_COMBO_BOX(personEditDlg->entry_atname)); sName_ = (gchar *) ATTRIBUTE[index]; sValue_ = gtk_editable_get_chars(GTK_EDITABLE(personEditDlg->entry_atvalue), 0, -1); sName = mgu_email_check_empty(sName_); sValue = mgu_email_check_empty(sValue_); g_free(sValue_); if (sName && sValue) { if (attrib == NULL) { attrib = addritem_create_attribute(); } addritem_attrib_set_name(attrib, sName); addritem_attrib_set_value(attrib, sValue); retVal = attrib; *error = FALSE; } else { edit_person_status_show(N_( "A Name and Value must be supplied." )); gtk_widget_grab_focus(personEditDlg->entry_atvalue); } g_free(sName); g_free(sValue); return retVal; }
/** * Process a single search entry. * \param cache Address cache to load. * \param qry Query object to process. * \param ld LDAP handle. * \param e LDAP message. * \return List of EMail objects found. */ static GList *ldapqry_process_single_entry( AddressCache *cache, LdapQuery *qry, LDAP *ld, LDAPMessage *e ) { char *dnEntry; char *attribute; LdapControl *ctl; BerElement *ber; GSList *listName = NULL, *listAddress = NULL; GSList *listFirst = NULL, *listLast = NULL; GSList *listDisplay = NULL; GSList *other_attrs = NULL; GList *listReturn; listReturn = NULL; ctl = qry->control; dnEntry = ldap_get_dn( ld, e ); debug_print( "DN: %s\n", dnEntry?dnEntry:"null" ); /* Process all attributes */ for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL; attribute = ldap_next_attribute( ld, e, ber ) ) { if( strcasecmp( attribute, ctl->attribEMail ) == 0 ) { listAddress = ldapqry_add_list_values( ld, e, attribute ); } else if( strcasecmp( attribute, ctl->attribCName ) == 0 ) { listName = ldapqry_add_list_values( ld, e, attribute ); } else if( strcasecmp( attribute, ctl->attribFName ) == 0 ) { listFirst = ldapqry_add_list_values( ld, e, attribute ); } else if( strcasecmp( attribute, ctl->attribLName ) == 0 ) { listLast = ldapqry_add_single_value( ld, e, attribute ); } else if( strcasecmp( attribute, ctl->attribDName ) == 0 ) { listDisplay = ldapqry_add_single_value( ld, e, attribute ); } else { GSList *attlist = ldapqry_add_single_value( ld, e, attribute ); UserAttribute *attrib = addritem_create_attribute(); const gchar *attvalue = attlist?((gchar *)attlist->data):NULL; if (attvalue) { addritem_attrib_set_name( attrib, attribute ); addritem_attrib_set_value( attrib, attvalue ); other_attrs = g_slist_prepend(other_attrs, attrib); } mgu_free_list(attlist); } /* Free memory used to store attribute */ ldap_memfree( attribute ); } /* Format and add items to cache */ listReturn = ldapqry_build_items_fl( cache, qry, dnEntry, listName, listAddress, listFirst, listLast, listDisplay, other_attrs ); /* Free up */ ldapqry_free_lists( listName, listAddress, listFirst, listLast, listDisplay, other_attrs ); listName = listAddress = listFirst = listLast = listDisplay = other_attrs = NULL; if( ber != NULL ) { ber_free( ber, 0 ); } ldap_memfree( dnEntry ); return listReturn; }
/** * Build an address list entry and append to list of address items in the * address cache. Name is formatted as "<first-name> <last-name>". * \param ldifFile LDIF import control object. * \param rec LDIF field object. * \param cache Address cache to be populated with data. */ static void ldif_build_items( LdifFile *ldifFile, Ldif_ParsedRec *rec, AddressCache *cache ) { GSList *nodeFirst; GSList *nodeAddress; GSList *nodeAttr; gchar *firstName = NULL, *lastName = NULL, *fullName = NULL; gchar *nickName = NULL; gint iLen = 0, iLenT = 0; ItemPerson *person; ItemEMail *email; nodeAddress = rec->listAddress; // if( nodeAddress == NULL ) return; /* Find longest first name in list */ nodeFirst = rec->listFName; while( nodeFirst ) { if( firstName == NULL ) { firstName = nodeFirst->data; iLen = strlen( firstName ); } else { if( ( iLenT = strlen( nodeFirst->data ) ) > iLen ) { firstName = nodeFirst->data; iLen = iLenT; } } nodeFirst = g_slist_next( nodeFirst ); } /* Format name */ if( rec->listLName ) { lastName = rec->listLName->data; } if( firstName ) { if( lastName ) { fullName = g_strdup_printf( "%s %s", firstName, lastName ); } else { fullName = g_strdup_printf( "%s", firstName ); } } else { if( lastName ) { fullName = g_strdup_printf( "%s", lastName ); } } if (!fullName || strlen(fullName) == 0) { g_free(fullName); fullName = NULL; if (rec->listCName) fullName = g_strdup(rec->listCName->data); } if( fullName ) { g_strstrip( fullName ); } if( rec->listNName ) { nickName = rec->listNName->data; } person = addritem_create_item_person(); addritem_person_set_common_name( person, fullName ); addritem_person_set_first_name( person, firstName ); addritem_person_set_last_name( person, lastName ); addritem_person_set_nick_name( person, nickName ); addrcache_id_person( cache, person ); addrcache_add_person( cache, person ); ++ldifFile->importCount; /* Add address item */ while( nodeAddress ) { email = addritem_create_item_email(); addritem_email_set_address( email, nodeAddress->data ); addrcache_id_email( cache, email ); addrcache_person_add_email( cache, person, email ); nodeAddress = g_slist_next( nodeAddress ); } g_free( fullName ); fullName = firstName = lastName = NULL; /* Add user attributes */ nodeAttr = rec->userAttr; while( nodeAttr ) { Ldif_UserAttr *attr = nodeAttr->data; UserAttribute *attrib = addritem_create_attribute(); addritem_attrib_set_name( attrib, attr->name ); addritem_attrib_set_value( attrib, attr->value ); addritem_person_add_attribute( person, attrib ); nodeAttr = g_slist_next( nodeAttr ); } nodeAttr = NULL; }