[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_handler.cGo to the documentation of this file.00001 /* 00002 snap service handler 00003 main source file 00004 (c) 2003 Willem de Bruijn 00005 some code has been copied from the base SNAP package by Jon Moore 00006 all code falls under the BSD License 00007 */ 00008 00009 00010 #ifdef CONFIG_IP_SNAP_SVCS 00011 00012 #include <stdlib.h> 00013 00014 #include <snap_svc.h> 00015 00016 #include "d_printf.h" 00017 #include "snap_svc_conversion.h" 00018 #include "snap_svc_reg_table.h" 00019 #include "snap_svc_reg_handler.h" 00020 #include "snap_svc_handler.h" 00021 00022 int snap_svc_initialized = 0; 00023 00024 /* 00025 call a service 00026 00027 additionally, stack values are converted to function arguments 00028 and return values are converted to stack values and placed on 00029 the stack 00030 */ 00031 int snap_svc_call_service(packet_t *p, char *name) { 00032 struct snap_svc_rec *sr = NULL; 00033 void** args = NULL; 00034 void* returnptr = NULL; 00035 int i = 0; 00036 00037 if (!snap_svc_initialized || !p || !name){ 00038 d_printf(50,"snap_svc : tried to call a service incorrectly, skipping\n"); 00039 d_printf(100,"debugging code: init=%d packet=%u name=%s\n", snap_svc_initialized, p, name); 00040 } 00041 00042 d_printf(100,"%s:%d: looking up service \"%s\"\n",__FILE__,__LINE__,name); 00043 sr = snap_svc_table_find(name); 00044 if (sr == NULL) { 00045 d_printf(50,"%s:%d: service not found\n",__FILE__,__LINE__); 00046 return -1; 00047 } 00048 d_printf(50,"%s:%d: svc takes %d args and returns %d values\n",__FILE__,__LINE__,sr->nargs,sr->nret); 00049 00050 00051 /* convert the arguments */ 00052 if (sr->nargs){ 00053 args = (void**) snap_svc_convert_stack2arguments(p, sr->nargs); 00054 if (!args) 00055 return -1; 00056 } 00057 00058 /* now call the service */ 00059 d_printf(100,"%s:%d: about to call service...\n",__FILE__,__LINE__); 00060 switch (sr->nargs){ 00061 case 0 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(NULL); break; /* send a dummy variable, since every variable must take at least one parameter */ 00062 case 1 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(args[0]); break; 00063 case 2 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(args[0], args[1]); break; 00064 case 3 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(args[0], args[1], args[2]); break; 00065 case 4 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(args[0], args[1], args[2], args[3]); break; 00066 case 5 : returnptr = ((snapsvc_func_proto) (sr->snapsvc_func))(args[0], args[1], args[2], args[3], args[4]); break; 00067 default : d_printf(50,"snap : %s:%d: tried to call a function with too many arguments\n",__FILE__,__LINE__); 00068 } 00069 00070 /* push up the direct results, if any */ 00071 if (sr->nret != SVC_SNMP_TYPE_NULL) 00072 snap_svc_convert_direct2stack(p, returnptr, sr->nret); 00073 00074 /* check if it returned anything using a returnstruct */ 00075 returnptr = snap_svc_register_returnlaststruct(); 00076 if (returnptr){ 00077 d_printf(50,"snap : %s:%d: retrieved a result containing %d variables, ptr =(%p) \n",__FILE__,__LINE__,((struct svc_returnstruct*)returnptr)->length, returnptr); 00078 for (i=0; i < ((struct svc_returnstruct*) returnptr)->length; i++) 00079 snap_svc_convert_returnstruct2stack(p, p->sp, &((struct svc_returnstruct*) returnptr)->list[i]); 00080 returnptr = snap_svc_register_freelaststruct(); 00081 } 00082 free(args); 00083 00084 return 0; 00085 00086 } 00087 00088 /* load the services */ 00089 void snap_svc_handler_init() { 00090 00091 snap_svc_table_init(); /* initialize the hashtable */ 00092 snap_svc_registerall(); /* register services */ 00093 00094 snap_svc_initialized = 1; 00095 } 00096 00097 /* unload the services */ 00098 void snap_svc_handler_close() { 00099 00100 snap_svc_unregisterall(); /* register services */ 00101 snap_svc_table_fini(); /* initialize the hashtable */ 00102 00103 snap_svc_initialized = 1; 00104 } 00105 00106 /* reinitialize the services */ 00107 void snap_svc_handler_reinit(){ 00108 snap_svc_handler_close(); 00109 snap_svc_handler_init(); 00110 } 00111 #endif |