/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ // // Address Book API Utility Functions // Written by: Rich Pizzarro (rhp@netscape.com) // March 1998 #include "stdafx.h" #include #include #include #include #include "wfemsg.h" // for WFE_MSGGetMaster() #include "nsstrseq.h" #include "abapi.h" #include "abhook.h" #include "nabapi.h" #include "mapismem.h" #include "hiddenfr.h" #include "msgcom.h" #include "abutils.h" #include "abcom.h" extern CNetscapeApp theApp; typedef struct { BOOL foundInSearch; int attribType; AB_AttribID attribID; char *ldifName; } attribPairsType; // I18N: Please don't touch these strings! #define ATTRIB_COUNT 19 attribPairsType attribArray[] = { // FALSE, dn: cn=first last,mail=email FALSE, CHAR_VALUE, AB_attribDisplayName, /*AB_attribFullName,*/ "cn: ", FALSE, CHAR_VALUE, AB_attribFamilyName, "sn: ", FALSE, CHAR_VALUE, AB_attribGivenName, "givenname: ", // FALSE, CHAR_VALUE, "top", "objectclass: ", // FALSE, CHAR_VALUE, "person", "objectclass: ", FALSE, CHAR_VALUE, AB_attribInfo, "description: ", FALSE, CHAR_VALUE, AB_attribLocality, "locality: ", FALSE, CHAR_VALUE, AB_attribRegion, "st: ", FALSE, CHAR_VALUE, AB_attribEmailAddress, "mail: ", FALSE, CHAR_VALUE, AB_attribTitle, "title: ", FALSE, CHAR_VALUE, AB_attribPOAddress, "postOfficeBox: ", FALSE, CHAR_VALUE, AB_attribStreetAddress, "streetaddress: ", FALSE, CHAR_VALUE, AB_attribZipCode, "postalcode: ", FALSE, CHAR_VALUE, AB_attribCountry, "countryname: ", FALSE, CHAR_VALUE, AB_attribWorkPhone, "telephonenumber: ", FALSE, CHAR_VALUE, AB_attribFaxPhone, "facsimiletelephonenumber: ", FALSE, CHAR_VALUE, AB_attribHomePhone, "homephone: ", FALSE, CHAR_VALUE, AB_attribCompanyName, "o: ", FALSE, CHAR_VALUE, AB_attribNickName, "xmozillanickname: ", FALSE, BOOL_VALUE, AB_attribHTMLMail, "xmozillausehtmlmail: ", FALSE, INT_VALUE, AB_attribUseServer, "xmozillauseconferenceserver: "}; BOOL TackOnAttributeValuePair(MSG_Pane *abPane, LONG userIndex, LPSTR outString, AB_AttribID attribID, LPSTR stringKey, DWORD typeOfValue, LPSTR concatString) { int result; AB_AttributeValue *value; if (!outString) return FALSE; result = AB_GetEntryAttributeForPane(abPane, userIndex, attribID, &value); if (result != 0) return FALSE; if (typeOfValue == CHAR_VALUE) { // Do the key name first... if ( (value->u.string != NULL) && (value->u.string[0] != '\0') ) { lstrcat(outString, stringKey); lstrcat(outString, (char *)value->u.string); if (concatString) lstrcat(outString, concatString); } } else if (typeOfValue == BOOL_VALUE) { // Do the key name first... lstrcat(outString, stringKey); if (value->u.boolValue) lstrcat(outString, "TRUE"); else lstrcat(outString, "FALSE"); if (concatString) lstrcat(outString, concatString); } else if (typeOfValue == INT_VALUE) { char tval[16]; // Do the key name first... lstrcat(outString, stringKey); wsprintf(tval, "%d", value->u.shortValue); lstrcat(outString, tval); if (concatString) lstrcat(outString, concatString); } AB_FreeEntryAttributeValue(value); return(TRUE); } BOOL GetLDIFLineForUser(MSG_Pane *abPane, LONG userIndex, LPSTR outString, NABUserID *userID, NABUpdateTime *updtTime) { ABID id; int i; BOOL rc; if (!outString) return FALSE; outString[0] = '\0'; lstrcpy(outString, "dn: "); rc = TackOnAttributeValuePair(abPane, userIndex, outString, AB_attribFullName, "cn: ", CHAR_VALUE, ","); if (!rc) return FALSE; rc = TackOnAttributeValuePair(abPane, userIndex, outString, AB_attribEmailAddress, "mail: ", CHAR_VALUE, NAB_CRLF); if (!rc) return FALSE; for (i=0; iu.string != NULL) && (value->u.string[0] != '\0') ) { if ( _lwrite(hHTMLFile, value->u.string, lstrlen(value->u.string)) == HFILE_ERROR) return FALSE; else return TRUE; } else return FALSE; } BOOL DumpHTMLTableLineForUser(MSG_Pane *abPane, LONG userIndex) { DumpHTMLForTable(HTMLNEWROW); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribFamilyName); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribGivenName); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribEmailAddress); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); if (DumpHTMLValue(abPane, userIndex, AB_attribCompanyName)) DumpHTMLForTable(HTMLBREAK); DumpHTMLValue(abPane, userIndex, AB_attribTitle); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribWorkPhone); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribFaxPhone); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); DumpHTMLValue(abPane, userIndex, AB_attribHomePhone); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLSTART); if (DumpHTMLValue(abPane, userIndex, AB_attribPOAddress)) DumpHTMLForTable(HTMLBREAK); if (DumpHTMLValue(abPane, userIndex, AB_attribStreetAddress)) DumpHTMLForTable(HTMLBREAK); if (DumpHTMLValue(abPane, userIndex, AB_attribLocality)) DumpHTMLForTable(HTMLCOMMA); DumpHTMLValue(abPane, userIndex, AB_attribRegion); if (DumpHTMLValue(abPane, userIndex, AB_attribZipCode)) DumpHTMLForTable(HTMLBREAK); DumpHTMLValue(abPane, userIndex, AB_attribCountry); DumpHTMLForTable(HTMLEND); DumpHTMLForTable(HTMLENDROW); return TRUE; } BOOL FindAttributeInLine(LPSTR attribName, LPSTR addLine) { DWORD totlen, complen, i; if ( (!attribName) || !(*attribName) ) return FALSE; if ( (!addLine) || !(*addLine) ) return FALSE; i = 0; totlen = strlen(addLine); complen = strlen(attribName); while ( (i + complen) <= totlen ) { if (strncmp( attribName, addLine+i, complen ) == 0) { return TRUE; } i++; } return FALSE; } LPSTR ExtractAttribValue(LPSTR attribName, LPSTR searchLine) { DWORD totlen, complen, i; if ( (!attribName) || !(*searchLine) ) return NULL; if ( (!searchLine) || !(*searchLine) ) return NULL; i = 0; totlen = strlen(searchLine); complen = strlen(attribName); while ( (i + complen) <= totlen ) { if (strncmp( attribName, searchLine+i, complen ) == 0) { if (i+complen == totlen) // Check if we are at the end... return NULL; LPSTR newPtr; LPSTR startPtr; LPSTR endPtr; DWORD totalSize; // Have to add this hack for the fact we have an attribute that // is a subset of another (i.e. "mail: " and "xmozillausehtmlmail: ") if ( (strcmp(attribName, "mail: ") == 0) && (i > 0) && (*(searchLine+i-1) == 'l' ) ) { i++; continue; } // end of hack startPtr = searchLine + (i + complen); endPtr = startPtr; while ( ((*endPtr) != '\0') && ((*endPtr) != '\r') ) { endPtr = (endPtr + 1); } totalSize = (endPtr - startPtr) + 1; newPtr = (LPSTR) malloc(totalSize); if (!newPtr) return NULL; memset(newPtr, 0, totalSize); strncpy(newPtr, startPtr, (totalSize - 1)); return newPtr; } i++; } return NULL; } BOOL ThisIsAStringAttrib(AB_AttribID attrib) { int i; for (i=0; iu.string != NULL) && (value->u.string[0] != '\0') ) { if ( strlen(value->u.string) >= strlen(searchValue) ) { if (_strnicmp(value->u.string, searchValue, strlen(searchValue)) == 0) { found = TRUE; } } } AB_FreeEntryAttributeValue(value); return(found); } BOOL SearchABForAttrib(AB_ContainerInfo *abContainer, LPSTR searchAttrib, LPSTR ldifInfo, NABUserID *userID, NABUpdateTime *updtTime) { int result; MSG_Pane *addressBookPane; // Container info for a particular addr book result = AB_CreateABPane(&addressBookPane, theApp.m_pAddressContext, WFE_MSGGetMaster()); if (result) { return FALSE; } result = AB_InitializeABPane(addressBookPane, abContainer); if (result) { AB_ClosePane(addressBookPane); return(FALSE); } DWORD id; int currentLocation = 0; LONG lineCount = MSG_GetNumLines(addressBookPane); LPSTR searchValue = NULL; BOOL found = FALSE; // // Support lookups by ABID's... if ((searchAttrib == NULL) || (searchAttrib[0] == '\0')) { while ( currentLocation < lineCount ) { ABID id; // Get the ABID... int result = AB_GetABIDForIndex(addressBookPane, currentLocation, &id); if (result != 0) { ++currentLocation; continue; } if (id == *userID) { found = TRUE; if (!GetLDIFLineForUser(addressBookPane, currentLocation, ldifInfo, userID, updtTime)) { found = FALSE; currentLocation++; continue; } break; } // Increment for next call... currentLocation++; } AB_ClosePane(addressBookPane); return found; } // Support lookups by ABID's... // if (!GetIDSearchField(searchAttrib, &id, &searchValue)) { AB_ClosePane(addressBookPane); return(FALSE); } while ( currentLocation < lineCount ) { found = FindValueForIDInLine(addressBookPane, currentLocation, (AB_AttribID)id, searchValue); if (found) { if (!GetLDIFLineForUser(addressBookPane, currentLocation, ldifInfo, userID, updtTime)) { found = FALSE; currentLocation++; continue; } break; } // Increment for next call... currentLocation++; } if (searchValue != NULL) free(searchValue); AB_ClosePane(addressBookPane); return found; }