2014-11-13 17:20:55 +00:00
|
|
|
/* Override the global definition QSE_ENABLE_STATIC_MODULE
|
|
|
|
* for httpd on platforms with mature dynamic loading support.
|
|
|
|
*/
|
|
|
|
#if defined(QSE_ENABLE_STATIC_MODULE) && \
|
|
|
|
(defined(USE_LTDL) || defined(_WIN32) || defined(__OS2__))
|
|
|
|
# undef QSE_ENABLE_STATIC_MODULE
|
|
|
|
#endif
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
|
2014-09-03 16:57:33 +00:00
|
|
|
{
|
2014-11-14 02:31:47 +00:00
|
|
|
#if defined(USE_LTDL)
|
2014-09-03 16:57:33 +00:00
|
|
|
void* h;
|
2014-09-05 15:52:19 +00:00
|
|
|
qse_mchar_t* modpath;
|
2014-09-04 16:55:45 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
modpath = sysname;
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
|
2014-09-05 15:52:19 +00:00
|
|
|
if (!modpath)
|
2014-09-03 16:57:33 +00:00
|
|
|
{
|
2014-09-05 15:52:19 +00:00
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
|
|
|
|
return QSE_NULL;
|
2014-09-03 16:57:33 +00:00
|
|
|
}
|
2014-09-05 15:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
h = lt_dlopenext (modpath);
|
|
|
|
if (!h) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* do nothing */
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
|
2014-09-05 15:52:19 +00:00
|
|
|
#endif
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
return h;
|
2014-09-03 16:57:33 +00:00
|
|
|
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
|
|
|
|
HMODULE h;
|
2014-09-04 16:55:45 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
h = LoadLibrary (sysname);
|
2014-10-19 12:50:51 +00:00
|
|
|
if (!h) qse_httpd_seterrnum (httpd, syserr_to_errnum(GetLastError()));
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
|
|
|
return h;
|
2014-09-03 16:57:33 +00:00
|
|
|
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
|
|
|
|
HMODULE h;
|
2014-09-05 15:52:19 +00:00
|
|
|
qse_mchar_t* modpath;
|
2014-09-03 16:57:33 +00:00
|
|
|
char errbuf[CCHMAXPATH];
|
|
|
|
APIRET rc;
|
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
modpath = sysname;
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
|
2014-09-05 15:52:19 +00:00
|
|
|
if (!modpath)
|
|
|
|
{
|
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
|
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-03 16:57:33 +00:00
|
|
|
|
|
|
|
/* DosLoadModule() seems to have severe limitation on
|
|
|
|
* the file name it can load (max-8-letters.xxx) */
|
|
|
|
rc = DosLoadModule (errbuf, QSE_COUNTOF(errbuf) - 1, modpath, &h);
|
2014-09-04 16:55:45 +00:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
qse_httpd_seterrnum (httpd, syserr_to_errnum(rc));
|
2014-09-05 15:52:19 +00:00
|
|
|
h = QSE_NULL;
|
2014-09-04 16:55:45 +00:00
|
|
|
}
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* do nothing */
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
|
2014-09-05 15:52:19 +00:00
|
|
|
#endif
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
|
|
|
return h;
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-11-14 02:31:47 +00:00
|
|
|
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
|
2014-09-03 16:57:33 +00:00
|
|
|
|
|
|
|
/* the DOS code here is not generic enough. it's for a specific
|
2014-11-14 02:31:47 +00:00
|
|
|
* dos-extender only. the best is to disable dynamic loading
|
2014-09-03 16:57:33 +00:00
|
|
|
* when building for DOS. */
|
|
|
|
void* h;
|
2014-09-05 15:52:19 +00:00
|
|
|
qse_mchar_t* modpath;
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
modpath = sysname;
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
|
2014-09-05 15:52:19 +00:00
|
|
|
if (!modpath)
|
2014-09-04 16:55:45 +00:00
|
|
|
{
|
2014-09-05 15:52:19 +00:00
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
|
|
|
|
return QSE_NULL;
|
2014-09-04 16:55:45 +00:00
|
|
|
}
|
2014-09-05 15:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
h = LoadModule (modpath);
|
|
|
|
if (!h) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* do nothing */
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
|
2014-09-05 15:52:19 +00:00
|
|
|
#endif
|
2014-09-03 16:57:33 +00:00
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
|
|
|
return h;
|
2018-06-26 08:30:02 +00:00
|
|
|
#elif defined(USE_DLFCN)
|
|
|
|
|
|
|
|
void* h;
|
|
|
|
qse_mchar_t* modpath;
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
modpath = sysname;
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
|
2018-06-26 08:30:02 +00:00
|
|
|
if (!modpath)
|
|
|
|
{
|
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
|
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
h = dlopen(modpath, RTLD_NOW);
|
|
|
|
if (!h) qse_httpd_seterrnum (httpd, QSE_HTTPD_ESYSERR);
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* do nothing */
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
|
2018-06-26 08:30:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return h;
|
2014-09-03 16:57:33 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
2014-09-05 15:52:19 +00:00
|
|
|
return QSE_NULL;
|
2014-09-03 16:57:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
static void mod_close (qse_httpd_t* httpd, void* handle)
|
2014-09-03 16:57:33 +00:00
|
|
|
{
|
2014-11-14 02:31:47 +00:00
|
|
|
#if defined(USE_LTDL)
|
2014-09-05 15:52:19 +00:00
|
|
|
lt_dlclose (handle);
|
2014-09-03 16:57:33 +00:00
|
|
|
#elif defined(_WIN32)
|
2014-09-05 15:52:19 +00:00
|
|
|
FreeLibrary ((HMODULE)handle);
|
2014-09-03 16:57:33 +00:00
|
|
|
#elif defined(__OS2__)
|
2014-09-05 15:52:19 +00:00
|
|
|
DosFreeModule ((HMODULE)handle);
|
2014-11-14 02:31:47 +00:00
|
|
|
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
|
2014-09-05 15:52:19 +00:00
|
|
|
FreeModule (handle);
|
2018-06-26 08:30:02 +00:00
|
|
|
#elif defined(USE_DLFCN)
|
|
|
|
dlclose (handle);
|
2014-09-03 16:57:33 +00:00
|
|
|
#else
|
|
|
|
/* nothing to do */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-05 15:52:19 +00:00
|
|
|
static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* name)
|
2014-09-03 16:57:33 +00:00
|
|
|
{
|
|
|
|
void* s;
|
|
|
|
qse_mchar_t* mname;
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
mname = name;
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
mname = qse_wcstombsdup (name, QSE_NULL, qse_httpd_getmmgr(httpd));
|
2014-09-03 16:57:33 +00:00
|
|
|
if (!mname)
|
|
|
|
{
|
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
|
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-19 12:50:51 +00:00
|
|
|
|
2014-11-14 02:31:47 +00:00
|
|
|
#if defined(USE_LTDL)
|
2014-09-05 15:52:19 +00:00
|
|
|
s = lt_dlsym (handle, mname);
|
2014-09-04 16:55:45 +00:00
|
|
|
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
2014-09-03 16:57:33 +00:00
|
|
|
#elif defined(_WIN32)
|
2014-09-05 15:52:19 +00:00
|
|
|
s = GetProcAddress ((HMODULE)handle, mname);
|
2014-09-04 16:55:45 +00:00
|
|
|
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(GetLastError()));
|
2014-09-03 16:57:33 +00:00
|
|
|
#elif defined(__OS2__)
|
2014-09-04 16:55:45 +00:00
|
|
|
{
|
|
|
|
APIRET rc;
|
2014-09-05 15:52:19 +00:00
|
|
|
rc = DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s);
|
2014-09-04 16:55:45 +00:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
qse_httpd_seterrnum (httpd, syserr_to_errnum(rc));
|
|
|
|
s = QSE_NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 02:31:47 +00:00
|
|
|
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
|
2014-09-05 15:52:19 +00:00
|
|
|
s = GetProcAddress (handle, mname);
|
2014-09-04 16:55:45 +00:00
|
|
|
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
2018-06-26 08:30:02 +00:00
|
|
|
#elif defined(USE_DLFCN)
|
|
|
|
s = dlsym (handle, mname);
|
|
|
|
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, QSE_HTTPD_ESYSERR);
|
2014-09-03 16:57:33 +00:00
|
|
|
#else
|
|
|
|
s = QSE_NULL;
|
2014-09-04 16:55:45 +00:00
|
|
|
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
2014-09-03 16:57:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* nothing to do */
|
|
|
|
#else
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), mname);
|
2014-09-03 16:57:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|