[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

SourceForge.net Logo

osi-open source certified logo

Splash - Documentation

SNMP Plus a Lightweight API for SNAP Handling

Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

snap_svc/snap_svc_memmap.c

Go to the documentation of this file.
00001 /* snap service library                 */
00002 /* (c) Willem de Bruijn, 2002, 2003     */
00003 /* Licensed under the BSD License       */
00004 /* snap_svc_memmap library sourcefile   */
00005 
00006 /* libc includes */
00007 #include <string.h>
00008 
00009 /* local includes */
00010 #include "d_printf.h"
00011 #include "snap_svc.h"
00012 #include "snap_svc_memmap_hash.h"
00013 #include "snap_svc_memmap.h"
00014 
00015 hash_table_t *snap_svc_memmap_hashtable = NULL; /* the hashtable used to store all service functions */
00016 
00017 /* helper function for hashtable lookups */
00018 int mystrcmp(char *s1, char *s2) {
00019   while((*s1 != '\0') && (*s2 != '\0')) {
00020     if (*s1 < *s2)
00021       return -1;
00022     if (*s1 > *s2)
00023       return 1;
00024     s1++;
00025     s2++;
00026   }
00027   if ((*s1 == '\0') && (*s2 == '\0'))
00028     return 0;
00029   if (*s1 == '\0')
00030     return -1;
00031   return 1;
00032 }
00033 
00034 /* library handling functions */
00035 void snap_external_svclib_init(){
00036     /* create the hashtable */
00037      snap_svc_memmap_hashtable = ht_create(100,
00038               (int (*)(const void *,const void *))mystrcmp,
00039               (int (*)(void *))hash_string);
00040               
00041               
00042     d_printf(50,"snap_svc_memmap : initialized\n");
00043 }
00044 
00045 void snap_external_svclib_done(){
00046     /* TODO delete the hashtable */
00047     d_printf(50,"snap_svc_memmap : closed\n");
00048 }
00049 
00050 /* there is where functions inside the library should be listed for registration */
00051 void snap_external_svclib_getnextfunc(char** snapsvc_name, snapsvc_func_proto* snapsvc_func, int* snapsvc_args, int* snapsvc_rets){
00052 
00053     switch (svc_fun_counter){
00054         case 0  :       (*snapsvc_name) = strdup ("memmap_addint");
00055                         (*snapsvc_func) = (snapsvc_func_proto) &snap_svc_memmap_add_value;
00056                         (*snapsvc_args) = 2;
00057                         (*snapsvc_rets) = SVC_SNMP_TYPE_NULL;
00058                         break;
00059         case 1  :       (*snapsvc_name) = strdup ("memmap_addstr");
00060                         (*snapsvc_func) = (snapsvc_func_proto) &snap_svc_memmap_add_string;
00061                         (*snapsvc_args) = 2;
00062                         (*snapsvc_rets) = SVC_SNMP_TYPE_NULL;
00063                         break;
00064         case 2  :       (*snapsvc_name) = strdup ("memmap_getint");
00065                         (*snapsvc_func) = (snapsvc_func_proto) &snap_svc_memmap_lookup_int;
00066                         (*snapsvc_args) = 1;
00067                         (*snapsvc_rets) = SVC_SNMP_TYPE_INT;
00068                         break;
00069         case 3  :       (*snapsvc_name) = strdup ("memmap_getstr");
00070                         (*snapsvc_func) = (snapsvc_func_proto) &snap_svc_memmap_lookup_string;
00071                         (*snapsvc_args) = 1;
00072                         (*snapsvc_rets) = SVC_SNMP_TYPE_STRING;
00073                         break;
00074         case 4  :       (*snapsvc_name) = strdup ("memmap_del");
00075                         (*snapsvc_func) = (snapsvc_func_proto) &snap_svc_memmap_del;
00076                         (*snapsvc_args) = 1;
00077                         (*snapsvc_rets) = SVC_SNMP_TYPE_NULL;
00078                         break;
00079         /* unknown handler -> return NULL as end-of-list symbol */
00080         default :   (*snapsvc_name) = NULL;
00081                     (*snapsvc_func) = NULL;
00082                     (*snapsvc_args) = 0;
00083                     (*snapsvc_rets) = 0;
00084     }
00085     svc_fun_counter ++;
00086 }
00087 
00088 /* ADD SERVICES BELOW */
00089 /* declarations of snap service handlers */
00090 
00091 void snap_svc_memmap_add_value(char* key, unsigned long pValue){
00092     unsigned long * pCopyValue = (unsigned long*) malloc (sizeof(unsigned long));
00093     memcpy(pCopyValue,&pValue,sizeof(unsigned long));
00094     ht_insert(snap_svc_memmap_hashtable, key, pCopyValue);
00095 }
00096 
00097 void snap_svc_memmap_add_string(char* key, char* pValue){
00098     int uByteSize = strlen(pValue) * sizeof(char);
00099     
00100     char * pCopyValue = (char*) malloc (uByteSize);
00101     memcpy(pCopyValue,&pValue, uByteSize);
00102     ht_insert(snap_svc_memmap_hashtable, key, pValue);
00103     
00104 }
00105  
00106 unsigned long snap_svc_memmap_lookup_int(char* key){
00107     unsigned long* pVal = ht_lookup(snap_svc_memmap_hashtable, key);
00108     if (pVal == 0)
00109         return 0;
00110     else
00111         return *pVal;
00112 }
00113 
00114 void* snap_svc_memmap_lookup_string(char* key){
00115     return ht_lookup(snap_svc_memmap_hashtable, key);
00116 }
00117 
00118 void snap_svc_memmap_del(char* key){
00119     ht_remove(snap_svc_memmap_hashtable, key);
00120 }