libprews.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <netware.h>
  17. #include <library.h>
  18. #include <nks/synch.h>
  19. #ifdef USE_WINSOCK
  20. #include "novsock2.h"
  21. #endif
  22. #include "fspr_pools.h"
  23. #include "fspr_private.h"
  24. /* library-private data...*/
  25. int gLibId = -1;
  26. void *gLibHandle = (void *) NULL;
  27. NXMutex_t *gLibLock = (NXMutex_t *) NULL;
  28. /* internal library function prototypes...*/
  29. int DisposeLibraryData(void *);
  30. int _NonAppStart
  31. (
  32. void *NLMHandle,
  33. void *errorScreen,
  34. const char *cmdLine,
  35. const char *loadDirPath,
  36. size_t uninitializedDataLength,
  37. void *NLMFileHandle,
  38. int (*readRoutineP)( int conn, void *fileHandle, size_t offset,
  39. size_t nbytes, size_t *bytesRead, void *buffer ),
  40. size_t customDataOffset,
  41. size_t customDataSize,
  42. int messageCount,
  43. const char **messages
  44. )
  45. {
  46. #ifdef USE_WINSOCK
  47. WSADATA wsaData;
  48. #endif
  49. fspr_status_t status;
  50. NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
  51. #pragma unused(cmdLine)
  52. #pragma unused(loadDirPath)
  53. #pragma unused(uninitializedDataLength)
  54. #pragma unused(NLMFileHandle)
  55. #pragma unused(readRoutineP)
  56. #pragma unused(customDataOffset)
  57. #pragma unused(customDataSize)
  58. #pragma unused(messageCount)
  59. #pragma unused(messages)
  60. gLibId = register_library(DisposeLibraryData);
  61. if (gLibId < -1)
  62. {
  63. OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
  64. return -1;
  65. }
  66. gLibHandle = NLMHandle;
  67. gLibLock = NXMutexAlloc(0, 0, &liblock);
  68. if (!gLibLock)
  69. {
  70. OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
  71. return -1;
  72. }
  73. fspr_netware_setup_time();
  74. if ((status = fspr_pool_initialize()) != APR_SUCCESS)
  75. return status;
  76. #ifdef USE_WINSOCK
  77. return WSAStartup((WORD) MAKEWORD(2, 0), &wsaData);
  78. #else
  79. return 0;
  80. #endif
  81. }
  82. void _NonAppStop( void )
  83. {
  84. fspr_pool_terminate();
  85. #ifdef USE_WINSOCK
  86. WSACleanup();
  87. #endif
  88. unregister_library(gLibId);
  89. NXMutexFree(gLibLock);
  90. }
  91. int _NonAppCheckUnload( void )
  92. {
  93. return 0;
  94. }
  95. int register_NLM(void *NLMHandle)
  96. {
  97. APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
  98. NXLock(gLibLock);
  99. if (!app_data) {
  100. app_data = (APP_DATA*)library_malloc(gLibHandle, sizeof(APP_DATA));
  101. if (app_data) {
  102. memset (app_data, 0, sizeof(APP_DATA));
  103. set_app_data(gLibId, app_data);
  104. app_data->gs_nlmhandle = NLMHandle;
  105. }
  106. }
  107. if (app_data && (!app_data->initialized)) {
  108. app_data->initialized = 1;
  109. NXUnlock(gLibLock);
  110. return 0;
  111. }
  112. NXUnlock(gLibLock);
  113. return 1;
  114. }
  115. int unregister_NLM(void *NLMHandle)
  116. {
  117. APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
  118. NXLock(gLibLock);
  119. if (app_data) {
  120. app_data->initialized = 0;
  121. NXUnlock(gLibLock);
  122. return 0;
  123. }
  124. NXUnlock(gLibLock);
  125. return 1;
  126. }
  127. int DisposeLibraryData(void *data)
  128. {
  129. if (data)
  130. {
  131. library_free(data);
  132. }
  133. return 0;
  134. }
  135. int setGlobalPool(void *data)
  136. {
  137. APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
  138. NXLock(gLibLock);
  139. if (app_data && !app_data->gPool) {
  140. app_data->gPool = data;
  141. }
  142. NXUnlock(gLibLock);
  143. return 1;
  144. }
  145. void* getGlobalPool()
  146. {
  147. APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
  148. if (app_data) {
  149. return app_data->gPool;
  150. }
  151. return NULL;
  152. }