_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; }
_declspec (dllexport) STATUS ATOM_NSFSearch(HANDLE far hDB, HANDLE far hFormula, char *ViewTitle, WORD SearchFlags, WORD NoteClassMask, TIMEDATE *Since, NSFSEARCHPROC EnumRoutine, void *EnumRoutineParameter, TIMEDATE *retUntil) { return NSFSearch(hDB, hFormula, ViewTitle, SearchFlags, NoteClassMask, Since, EnumRoutine, EnumRoutineParameter, retUntil); }
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; }
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; }