_declspec ( dllexport ) WORD GetDatabaseNames(const char *port, const char *serverName, char retDatabaseNames[MAX_ENTRIES][MAXPATH]) { STATUS error = NO_ERROR; char directory[STRING_LENGTH]; /* directory path */ char full_netpath[MAXPATH] = ""; /* full network path */ DBHANDLE dir_handle; /* handle for directory */ wDatabaseCount = 0; //block = (char**)malloc(MAX_ENTRIES * MAXPATH * sizeof(char*)); strcpy_s(directory, full_netpath); if (strcmp(serverName, "Local")) { if (error = OSPathNetConstruct(port, serverName, directory, full_netpath)) return 0; } else { if (error = OSPathNetConstruct(NULL, "", directory, full_netpath)) return 0; } if (error = NSFDbOpen (full_netpath, &dir_handle)) { return 0; } if (error = NSFSearch ( dir_handle, // directory handle NULLHANDLE, // selection formula NULL, // title of view in formula SEARCH_FILETYPE + // search for files SEARCH_SUMMARY, // return a summary buffer FILE_DBANY + // find any .NS? file FILE_RECURSE + // find subdirectories FILE_NOUPDIRS, // don't find the ".." dir NULL, // starting date file_action, // call for each file found NULL, // argument to action routine NULL)) // returned ending date (unused) if (error = NSFDbClose(dir_handle)) return 0; for (int dbIndex=0; dbIndex<(int)wDatabaseCount; dbIndex++) { strcpy_s(retDatabaseNames[dbIndex], MAXPATH, dblist[dbIndex]); //strcpy_s(retDatabaseNames[dbIndex], MAXPATH, block[dbIndex]); //free(block[dbIndex]); } //free(block); return wDatabaseCount; }
/** eus_OpenDb( *** Attempts to open the specified Notes database on the given server. Validates that the "database" is not really a subdirectory path, the alternative return of NSFDbOpen(). --- parameters & return ---- pc_FILENM: pointer to the extended filename of the Notes database to be opened pc_SERVERNM: pointer to the name of the server on which the specified Notes database resides ph: Output. Pointer to the handle variable in which to store the handle to the specified Notes database. Guaranteed to be null if database could not be validated as a true Notes Mail database. RETURN: eus_SUCCESS if no error occured ERR_DIRECTORY if the specified filename is a directory, not a database the Notes API error code otherwise --- revision history ------- 9/12/99 PR: created */ STATUS eus_OpenDb( char pc_FILENM[], char pc_SERVERNM[], DBHANDLE *const ph) { char pc[ MAXPATH]; DBHANDLE h; WORD us; STATUS us_err; if (!( pc_FILENM && *pc_FILENM && pc_SERVERNM && ph)) return !eus_SUCCESS; *ph = NULL; //open the specified database on the given server OSPathNetConstruct( NULL, pc_SERVERNM, pc_FILENM, pc); if (us_err = NSFDbOpen( pc, &h)) return us_err; if (us_err = NSFDbModeGet( h, &us)) goto errJump; if (us_err = (us != DB_LOADED ? ERR_DIRECTORY : eus_SUCCESS)) goto errJump; *ph = h; return eus_SUCCESS; errJump: NSFDbClose( h); return us_err; } //eus_OpenDb(
_declspec ( dllexport ) STATUS ATOM_OSPathNetConstruct(const char *PortName, const char *ServerName, const char *FileName, char retPathName[MAXPATH]) { return OSPathNetConstruct(PortName, ServerName, FileName, retPathName); }
BOOL getDBSpace(CString strServer, CString strDBFile, char *szReturn) { char szFullNetPath[MAXPATH] = ""; /* full network path */ DBHANDLE dir_handle; /* handle for directory */ STATUS error = NOERROR; /* return status from API calls */ DWORD dwAvalid = 0; DWORD dwFree = 0; error = NotesInitExtended (0, NULL); if (error) { sprintf (szReturn, "error=Error initializing Notes."); return FALSE; } if(strServer != _T("")) { /* Compose the full network pathname to the directory. */ if (error = OSPathNetConstruct(NULL, strServer.GetBuffer(0), strDBFile.GetBuffer(0), szFullNetPath)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } } /* Open the directory. */ if (error = NSFDbOpen (szFullNetPath, &dir_handle)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } if (error = NSFDbSpaceUsage(dir_handle, &dwAvalid, &dwFree)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } /* Close the directory. */ if (error = NSFDbClose (dir_handle)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } NotesTerm(); sprintf(szReturn, "Used=%f$Free=%f$FreePer=%f$", dwAvalid/(1024.0*1024), dwFree/(1024.0*1024), 100.0*dwFree/(dwFree+dwAvalid)); return TRUE; }
void NotesHelper::InitialiseSession() { if(m_notesInitialised) return; if (0 != NotesInit()) throw CppUnitException(_T("Failed to Initialise Notes runtime"), __LINE__, _T(__FILE__)); char serverName[1024] = {0}; if(TRUE != OSGetEnvironmentString("MailServer", serverName, sizeof(serverName))) throw CppUnitException(_T("Failed to obtain the Lotus Domino Mail Server"), __LINE__, _T(__FILE__)); char szMailFileName[MAXUSERNAME + 1]; strcpy(szMailFileName, MAILBOX_NAME); char szMailBoxPath[MAXPATH + 1] = {0}; OSPathNetConstruct(0, serverName, szMailFileName, szMailBoxPath); STATUS error = NSFDbOpen(szMailBoxPath, &m_hMailBox); if (NOERROR != error) throw CppUnitException(_T("Failed to open mail.box"), __LINE__, _T(__FILE__)); m_notesInitialised = true; }
int main(int argc, char *argv[]) { DBHANDLE db_handle; /* handle of source database */ STATUS error = NOERROR; /* return #Dtatus from API calls */ char formula[STRING_LENGTH]; char database_name[STRING_LENGTH]; char username_name[STRING_LENGTH]; char *pUserName = username_name; char *pDbFileName = database_name; /* pathname of source database */ ProcessArgs(argc, argv); // ConfigAgent.exe idfile passwd server dbfile formname char *pIDFileName = argv[1]; //"C:\\Program Files\\lotus\\notes\\data\\admin.id"; char *pPassword = argv[2]; //"mac8.6"; char *pServer = argv[3]; // benz char *pDatabase = argv[4]; // smd\smconf.nsf char *pForm = argv[5]; // policy if (strncmp(pForm, "*", strlen(pForm)) == 0) strncpy(formula, "@All", 5); else { _snprintf(formula, sizeof(formula)-1, "Form=\"%s\"", pForm); formula[sizeof(formula)-1] = '\0'; } if (error = NotesInitExtended (argc, argv)) { printf("\n Unable to initialize Notes.\n"); return CONFIG_AGENT_ERROR_NOTE_INIT_FAIL; } if (error = OSPathNetConstruct( NULL, pServer, pDatabase, pDbFileName)) { PrintAPIError (error); NotesTerm(); return CONFIG_AGENT_ERROR_PATH_CONSTRUCT_FAIL; } if (error = SECKFMSwitchToIDFile(pIDFileName, pPassword, pUserName, STRING_LENGTH, fKFM_switchid_DontSetEnvVar, NULL)) { printf ("Error: unable to open the id file '%s'\n", pIDFileName); PrintAPIError (error); NotesTerm(); if (error == ERR_NOEXIST) return CONFIG_AGENT_ERROR_IDFILE_NOT_EXIST; else if (error == ERR_BSAFE_BADPASSWORD) return CONFIG_AGENT_ERROR_BAD_PASSWORD; else return CONFIG_AGENT_ERROR_SWITCH_ID_FAIL; } /* Open the database. */ if (error = NSFDbOpen (pDbFileName, &db_handle)) { printf ("Error: unable to open database '%s'\n", pDbFileName); PrintAPIError (error); NotesTerm(); return CONFIG_AGENT_ERROR_DB_OPEN_FAIL; } /* Compile the selection formula. */ //char formula[] = "select form=\"Events\""; /* an ASCII selection formula. */ FORMULAHANDLE formula_handle; /* a compiled selection formula */ WORD wdc; /* a word we don't care about */ if (error = NSFFormulaCompile ( NULL, /* name of formula (none) */ (WORD) 0, /* length of name */ formula, /* the ASCII formula */ (WORD) strlen(formula), /* length of ASCII formula */ &formula_handle, /* handle to compiled formula */ &wdc, /* compiled formula length (don't care) */ &wdc, /* return code from compile (don't care) */ &wdc, &wdc, &wdc, &wdc)) /* compile error info (don't care) */ { NSFDbClose (db_handle); PrintAPIError (error); NotesTerm(); return CONFIG_AGENT_ERROR_FORMULA_COMPILE_FAIL; } /* Call NSFSearch to find all data notes in the database. Specify search flag SEARCH_SUMMARY so that the action routine gets passed the summary buffer as input. */ if (error = NSFSearch ( db_handle, /* database handle */ formula_handle, /* selection formula */ NULL, /* title of view in selection formula */ SEARCH_SUMMARY, /* search flags: get summary data! */ NOTE_CLASS_DATA, /* note class to find */ NULL, /* starting date (unused) */ ReadSummaryData, /* action routine for notes found */ NULL, /* argument to action routine */ NULL)) /* returned ending date (unused) */ { printf ("Error: unable to search database.\n"); NSFDbClose (db_handle); PrintAPIError (error); NotesTerm(); return CONFIG_AGENT_ERROR_DB_SERACH_FAIL; } /* Close the database. */ if (error = NSFDbClose (db_handle)) { printf ("Error: unable to close database '%s'\n", pDbFileName); PrintAPIError (error); NotesTerm(); return CONFIG_AGENT_ERROR_DB_CLOSE_FAIL; } /* End of main routine. */ printf("\nProgram completed successfully.\n"); NotesTerm(); return CONFIG_AGENT_ERROR_SUCCESS; }
/****************************************************************************** This function attempts to find the first matching name from the supplied (possibly) partial name. Searches local, server or additional directories ******************************************************************************/ std::wstring RecipientsHandler::GetMatchingName(const std::wstring &name, const std::wstring &server, bool exhaustive) { std::wstring result; WORD wEntry; WORD wABCount; WORD wABBufferLength; HANDLE hABBuffer = 0; char szABServer[MAXPATH]; char szABFileName[MAXPATH]; char szABFullPath[MAXPATH]; //char szCaption[MAXUSERNAME + 64]; //strcpy_s(szCaption, "Searching for "); //strcat_s(szCaption, sizeof(szCaption) - strlen(szCaption), Workshare::Conversions::W22LMBCS(name).c_str()); //IXPostMessage(szCaption); STATUS status = NAMEGetAddressBooks(server.empty() ? NULL : Workshare::Conversions::W22LMBCS(server).c_str(), exhaustive ? 0 : NAME_GET_AB_FIRSTONLY, &wABCount, &wABBufferLength, &hABBuffer); if (NOERROR != status) { LOG_WS_ERROR(L"Error: NAMEGetAddressBooks"); return L""; } // if stat was good, but no directories returned, we still have to free the buffer if (wABCount == 0) { if (hABBuffer != 0) OSMemFree(hABBuffer); LOG_WS_INFO(L"No directories returned."); return L""; } char* pszABBuffer = OSLock(char, hABBuffer); for (wEntry = 0; wEntry < wABCount; wEntry++) { OSPathNetParse(pszABBuffer, NULL, szABServer, szABFileName); if (strlen(szABServer) == 0 && !server.empty()) { strcpy_s(szABServer, sizeof(szABServer), Workshare::Conversions::W22LMBCS(server).c_str()); } OSPathNetConstruct( NULL, szABServer, szABFileName, szABFullPath); if (IsCondensedDirectory(szABFullPath)) { result = SearchCondensedDirectory(szABFullPath, name); } else { result = SearchDominoDirectory(szABFullPath, name); } if (!result.empty()) { break; } pszABBuffer += (strlen(pszABBuffer) + 1); } OSUnlock(hABBuffer); // done with this now OSMemFree(hABBuffer); // unlock and free it if (result.empty()) { //strcpy_s(szCaption, sizeof(szCaption), "Could not find "); //strcat_s(szCaption, sizeof(szCaption) - strlen(szCaption), Workshare::Conversions::W22LMBCS(name).c_str()); //IXPostMessage(szCaption); std::wostringstream msg; msg << "No match found: name=[" << name.c_str() << "] server=[" << server.c_str() << "]" << std::ends; LOG_WS_INFO(msg.str().c_str()); return L""; } //strcpy_s(szCaption, sizeof(szCaption), "Found "); //strcat_s(szCaption, sizeof(szCaption) - strlen(szCaption), Workshare::Conversions::W22LMBCS(result).c_str()); //IXPostMessage(szCaption); std::wostringstream msg; msg << "Match found: name=[" << name.c_str() << "] match=[" << result.c_str() << "] server=[" << server.c_str() << "]" << std::ends; LOG_WS_INFO(msg.str().c_str()); return result; }
BOOL NSF_List(CString strServer, CString strDirectory, CStringList &lstTexts, CStringList &lstValues, char* szReturn) { char szFullNetPath[MAXPATH] = ""; /* full network path */ DBHANDLE dir_handle; /* handle for directory */ STATUS error = NOERROR; /* return status from API calls */ error = NotesInitExtended (0, NULL); if (error) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); return FALSE; } if (strDirectory != _T("")) { strcpy(szFullNetPath, strDirectory.GetBuffer(0)); } if(strServer != _T("")) { // Compose the full network pathname to the directory. if (error = OSPathNetConstruct(NULL, strServer.GetBuffer(0), strDirectory.GetBuffer(0), szFullNetPath)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } } // Open the directory. if (error = NSFDbOpen (szFullNetPath, &dir_handle)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } /* Call NSFSearch to find files in the directory. For each file found, call an action routine. */ if (error = NSFSearch ( dir_handle, /* directory handle */ NULLHANDLE, /* selection formula */ NULL, /* title of view in formula */ SEARCH_FILETYPE + /* search for files */ SEARCH_SUMMARY, /* return a summary buffer */ FILE_DBANY + /* find any .NS? file */ FILE_DIRS + /* find subdirectories */ FILE_NOUPDIRS, /* don't find the ".." dir */ NULL, /* starting date */ file_action_list, /* call for each file found */ &lstTexts, /* argument to action routine */ NULL)) /* returned ending date (unused) */ { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NSFDbClose (dir_handle); NotesTerm(); return FALSE; } /* Close the directory. */ if (error = NSFDbClose (dir_handle)) { OSLoadString(NULLHANDLE, ERR(error), szReturn, 1024); NotesTerm(); return FALSE; } /* Terminate Domino and Notes. */ NotesTerm(); POSITION pos=NULL; pos = lstTexts.GetHeadPosition(); while(pos) { lstValues.AddTail(lstTexts.GetNext(pos)); } return TRUE; }
_declspec ( dllexport ) WORD GetServerNamesEx(char retServerNames[MAX_SERVERS][MAXPATH]) { BOOL status = NOERROR; char szLocation[MAXENVVALUE]; char szPAB[MAXENVVALUE]; HANDLE db; char full_netpath[MAXPATH-1]; NOTEID view_id; HCOLLECTION hCollection; COLLECTIONPOSITION pCollPosition; HANDLE hBuffer; DWORD NumberReturned = 0; NOTEID *IdList; NOTEHANDLE note; char szFieldName[80] = { 0 }; char szFieldType[80] = { 0 }; WORD retServerCount = 0; bool bUseLocal = false; // first, get the name of the current location status = OSGetEnvironmentString("Location", szLocation, MAXENVVALUE); if (status == TRUE) { char *pb = strchr(szLocation, ','); if (pb != NULL) *pb = 0 ; } status = OSGetEnvironmentString("MAILSERVER", szPAB, MAXENVVALUE); if (status == TRUE) { char *pb = strchr(szPAB, ','); if (pb != NULL) *pb = 0 ; } if (status = OSPathNetConstruct(NULL, szPAB, _T("names.nsf"), full_netpath)) { printf("unable to open the public NAB %s!!names.nsf\n", szFieldName); return 0; } if (status = NSFDbOpen (full_netpath, &db)) return 0; if (bUseLocal) { // choose local PAB view if (status = NIFFindView(db, _T("Connections"), &view_id)) { NSFDbClose(db); return 0; } } else { // choose server list from server Directory if (status = NIFFindView(db, _T("Servers"), &view_id)) { NSFDbClose(db); return 0; } } if (status = NIFOpenCollection( db, db, view_id, 0, NULLHANDLE, &hCollection, NULL, NULL, NULL, NULL )) { NSFDbClose(db); return 0; } pCollPosition.Level = 0; pCollPosition.Tumbler[0] = 1; if (status = NIFReadEntries(hCollection, &pCollPosition, NAVIGATE_CURRENT, 1L, NAVIGATE_NEXT, 0xFFFFFFFF, READ_MASK_NOTEID, &hBuffer, NULL, NULL, &NumberReturned, NULL)) { NIFCloseCollection(hCollection); NSFDbClose(db); return 0; } strcpy_s(retServerNames[retServerCount++], MAXPATH, _T("Local")); if (NumberReturned != 0) { if (hBuffer != NULLHANDLE) { IdList = (NOTEID far *)OSLockObject(hBuffer); for (DWORD i=0; i<(DWORD)NumberReturned; i++) { if (status = NSFNoteOpen( db, IdList[i], 0, ¬e)) { // skip categories } else { // scan documents WORD lenFieldName = NSFItemGetText(note, (bUseLocal) ? _T("Destination") : _T("ServerName"), szFieldName, sizeof(szFieldName)); strcpy_s(retServerNames[retServerCount++], MAXPATH, szFieldName); status = NSFNoteClose(note); } } OSUnlockObject(hBuffer); OSMemFree(hBuffer); } } if (status) { NIFCloseCollection(hCollection); NSFDbClose(db); return 0; } if (status = NIFCloseCollection(hCollection)) { NSFDbClose(db); return 0; } if (status = NSFDbClose(db)) return 0; return retServerCount; }