Fixes for Win32 build.
[openssl.git] / crypto / dso / dso_win32.c
index e204b6b07bd916512d27aa6d8c51375ea9575459..d613fbf378be72d15e6b8372daf874c13fcddd09 100644 (file)
@@ -73,9 +73,11 @@ DSO_METHOD *DSO_METHOD_win32(void)
 
 static int win32_load(DSO *dso, const char *filename);
 static int win32_unload(DSO *dso);
-static int win32_bind(DSO *dso, const char *symname, void **symptr);
+static void *win32_bind_var(DSO *dso, const char *symname);
+static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
 #if 0
-static int win32_unbind(DSO *dso, char *symname, void *symptr);
+static int win32_unbind_var(DSO *dso, char *symname, void *symptr);
+static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
 static int win32_init(DSO *dso);
 static int win32_finish(DSO *dso);
 #endif
@@ -85,10 +87,12 @@ static DSO_METHOD dso_meth_win32 = {
        "OpenSSL 'win32' shared library method",
        win32_load,
        win32_unload,
-       win32_bind,
+       win32_bind_var,
+       win32_bind_func,
 /* For now, "unbind" doesn't exist */
 #if 0
-       NULL, /* unbind */
+       NULL, /* unbind_var */
+       NULL, /* unbind_func */
 #endif
        win32_ctrl,
        NULL, /* init */
@@ -137,14 +141,14 @@ static int win32_load(DSO *dso, const char *filename)
        if(p == NULL)
                {
                DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE);
-               OPENSSL_freeLibrary(h);
+                FreeLibrary(h);
                return(0);
                }
        *p = h;
        if(!sk_push(dso->meth_data, (char *)p))
                {
                DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
-               OPENSSL_freeLibrary(h);
+                FreeLibrary(h);
                OPENSSL_free(p);
                return(0);
                }
@@ -167,7 +171,7 @@ static int win32_unload(DSO *dso)
                DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE);
                return(0);
                }
-       if(!OPENSSL_freeLibrary(p))
+        if(!FreeLibrary(*p))
                {
                DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED);
                /* We should push the value back onto the stack in
@@ -180,35 +184,66 @@ static int win32_unload(DSO *dso)
        return(1);
        }
 
-static int win32_bind(DSO *dso, const char *symname, void **symptr)
+/* Using GetProcAddress for variables? TODO: Check this out in
+ * the Win32 API docs, there's probably a variant for variables. */
+static void *win32_bind_var(DSO *dso, const char *symname)
        {
        HINSTANCE *ptr;
        void *sym;
 
-       if((dso == NULL) || (symptr == NULL) || (symname == NULL))
+       if((dso == NULL) || (symname == NULL))
                {
-               DSOerr(DSO_F_WIN32_BIND,ERR_R_PASSED_NULL_PARAMETER);
-               return(0);
+               DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
+               return(NULL);
                }
        if(sk_num(dso->meth_data) < 1)
                {
-               DSOerr(DSO_F_WIN32_BIND,DSO_R_STACK_ERROR);
-               return(0);
+               DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR);
+               return(NULL);
                }
        ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
-               DSOerr(DSO_F_WIN32_BIND,DSO_R_NULL_HANDLE);
-               return(0);
+               DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE);
+               return(NULL);
                }
        sym = GetProcAddress(*ptr, symname);
        if(sym == NULL)
                {
-               DSOerr(DSO_F_WIN32_BIND,DSO_R_SYM_FAILURE);
-               return(0);
+               DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE);
+               return(NULL);
                }
-       *symptr = sym;
-       return(1);
+       return(sym);
+       }
+
+static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
+       {
+       HINSTANCE *ptr;
+       void *sym;
+
+       if((dso == NULL) || (symname == NULL))
+               {
+               DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
+               return(NULL);
+               }
+       if(sk_num(dso->meth_data) < 1)
+               {
+               DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR);
+               return(NULL);
+               }
+       ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       if(ptr == NULL)
+               {
+               DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE);
+               return(NULL);
+               }
+       sym = GetProcAddress(*ptr, symname);
+       if(sym == NULL)
+               {
+               DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE);
+               return(NULL);
+               }
+       return((DSO_FUNC_TYPE)sym);
        }
 
 static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg)