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

📄 snap_svc_reg_table.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
字号:
/*	snap service handler	registration table source file	(c) 2003 Willem de Bruijn    some code has been copied from the base SNAP package by Jon Moore	all other code falls under the BSD License*/#include <stdlib.h>#include <stddef.h>#include <snap_svc.h>#include "d_printf.h" #include "hashtable.h"#include "snap_svc_reg_table.h"static hash_table_t *svc_fun_tab; /* the hashtable used to store all service functions */int snap_svc_table_initialized = 0; /* verify we're initialized correctly *//* helper function for hashtable lookups */int mystrcmp(char *s1, char *s2) {  while((*s1 != '\0') && (*s2 != '\0')) {    if (*s1 < *s2)      return -1;    if (*s1 > *s2)      return 1;    s1++;    s2++;  }  if ((*s1 == '\0') && (*s2 == '\0'))    return 0;  if (*s1 == '\0')    return -1;  return 1;}void* snap_svc_table_find(char* strName){    return ht_lookup(svc_fun_tab, strName);}/* insert a service function into the service table */int snap_svc_table_add(char* strName, snapsvc_func_proto pFunc, int nargs, int nret) {  struct snap_svc_rec *sr;  if (!snap_svc_table_initialized){    d_printf(50,"snap_svc : adding an entry to the hashtable without initializing it\n");    snap_svc_table_init();  }    if (! strName || !pFunc){    d_printf(50,"snap_svc : trying to register a function without name (%s) or pointer (%u)\n", strName, pFunc);	return -1;  }  if (nargs <0 || nret < 0){    d_printf(50,"snap_svc : trying to register a function with too few args (%d) or illegal retval (%d)\n", nargs, nret);	return -1;  }        sr = (struct snap_svc_rec*) malloc ( sizeof (struct snap_svc_rec));  if (sr == NULL)     return -1;	  /* fill the new structure */  sr->snapsvc_func = pFunc;  sr->nargs = nargs;  sr->nret = nret;  /* enter the structure into the hashtable */  ht_insert(svc_fun_tab, strName, sr);  return 0;}/* initialize the table*/int snap_svc_table_init(){	if (snap_svc_table_initialized){		d_printf(50,"snap_svc : reinitializing hashtable, skipping\n");		return 1;	}      svc_fun_tab = ht_create(DEF_SVC_TAB_SZ,  			  (int (*)(const void *,const void *))mystrcmp,			  (int (*)(void *))hash_string);    	snap_svc_table_initialized = 1;		return 0;}/* destroy the table */int snap_svc_table_fini(){        /* TODO : implement hashtable destroy code */	snap_svc_table_initialized = 0;		return 0;}

⌨️ 快捷键说明

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