[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap-1.1-wjdb/lib/snap_svc_reg_table.cGo to the documentation of this file.00001 /* 00002 snap service handler 00003 registration table source file 00004 (c) 2003 Willem de Bruijn 00005 some code has been copied from the base SNAP package by Jon Moore 00006 all other code falls under the BSD License 00007 */ 00008 00009 #include <stdlib.h> 00010 #include <stddef.h> 00011 #include <snap_svc.h> 00012 00013 #include "d_printf.h" 00014 #include "hashtable.h" 00015 #include "snap_svc_reg_table.h" 00016 00017 static hash_table_t *svc_fun_tab; /* the hashtable used to store all service functions */ 00018 int snap_svc_table_initialized = 0; /* verify we're initialized correctly */ 00019 00020 /* helper function for hashtable lookups */ 00021 int mystrcmp(char *s1, char *s2) { 00022 while((*s1 != '\0') && (*s2 != '\0')) { 00023 if (*s1 < *s2) 00024 return -1; 00025 if (*s1 > *s2) 00026 return 1; 00027 s1++; 00028 s2++; 00029 } 00030 if ((*s1 == '\0') && (*s2 == '\0')) 00031 return 0; 00032 if (*s1 == '\0') 00033 return -1; 00034 return 1; 00035 } 00036 00037 void* snap_svc_table_find(char* strName){ 00038 return ht_lookup(svc_fun_tab, strName); 00039 } 00040 00041 /* insert a service function into the service table */ 00042 int snap_svc_table_add(char* strName, snapsvc_func_proto pFunc, int nargs, int nret) { 00043 struct snap_svc_rec *sr; 00044 00045 if (!snap_svc_table_initialized){ 00046 d_printf(50,"snap_svc : adding an entry to the hashtable without initializing it\n"); 00047 snap_svc_table_init(); 00048 } 00049 00050 if (! strName || !pFunc){ 00051 d_printf(50,"snap_svc : trying to register a function without name (%s) or pointer (%u)\n", strName, pFunc); 00052 return -1; 00053 } 00054 00055 if (nargs <0 || nret < 0){ 00056 d_printf(50,"snap_svc : trying to register a function with too few args (%d) or illegal retval (%d)\n", nargs, nret); 00057 return -1; 00058 } 00059 00060 sr = (struct snap_svc_rec*) malloc ( sizeof (struct snap_svc_rec)); 00061 if (sr == NULL) 00062 return -1; 00063 00064 /* fill the new structure */ 00065 sr->snapsvc_func = pFunc; 00066 sr->nargs = nargs; 00067 sr->nret = nret; 00068 00069 /* enter the structure into the hashtable */ 00070 ht_insert(svc_fun_tab, strName, sr); 00071 return 0; 00072 } 00073 00074 /* initialize the table*/ 00075 int snap_svc_table_init(){ 00076 00077 if (snap_svc_table_initialized){ 00078 d_printf(50,"snap_svc : reinitializing hashtable, skipping\n"); 00079 return 1; 00080 } 00081 00082 svc_fun_tab = ht_create(DEF_SVC_TAB_SZ, 00083 (int (*)(const void *,const void *))mystrcmp, 00084 (int (*)(void *))hash_string); 00085 00086 snap_svc_table_initialized = 1; 00087 00088 return 0; 00089 } 00090 00091 /* destroy the table */ 00092 int snap_svc_table_fini(){ 00093 00094 /* TODO : implement hashtable destroy code */ 00095 snap_svc_table_initialized = 0; 00096 00097 return 0; 00098 } |