Java Code Examples for com.sun.jna.Memory#size()
The following examples show how to use
com.sun.jna.Memory#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IDUtils.java From domino-jna with Apache License 2.0 | 6 votes |
/** * This function returns the Username associated with the workstation's or server's * ID where this function is executed. * * @return username */ public static String getIdUsername() { Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1); short result = NotesNativeAPI.get().SECKFMGetUserName(retUserNameMem); NotesErrorUtils.checkResult(result); int userNameLength = 0; for (int i=0; i<retUserNameMem.size(); i++) { userNameLength = i; if (retUserNameMem.getByte(i) == 0) { break; } } String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength); return userName; }
Example 2
Source File: IDUtils.java From domino-jna with Apache License 2.0 | 6 votes |
/** * This function switches to the specified ID file and returns the user name associated with it.<br> * <br> * Multiple passwords are not supported.<br> * <br> * NOTE: This function should only be used in a C API stand alone application. * * @param idPath path to the ID file that is to be switched to * @param password password of the ID file that is to be switched to * @param dontSetEnvVar If specified, the notes.ini file (either ServerKeyFileName or KeyFileName) is modified to reflect the ID change. * @return user name, in the ID file that is to be switched to */ public static String switchToId(String idPath, String password, boolean dontSetEnvVar) { Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true); Memory passwordMem = NotesStringUtils.toLMBCS(password, true); Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1); short result = NotesNativeAPI.get().SECKFMSwitchToIDFile(idPathMem, passwordMem, retUserNameMem, NotesConstants.MAXUSERNAME, dontSetEnvVar ? NotesConstants.fKFM_switchid_DontSetEnvVar : 0, null); NotesErrorUtils.checkResult(result); int userNameLength = 0; for (int i=0; i<retUserNameMem.size(); i++) { userNameLength = i; if (retUserNameMem.getByte(i) == 0) { break; } } String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength); return userName; }
Example 3
Source File: NotesStringUtils.java From domino-jna with Apache License 2.0 | 6 votes |
/** * Scans the Memory object for null values * * @param in memory * @return number of bytes before null byte in memory */ public static int getNullTerminatedLength(Memory in) { if (in == null) { return 0; } int textLen = (int) in.size(); //search for terminating null character for (int i=0; i<textLen; i++) { byte b = in.getByte(i); if (b==0) { textLen = i; break; } } return textLen; }
Example 4
Source File: NotesSearchKeyEncoder.java From domino-jna with Apache License 2.0 | 6 votes |
/** * Writes data for a time search key * * @param itemOut output stream for ITEM structure * @param valueDataOut output stream for search key value * @param innard0 first innard of date * @param innard1 second innard of date * @throws Exception in case of errors */ private static void addCalendarKey(OutputStream itemOut, OutputStream valueDataOut, int innard0, int innard1) throws Exception { Memory itemMem = new Memory(NotesConstants.tableItemSize); NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem); item.NameLength = 0; item.ValueLength = (short) (NotesConstants.timeDateSize + 2); item.write(); for (int i=0; i<NotesConstants.tableItemSize; i++) { itemOut.write(itemMem.getByte(i)); } //write data type Memory valueMem = new Memory(2 + 8); valueMem.setShort(0, (short) NotesItem.TYPE_TIME); Pointer timeDatePtr = valueMem.share(2); NotesTimeDateStruct timeDate = NotesTimeDateStruct.newInstance(timeDatePtr); timeDate.Innards[0] = innard0; timeDate.Innards[1] = innard1; timeDate.write(); for (int i=0; i<valueMem.size(); i++) { valueDataOut.write(valueMem.getByte(i)); } }
Example 5
Source File: NotesSearchKeyEncoder.java From domino-jna with Apache License 2.0 | 6 votes |
/** * Writes data for a number search key * * @param itemOut output stream for ITEM structure * @param valueDataOut output stream for search key value * @param doubleValue search key * @throws Exception in case of errors */ private static void addNumberKey(OutputStream itemOut, OutputStream valueDataOut, double doubleValue) throws Exception { Memory itemMem = new Memory(NotesConstants.tableItemSize); NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem); item.NameLength = 0; item.ValueLength = (short) (8 + 2); item.write(); for (int i=0; i<NotesConstants.tableItemSize; i++) { itemOut.write(itemMem.getByte(i)); } Memory valueMem = new Memory(8 + 2); valueMem.setShort(0, (short) NotesItem.TYPE_NUMBER); Pointer doubleValPtr = valueMem.share(2); doubleValPtr.setDouble(0, doubleValue); for (int i=0; i<valueMem.size(); i++) { valueDataOut.write(valueMem.getByte(i)); } }
Example 6
Source File: Advapi32Util.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
/** * Get a registry REG_MULTI_SZ value. * * @param root Root key. * @param key Registry path. * @param value Name of the value to retrieve. * @return String value. */ public static String[] registryGetStringArray(HKEY root, String key, String value) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } try { IntByReference lpcbData = new IntByReference(); IntByReference lpType = new IntByReference(); rc = Advapi32.INSTANCE.RegQueryValueEx( phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { throw new Win32Exception(rc); } if (lpType.getValue() != WinNT.REG_MULTI_SZ) { throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ"); } Memory data = new Memory(lpcbData.getValue()); rc = Advapi32.INSTANCE.RegQueryValueEx( phkKey.getValue(), value, 0, lpType, data, lpcbData); if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { throw new Win32Exception(rc); } ArrayList<String> result = new ArrayList<>(); int offset = 0; while (offset < data.size()) { String s = data.getString(offset, true); offset += s.length() * Native.WCHAR_SIZE; offset += Native.WCHAR_SIZE; result.add(s); } return result.toArray(new String[result.size()]); } finally { rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } } }
Example 7
Source File: SecureStorageWindowsManager.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
public SecureStorageStatus setCredential(String host, String user, String token) { if (Strings.isNullOrEmpty(token)) { logger.info("No token provided"); return SecureStorageStatus.SUCCESS; } byte[] credBlob = token.getBytes(StandardCharsets.UTF_16LE); Memory credBlobMem = new Memory(credBlob.length); credBlobMem.write(0, credBlob, 0, credBlob.length); String target = SecureStorageManager.convertTarget(host, user); SecureStorageWindowsCredential cred = new SecureStorageWindowsCredential(); cred.Type = SecureStorageWindowsCredentialType.CRED_TYPE_GENERIC.getType(); cred.TargetName = new WString(target); cred.CredentialBlobSize = (int) credBlobMem.size(); cred.CredentialBlob = credBlobMem; cred.Persist = SecureStorageWindowsCredentialPersistType.CRED_PERSIST_LOCAL_MACHINE.getType(); cred.UserName = new WString(user.toUpperCase()); boolean ret = false; synchronized (advapi32Lib) { ret = advapi32Lib.CredWriteW(cred, 0); } if (!ret) { logger.info(String.format("Failed to write to Windows Credential Manager. Error code = %d", Native.getLastError())); return SecureStorageStatus.FAILURE; } logger.info("Wrote to Windows Credential Manager successfully"); return SecureStorageStatus.SUCCESS; }
Example 8
Source File: NotesSearchKeyEncoder.java From domino-jna with Apache License 2.0 | 5 votes |
/** * Searching with number range keys is not supported yet (R9), as the * <a href="http://www-12.lotus.com/ldd/doc/domino_notes/9.0/api90ref.nsf/70cfe734675fd140852561ce00718042/35abe18f9580ca2d8525622e0062c48d?OpenDocument">documentation</a> says. * * @param itemOut output stream for ITEM structure * @param valueDataOut output stream for search key value * @param currKey search key * @throws Exception in case of errors */ private static void addNumberRangeKey(OutputStream itemOut, OutputStream valueDataOut, double[] currKey) throws Exception { if (currKey.length!=2) throw new IllegalArgumentException("Double search key array must have exactly 2 elements. We found "+currKey.length); Memory itemMem = new Memory(NotesConstants.tableItemSize); NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem); item.NameLength = 0; item.ValueLength = (short) ((NotesConstants.rangeSize + NotesConstants.numberPairSize + 2) & 0xffff); item.write(); for (int i=0; i<NotesConstants.tableItemSize; i++) { itemOut.write(itemMem.getByte(i)); } Memory valueMem = new Memory(NotesConstants.rangeSize + NotesConstants.numberPairSize + 2); valueMem.setShort(0, (short) NotesItem.TYPE_NUMBER_RANGE); Pointer rangePtr = valueMem.share(2); NotesRangeStruct range = NotesRangeStruct.newInstance(rangePtr); range.ListEntries = 0; range.RangeEntries = 1; range.write(); Pointer pairPtr = rangePtr.share(NotesConstants.rangeSize); NotesNumberPairStruct pair = NotesNumberPairStruct.newInstance(pairPtr); pair.Lower = currKey[0]; pair.Upper = currKey[1]; pair.write(); for (int i=0; i<valueMem.size(); i++) { valueDataOut.write(valueMem.getByte(i)); } }
Example 9
Source File: NotesSearchKeyEncoder.java From domino-jna with Apache License 2.0 | 5 votes |
/** * Writes data for a time range search key * * @param itemOut output stream for ITEM structure * @param valueDataOut output stream for search key value * @param startInnard0 innard 0 of startdatetime * @param startInnard1 innard 0 of startdatetime * @param endInnard0 innard 0 of enddatetime * @param endInnard1 innard 0 of enddatetime * @throws Exception in case of errors */ private static void addCalendarRangeKey(OutputStream itemOut, OutputStream valueDataOut, int startInnard0, int startInnard1, int endInnard0, int endInnard1) throws Exception { Memory itemMem = new Memory(NotesConstants.tableItemSize); NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem); item.NameLength = 0; item.ValueLength = (short) ((NotesConstants.rangeSize + NotesConstants.timeDatePairSize + 2) & 0xffff); item.write(); for (int i=0; i<NotesConstants.tableItemSize; i++) { itemOut.write(itemMem.getByte(i)); } Memory valueMem = new Memory(NotesConstants.rangeSize + NotesConstants.timeDatePairSize + 2); valueMem.setShort(0, (short) NotesItem.TYPE_TIME_RANGE); Pointer rangePtr = valueMem.share(2); NotesRangeStruct range = NotesRangeStruct.newInstance(rangePtr); range.ListEntries = 0; range.RangeEntries = 1; range.write(); Pointer pairPtr = rangePtr.share(NotesConstants.rangeSize); NotesTimeDatePairStruct pair = NotesTimeDatePairStruct.newInstance(pairPtr); pair.Lower = NotesTimeDateStruct.newInstance(new int[] {startInnard0, startInnard1}); pair.Upper = NotesTimeDateStruct.newInstance(new int[] {endInnard0, endInnard1}); pair.write(); for (int i=0; i<valueMem.size(); i++) { valueDataOut.write(valueMem.getByte(i)); } }
Example 10
Source File: NotesSearchKeyEncoder.java From domino-jna with Apache License 2.0 | 5 votes |
/** * Writes data for a string search key * * @param itemOut output stream for ITEM structure * @param valueDataOut output stream for search key value * @param currKey search key * @throws Exception in case of errors */ private static void addStringKey(OutputStream itemOut, OutputStream valueDataOut, String currKey) throws Exception { Memory strValueMem = NotesStringUtils.toLMBCS(currKey, false); Memory itemMem = new Memory(NotesConstants.tableItemSize); NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem); item.NameLength = 0; item.ValueLength = (short) ((strValueMem.size() + 2) & 0xffff); item.write(); for (int i=0; i<NotesConstants.tableItemSize; i++) { itemOut.write(itemMem.getByte(i)); } Memory valueMem = new Memory(strValueMem.size() + 2); short txtType = (short) NotesItem.TYPE_TEXT; valueMem.setShort(0, txtType); Pointer strValuePtr = valueMem.share(2); for (int i=0; i<strValueMem.size(); i++) { strValuePtr.setByte(i, strValueMem.getByte(i)); } for (int i=0; i<valueMem.size(); i++) { valueDataOut.write(valueMem.getByte(i)); } }
Example 11
Source File: Advapi32Util.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
/** * Get a table of registry values. * * @param hKey Registry key. * @return Table of values. */ public static TreeMap<String, Object> registryGetValues(HKEY hKey) { IntByReference lpcValues = new IntByReference(); IntByReference lpcMaxValueNameLen = new IntByReference(); IntByReference lpcMaxValueLen = new IntByReference(); int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null, null, null, null, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, null, null); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } TreeMap<String, Object> keyValues = new TreeMap<>(); char[] name = new char[lpcMaxValueNameLen.getValue() + 1]; byte[] data = new byte[lpcMaxValueLen.getValue()]; for (int i = 0; i < lpcValues.getValue(); i++) { IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1); IntByReference lpcbData = new IntByReference(lpcMaxValueLen.getValue()); IntByReference lpType = new IntByReference(); rc = Advapi32.INSTANCE.RegEnumValue(hKey, i, name, lpcchValueName, null, lpType, data, lpcbData); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } String nameString = Native.toString(name); Memory byteData = new Memory(lpcbData.getValue()); byteData.write(0, data, 0, lpcbData.getValue()); switch (lpType.getValue()) { case WinNT.REG_DWORD: { keyValues.put(nameString, byteData.getInt(0)); break; } case WinNT.REG_SZ: case WinNT.REG_EXPAND_SZ: { keyValues.put(nameString, byteData.getString(0, true)); break; } case WinNT.REG_BINARY: { keyValues.put(nameString, byteData.getByteArray(0, lpcbData.getValue())); break; } case WinNT.REG_MULTI_SZ: { Memory stringData = new Memory(lpcbData.getValue()); stringData.write(0, data, 0, lpcbData.getValue()); ArrayList<String> result = new ArrayList<>(); int offset = 0; while (offset < stringData.size()) { String s = stringData.getString(offset, true); offset += s.length() * Native.WCHAR_SIZE; offset += Native.WCHAR_SIZE; result.add(s); } keyValues.put(nameString, result.toArray(new String[result.size()])); break; } default: throw new RuntimeException("Unsupported type: " + lpType.getValue()); } } return keyValues; }
Example 12
Source File: IDUtils.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Internal helper method to fetch the ID from the ID vault. * * @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format * @param password Password to id file being uploaded to the vault * @param idPath if not null, path to where the download ID file should be created or overwritten * @param rethKFC64 if not null, returns the hKFC handle to the in-memory id for 64 bit * @param rethKFC32 if not null, returns the hKFC handle to the in-memory id for 32 bit * @param serverName Name of server to contact * @return the vault server name * @throws NotesError in case of problems, e.g. ERR 22792 Wrong Password */ private static String _getUserIdFromVault(String userName, String password, String idPath, LongByReference rethKFC64, IntByReference rethKFC32, String serverName) { String userNameCanonical = NotesNamingUtils.toCanonicalName(userName); Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true); Memory passwordMem = NotesStringUtils.toLMBCS(password, true); Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true); Memory serverNameMem = new Memory(NotesConstants.MAXPATH); { Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true); if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) { throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)"); } if (serverNameParamMem!=null) { byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size()); serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length); } else { serverNameMem.setByte(0, (byte) 0); } } short result; if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC64, serverNameMem, 0, (short) 0, null); } else { result = NotesNativeAPI32.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC32, serverNameMem, 0, (short) 0, null); } NotesErrorUtils.checkResult(result); int vaultServerNameLength = 0; for (int i=0; i<serverNameMem.size(); i++) { vaultServerNameLength = i; if (serverNameMem.getByte(i) == 0) { break; } } String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength); return vaultServerName; }
Example 13
Source File: TestStringUtils.java From domino-jna with Apache License 2.0 | 4 votes |
private byte[] toByteArray(Memory m) { byte[] arr = new byte[(int) m.size()]; m.read(0, arr, 0, arr.length); return arr; }
Example 14
Source File: NotesStringUtils.java From domino-jna with Apache License 2.0 | 4 votes |
@Override protected int computeSize(String key, Memory value) { return key.length()*2 + (int) value.size(); }
Example 15
Source File: IDUtils.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Will open the ID file name provided, locate a vault server, synch the ID file contents to the vault, * then return the synched content. If successful the vault server name is returned. * @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format * @param password Password to id file being uploaded to the vault * @param idPath Path to where the download ID file should be created or overwritten * @param serverName Name of server to contact * @return sync result */ public static SyncResult syncUserIdWithVault(String userName, String password, String idPath, String serverName) { String userNameCanonical = NotesNamingUtils.toCanonicalName(userName); Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true); Memory passwordMem = NotesStringUtils.toLMBCS(password, true); Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true); Memory serverNameMem = new Memory(NotesConstants.MAXPATH); { Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true); if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) { throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)"); } if (serverNameParamMem!=null) { byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size()); serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length); } else { serverNameMem.setByte(0, (byte) 0); } } LongByReference phKFC64 = new LongByReference(); IntByReference phKFC32 = new IntByReference(); IntByReference retdwFlags = new IntByReference(); short result; if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECKFMOpen (phKFC64, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null); } else { result = NotesNativeAPI32.get().SECKFMOpen (phKFC32, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null); } NotesErrorUtils.checkResult(result); try { if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC64, serverNameMem, 0, (short) 0, null, retdwFlags); } else { result = NotesNativeAPI32.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC32, serverNameMem, 0, (short) 0, null, retdwFlags); } NotesErrorUtils.checkResult(result); } finally { if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECKFMClose(phKFC64, NotesConstants.SECKFM_close_WriteIdFile, 0, null); } else { result = NotesNativeAPI32.get().SECKFMClose(phKFC32, NotesConstants.SECKFM_close_WriteIdFile, 0, null); } NotesErrorUtils.checkResult(result); } NotesErrorUtils.checkResult(result); int vaultServerNameLength = 0; for (int i=0; i<serverNameMem.size(); i++) { vaultServerNameLength = i; if (serverNameMem.getByte(i) == 0) { break; } } String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength); SyncResult syncResult = new SyncResult(vaultServerName, retdwFlags.getValue()); return syncResult; }
Example 16
Source File: IDUtils.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Will open the ID file name provided, locate a vault server for user <code>userName</code>, * upload the ID file contents to the vault, then return with the vault server name.<br> * * @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format * @param password Password to id file being uploaded to the vault * @param idPath Path to where the download ID file should be created or overwritten or null to use the in-memory id * @param phKFC64 handle to the in-memory id or null to use an id file on disk for 64 bit * @param phKFC32 handle to the in-memory id or null to use an id file on disk for 32 bit * @param serverName Name of server to contact * @return the vault server name * @throws NotesError in case of problems, e.g. ERR 22792 Wrong Password */ private static String _putUserIdIntoVault(String userName, String password, String idPath, LongByReference phKFC64, IntByReference phKFC32, String serverName) { //opening any database on the server is required before putting the id fault, according to the //C API documentation and sample "idvault.c" NotesDatabase anyServerDb = new NotesDatabase(serverName, "names.nsf", (String) null); try { String userNameCanonical = NotesNamingUtils.toCanonicalName(userName); Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true); Memory passwordMem = NotesStringUtils.toLMBCS(password, true); Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true); Memory serverNameMem = new Memory(NotesConstants.MAXPATH); { Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true); if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) { throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)"); } if (serverNameParamMem!=null) { byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size()); serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length); } else { serverNameMem.setByte(0, (byte) 0); } } short result; if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECKFMOpen (phKFC64, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null); } else { result = NotesNativeAPI32.get().SECKFMOpen (phKFC32, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null); } NotesErrorUtils.checkResult(result); try { if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECidfPut(userNameCanonicalMem, passwordMem, idPathMem, phKFC64, serverNameMem, 0, (short) 0, null); } else { result = NotesNativeAPI32.get().SECidfPut(userNameCanonicalMem, passwordMem, idPathMem, phKFC32, serverNameMem, 0, (short) 0, null); } NotesErrorUtils.checkResult(result); } finally { if (PlatformUtils.is64Bit()) { result = NotesNativeAPI64.get().SECKFMClose(phKFC64, NotesConstants.SECKFM_close_WriteIdFile, 0, null); } else { result = NotesNativeAPI32.get().SECKFMClose(phKFC32, NotesConstants.SECKFM_close_WriteIdFile, 0, null); } NotesErrorUtils.checkResult(result); } int vaultServerNameLength = 0; for (int i=0; i<serverNameMem.size(); i++) { if (serverNameMem.getByte(i) == 0) { break; } else { vaultServerNameLength = i; } } String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength); return vaultServerName; } finally { anyServerDb.recycle(); } }
Example 17
Source File: NotesOOOUtils.java From domino-jna with Apache License 2.0 | 3 votes |
/** * OOO supports two sets of notification messages.<br> * They are called General message/subject and Special message/subject.<br> * The following text is always appended to the body of the message, where * the "Message subject" is obtained from the message which caused the * notification to be generated.<br> * <i>"Note: This is an automated response to your message "Message subject" * sent on 2/12/2009 10:12:17 AM. This is the only notification you will receive while this person is away."</i> * * @param msg message, max 65535 bytes LMBCS encoded (WORD datatype for length) */ public void setGeneralMessage(String msg) { checkHandle(); Memory msgMem = NotesStringUtils.toLMBCS(msg, false); if (msgMem.size() > 65535) throw new IllegalArgumentException("Message exceeds max length, "+msgMem.size() + "> 65535 bytes"); short result = NotesNativeAPI.get().OOOSetGeneralMessage(m_pOOOContext, msgMem, (short) (msgMem.size() & 0xffff)); NotesErrorUtils.checkResult(result); }