remove hungarian notation

This commit is contained in:
Doug MacEachern 2005-06-27 03:41:43 +00:00
parent ee4b71fc84
commit 547f584064
1 changed files with 82 additions and 89 deletions

View File

@ -33,7 +33,7 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_ChangeServiceDescription)
(JNIEnv *env, jclass, jlong handle, jstring description) (JNIEnv *env, jclass, jlong handle, jstring description)
{ {
jboolean result = FALSE; jboolean result = FALSE;
SERVICE_DESCRIPTION servdesc; SERVICE_DESCRIPTION desc;
HINSTANCE lib; HINSTANCE lib;
ChangeServiceConfig2_func_t change_config; ChangeServiceConfig2_func_t change_config;
@ -42,13 +42,13 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_ChangeServiceDescription)
GetProcAddress(lib, "ChangeServiceConfig2W"); GetProcAddress(lib, "ChangeServiceConfig2W");
if (change_config) { if (change_config) {
servdesc.lpDescription = desc.lpDescription =
(LPTSTR)env->GetStringChars(description, NULL); (LPTSTR)env->GetStringChars(description, NULL);
result = change_config((SC_HANDLE)handle, result = change_config((SC_HANDLE)handle,
SERVICE_CONFIG_DESCRIPTION, &servdesc); SERVICE_CONFIG_DESCRIPTION, &desc);
env->ReleaseStringChars(description, env->ReleaseStringChars(description,
(const jchar *)servdesc.lpDescription); (const jchar *)desc.lpDescription);
} }
FreeLibrary(lib); FreeLibrary(lib);
@ -68,99 +68,94 @@ JNIEXPORT void SIGAR_JNI(win32_Service_ControlService)
{ {
BOOL retval; BOOL retval;
SERVICE_STATUS status; SERVICE_STATUS status;
if (control == 0) { if (control == 0) {
retval = StartService((SC_HANDLE)handle, 0, NULL); retval = StartService((SC_HANDLE)handle, 0, NULL);
} }
else { else {
retval = ControlService((SC_HANDLE)handle, control, &status); retval = ControlService((SC_HANDLE)handle, control, &status);
} }
if (!retval) { if (!retval) {
win32_throw_last_error(env); win32_throw_last_error(env);
} }
} }
JNIEXPORT jlong SIGAR_JNI(win32_Service_CreateService) JNIEXPORT jlong SIGAR_JNI(win32_Service_CreateService)
(JNIEnv *env, (JNIEnv *env, jclass, jlong handle,
jclass, jstring j_name, jstring j_display, jint type,
jlong handle, jint startType, jint errorControl, jstring j_path,
jstring serviceName,
jstring displayName,
jint serviceType,
jint startType,
jint errorControl,
jstring path,
jobjectArray dependencies, jobjectArray dependencies,
jstring startName, jstring j_startName,
jstring password) jstring j_password)
{ {
TCHAR szBuf[4048]; TCHAR buffer[8192];
LPCTSTR lpDepend = NULL; LPCTSTR depend = NULL;
jlong lResult; jlong result;
LPCTSTR lpStartName; LPCTSTR startName;
LPCTSTR name = (LPCTSTR)env->GetStringChars(j_name, NULL);
LPCTSTR display = (LPCTSTR)env->GetStringChars(j_display, NULL);
LPCTSTR path = (LPCTSTR)env->GetStringChars(j_path, NULL);
LPCTSTR password = (LPCTSTR)env->GetStringChars(j_password, NULL);
LPCTSTR lpServiceName = (LPCTSTR)env->GetStringChars(serviceName, NULL); if (j_startName != NULL) {
LPCTSTR lpDisplayName = (LPCTSTR)env->GetStringChars(displayName, NULL); startName = (LPCTSTR)env->GetStringChars(j_startName, NULL);
LPCTSTR lpPath = (LPCTSTR)env->GetStringChars(path, NULL); }
LPCTSTR lpPassword = (LPCTSTR)env->GetStringChars(password, NULL); else {
startName = NULL;
}
if(startName != NULL) if (dependencies != NULL) {
lpStartName = (LPCTSTR)env->GetStringChars(path, NULL);
else
lpStartName = NULL;
if(dependencies != NULL)
{
// Build a buffer of a double null terminated array of // Build a buffer of a double null terminated array of
// null terminated service names // null terminated service names
lpDepend = szBuf; LPTSTR ptr = buffer;
jsize alen = env->GetArrayLength(dependencies);
depend = buffer;
LPTSTR lpBuf = szBuf; for (int i=0; i<alen; i++) {
size_t cbLen = 0;
jsize cSize = env->GetArrayLength(dependencies);
for(int i = 0;i < cSize;i ++)
{
jstring str = (jstring)env->GetObjectArrayElement(dependencies, i); jstring str = (jstring)env->GetObjectArrayElement(dependencies, i);
LPCTSTR chars = (LPCTSTR)env->GetStringChars(str, NULL);
LPCTSTR lpStr = (LPCTSTR)env->GetStringChars(str, NULL); size_t len = lstrlen(chars);
cbLen = lstrlen(lpStr);
// If we're going to overrun the buffer then break out of the loop // If we're going to overrun the buffer then break out of the loop
if((lpBuf + cbLen + 1) >= (szBuf + sizeof(szBuf) / sizeof(TCHAR))) if ((ptr + len + 1) >=
(buffer + sizeof(buffer) / sizeof(TCHAR)))
{
break; break;
}
lstrcpy(lpBuf, lpStr); lstrcpy(ptr, chars);
env->ReleaseStringChars(str, (const jchar *)lpStr); env->ReleaseStringChars(str, (const jchar *)chars);
// Move the buffer to the byte beyond the current string // Move the buffer to the byte beyond the current string
// null terminator // null terminator
lpBuf = lpBuf + cbLen + 1; ptr = ptr + len + 1;
} }
*lpBuf = 0; // Double null terminate the string *ptr = 0; // Double null terminate the string
} }
// Create the Service // Create the Service
lResult = (jlong)CreateService((SC_HANDLE)handle, lpServiceName, result = (jlong)CreateService((SC_HANDLE)handle, name,
lpDisplayName, SERVICE_ALL_ACCESS, display, SERVICE_ALL_ACCESS,
serviceType, type,
startType, errorControl, lpPath, startType, errorControl, path,
NULL, NULL, lpDepend, lpStartName, NULL, NULL, depend, startName,
lpPassword); password);
if(lpStartName != NULL) if (startName != NULL) {
env->ReleaseStringChars(path, (const jchar *)lpStartName); env->ReleaseStringChars(j_startName, (const jchar *)startName);
}
env->ReleaseStringChars(j_password, (const jchar *)password);
env->ReleaseStringChars(j_path, (const jchar *)path);
env->ReleaseStringChars(j_display, (const jchar *)display);
env->ReleaseStringChars(j_name, (const jchar *)name);
env->ReleaseStringChars(password, (const jchar *)lpPassword); if (result == 0) {
env->ReleaseStringChars(path, (const jchar *)lpPath);
env->ReleaseStringChars(displayName, (const jchar *)lpDisplayName);
env->ReleaseStringChars(serviceName, (const jchar *)lpServiceName);
if (lResult == 0) {
win32_throw_last_error(env); win32_throw_last_error(env);
} }
return lResult; return result;
} }
JNIEXPORT void SIGAR_JNI(win32_Service_DeleteService) JNIEXPORT void SIGAR_JNI(win32_Service_DeleteService)
@ -172,39 +167,35 @@ JNIEXPORT void SIGAR_JNI(win32_Service_DeleteService)
} }
JNIEXPORT jlong SIGAR_JNI(win32_Service_OpenSCManager) JNIEXPORT jlong SIGAR_JNI(win32_Service_OpenSCManager)
(JNIEnv *env, jclass, jstring machine, jint access) (JNIEnv *env, jclass, jstring jmachine, jint access)
{ {
jlong lResult; LPCTSTR machine = (LPCTSTR)env->GetStringChars(jmachine, NULL);
jlong result = (jlong)OpenSCManager(machine, NULL, access);
LPCTSTR lpMachine = (LPCTSTR)env->GetStringChars(machine, NULL); env->ReleaseStringChars(jmachine, (const jchar *)machine);
lResult = (jlong)OpenSCManager(lpMachine, NULL, access);
env->ReleaseStringChars(machine, (const jchar *)lpMachine);
if (!lResult) { if (!result) {
win32_throw_last_error(env); win32_throw_last_error(env);
} }
return lResult; return result;
} }
JNIEXPORT jlong SIGAR_JNI(win32_Service_OpenService) JNIEXPORT jlong SIGAR_JNI(win32_Service_OpenService)
(JNIEnv *env, (JNIEnv *env, jclass, jlong handle,
jclass, jstring jservice, jint access)
jlong handle,
jstring service,
jint access)
{ {
jlong lResult; LPCTSTR service = (LPCTSTR)env->GetStringChars(jservice, NULL);
LPCTSTR lpService = (LPCTSTR)env->GetStringChars(service, NULL); jlong result =
lResult = (jlong)OpenService((SC_HANDLE)handle, (jlong)OpenService((SC_HANDLE)handle, service, access);
lpService, access);
env->ReleaseStringChars(service, (const jchar *)lpService);
if (!lResult) { env->ReleaseStringChars(jservice, (const jchar *)service);
if (!result) {
win32_throw_last_error(env); win32_throw_last_error(env);
} }
return lResult; return result;
} }
JNIEXPORT jint JNIEXPORT jint
@ -212,14 +203,16 @@ SIGAR_JNI(win32_Service_QueryServiceStatus)
(JNIEnv *, jclass, jlong handle) (JNIEnv *, jclass, jlong handle)
{ {
SERVICE_STATUS status; SERVICE_STATUS status;
int iResult; int result;
if (QueryServiceStatus((SC_HANDLE)handle, &status) == TRUE) { if (QueryServiceStatus((SC_HANDLE)handle, &status) == TRUE) {
iResult = status.dwCurrentState; result = status.dwCurrentState;
} else }
iResult = -1; else {
result = -1;
}
return iResult; return result;
} }
JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames) JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames)
@ -251,7 +244,7 @@ JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames)
DWORD err = GetLastError(); DWORD err = GetLastError();
if ((retval == FALSE) || err == ERROR_MORE_DATA) { if ((retval == FALSE) || (err == ERROR_MORE_DATA)) {
DWORD size = bytes + sizeof(ENUM_SERVICE_STATUS); DWORD size = bytes + sizeof(ENUM_SERVICE_STATUS);
services = new ENUM_SERVICE_STATUS[size]; services = new ENUM_SERVICE_STATUS[size];
EnumServicesStatus(handle, type, state, services, EnumServicesStatus(handle, type, state, services,
@ -301,7 +294,7 @@ static int to_array(JNIEnv *env, LPTSTR str, jobjectArray array)
JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig) JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
(JNIEnv *env, jclass, jlong handle, jobject obj) (JNIEnv *env, jclass, jlong handle, jobject obj)
{ {
char buffer[8096]; /* 8k is max size from mdsn docs */ char buffer[8192]; /* 8k is max size from mdsn docs */
LPQUERY_SERVICE_CONFIG config = (LPQUERY_SERVICE_CONFIG)buffer; LPQUERY_SERVICE_CONFIG config = (LPQUERY_SERVICE_CONFIG)buffer;
DWORD bytes; DWORD bytes;
jfieldID id; jfieldID id;