1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1997-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * Glenn Fowler
23  * AT&T Research
24  */
25 
26 #include "dlllib.h"
27 
28 /*
29  * return plugin version for dll
30  * 0 if there is none
31  * path!=0 enables library level diagnostics
32  */
33 
34 extern unsigned long
dllversion(void * dll,const char * path)35 dllversion(void* dll, const char* path)
36 {
37 	Dll_plugin_version_f	pvf;
38 
39 	if (pvf = (Dll_plugin_version_f)dlllook(dll, "plugin_version"))
40 		return (*pvf)();
41 	if (path)
42 	{
43 		state.error = 1;
44 		sfsprintf(state.errorbuf, sizeof(state.errorbuf), "plugin_version() not found");
45 		errorf("dll", NiL, 1, "dllversion: %s: %s", path, state.errorbuf);
46 	}
47 	return 0;
48 }
49 
50 /*
51  * check if dll on path has plugin version >= ver
52  * 1 returned on success, 0 on failure
53  * path!=0 enables library level diagnostics
54  * cur!=0 gets actual version
55  */
56 
57 extern int
dllcheck(void * dll,const char * path,unsigned long ver,unsigned long * cur)58 dllcheck(void* dll, const char* path, unsigned long ver, unsigned long* cur)
59 {
60 	unsigned long		v;
61 
62 	state.error = 0;
63 	if (ver || cur)
64 	{
65 		v = dllversion(dll, path);
66 		if (cur)
67 			*cur = v;
68 	}
69 	if (!ver)
70 		return 1;
71 	if (!v)
72 		return 0;
73 	if (v < ver)
74 	{
75 		if (path)
76 		{
77 			state.error = 1;
78 			sfsprintf(state.errorbuf, sizeof(state.errorbuf), "plugin version %lu older than caller %lu", v, ver);
79 			errorf("dll", NiL, 1, "dllcheck: %s: %s", path, state.errorbuf);
80 		}
81 		return 0;
82 	}
83 	errorf("dll", NiL, -1, "dllversion: %s: %lu >= %lu", path, v, ver);
84 	return 1;
85 }
86