⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snap_svc_reg_handler.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
字号:
/*	snap service handler	registration handler source file	(c) 2003 Willem de Bruijn	all code falls under the BSD License*/#include "d_printf.h"#include "snap_svc_library_handler.h"#include "snap_svc_reg_table.h"#include "snap_svc_reg_handler.h"int snap_svc_register_initialized=0;tDllList hDllList = NULL;snap_svc_getlastresult pReturnLast;snap_svc_free_local_returnstruct pReturnFree;void snap_svc_register_init(){    hDllList = NULL;    snap_svc_register_initialized = 1;}void snap_svc_register_fini(){    if (!snap_svc_register_initialized)	    d_printf(50,"snap_svc : trying to close possibly unopened registration data\n");	else	    if(hDllList)		    snap_svc_unregisterall();				snap_svc_register_initialized = 0;}void* snap_svc_register_returnlaststruct(){    return pReturnLast();}void* snap_svc_register_freelaststruct(){    return pReturnFree();}int snap_svc_registerlib(void* hDll){    snap_svc_init pInit;	snap_svc_register pReg;	snapsvc_func_proto pDllFunc;	int dDllArgs, dDllRets;	char* strDllFuncName;		if (!hDll || (int) hDll == -1)	    d_printf(10,"snap_svc : error : registerlib called with NULL pointeror end condition occurred\n");	d_printf(100,"snap_svc : trying to bind the initialization function... \n");	if (snap_svc_bind(hDll,"init", (void**) &pInit))	    return -1;		pInit();	if (snap_svc_bind(hDll,"snap_external_svclib_getnextfunc", (void**) &pReg))		return -1;	if (snap_svc_bind(hDll,"snap_external_svclib_getlastresult", (void**) &pReturnLast))		return -1;	if (snap_svc_bind(hDll,"snap_external_svclib_free_local_returnstruct", (void**) &pReturnFree))		return -1;		do {		pReg(&strDllFuncName, &pDllFunc, &dDllArgs, &dDllRets);		if (strDllFuncName){			d_printf(100,"snap_svc : registered a function : (#rets = %d) %s (#args = %d)\n",dDllRets,strDllFuncName,dDllArgs);      		snap_svc_table_add(strDllFuncName, pDllFunc, dDllArgs, dDllRets);		}	} while (strDllFuncName != NULL);	d_printf(100,"snap_svc : all routines registered succesfully\n");		return 0;}int snap_svc_unregisterlib(void* hDll){    snap_svc_init pFini;		d_printf(100,"snap_svc : trying to bind the release function \n");	if (snap_svc_bind(hDll,"fini", (void**) &pFini))	    return -1;		pFini();		snap_svc_close(&hDll); 		return 0;}int snap_svc_registeralllibs(char* strDirectory){	int dSuccessCount, dCurEntry=0;		if (!strDirectory)	    return -1;		    if (hDllList)	    d_printf(50,"snap_svc : warning : possibly overwriting previous librarylist\n");			d_printf(100,"snap_svc : trying to open all libraries that start with libsnap_svc in %s\n", strDirectory);	dSuccessCount = snap_svc_openmultiple(&hDllList, strDirectory, snap_svc_openmultiple_selector_snapsvc);	d_printf(100, "dSuccessCount = %d\n", dSuccessCount);	if (dSuccessCount == -1)	    return -1;	while (hDllList[dCurEntry] && (int) hDllList[dCurEntry] != -1){	    d_printf(100, "dCurEntry = %d\n", dCurEntry);	    snap_svc_registerlib(hDllList[dCurEntry]);	    dCurEntry++;	}	d_printf(100,"snap_svc : opened %d files\n",dSuccessCount);		return dSuccessCount;}int snap_svc_unregisteralllibs(){    int dErrorCount=0, dCurEntry=0;    	if (!hDllList)	    return -1;	d_printf(100,"snap_svc : trying to close libraries\n");	while (hDllList[dCurEntry]){	    snap_svc_unregisterlib(hDllList[dCurEntry]);	    dCurEntry++;	}	dErrorCount += snap_svc_closemultiple(&hDllList);	d_printf(100,"snap_svc : closed %d files\n",dCurEntry-1);	return dErrorCount;}/* EASY ACCESS FUNCTIONS (register, unregister, reregister) */void snap_svc_registerall(){    if (!snap_svc_registeralllibs("/usr/local/lib")){	    if(!snap_svc_registeralllibs("/usr/lib")){		    if(!snap_svc_registeralllibs("/lib")){			    d_printf(50,"snap_svc : no suitable libraries found\n");			}		}    }}void snap_svc_unregisterall(){    snap_svc_unregisteralllibs();}void snap_svc_reregisterall(){	snap_svc_unregisterall();    snap_svc_registerall();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -