int main( int argc, char ** argv ) { int i,n=10; KMAP * km; char * p; char str[80]; printf("usage: kmap nkeys (default=10)\n\n"); km = KMapNew( free ); /* use 'free' to free 'userdata' */ KMapSetNoCase(km,1); //need to add xlat.... if( argc > 1 ) { n = atoi(argv[1]); } for(i=1;i<=n;i++) { SnortSnprintf(str, sizeof(str), "KeyWord%d",i); KMapAdd( km, str, 0 /* strlen(str) */, strupr(strdup(str)) ); printf("Adding Key=%s\n",str); } printf("xmem: %u bytes, %d chars\n",xmalloc_bytes(),km->nchars); printf("\nKey Find test...\n"); for(i=1;i<=n;i++) { SnortSnprintf(str, sizeof(str), "KeyWord%d",i); p = (char*) KMapFind( km, str, 0 /*strlen(str) */ ); if(p)printf("key=%s, data=%*s\n",str,strlen(str),p); else printf("'%s' NOT found.\n",str); } KMapSetNoCase(km,0); // this should fail all key searches printf("\nKey Find test2...\n"); for(i=1;i<=n;i++) { SnortSnprintf(str, sizeof(str), "KeyWord%d",i); p = (char*) KMapFind( km, str, 0 /*strlen(str) */ ); if(p)printf("key=%s, data=%*s\n",str,strlen(str),p); else printf("'%s' NOT found.\n",str); } printf("\nKey FindFirst/Next test...\n"); for(p = (char*) KMapFindFirst(km); p; p=(char*)KMapFindNext(km) ) printf("data=%s\n",p); printf("\nKey FindFirst/Next test done.\n"); KMapDelete( km ); printf("xmem: %u bytes\n",xmalloc_bytes()); printf("normal pgm finish.\n"); return 0; }
/* * Function: ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup) * * Purpose: Initialize the client_lookup structure. * * We need to initialize the client_lookup structure for * the FTP client configuration. Don't want a NULL pointer * flying around, when we have to look for FTP clients. * * Arguments: ClientLookup => pointer to the pointer of the client * lookup structure. * * Returns: int => return code indicating error or success * */ int ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup) { *ClientLookup = KMapNew(NULL); if(*ClientLookup == NULL) { return FTPP_MEM_ALLOC_FAIL; } return FTPP_SUCCESS; }
/** ** Initialize the server_lookup structure. ** ** We need to initialize the server_lookup structure for the server ** configuration access. Don't want a NULL pointer flying around, when ** we have to look for server configs. ** ** @param ServerLookup pointer to the pointer of the server lookup structure. ** ** @return integer ** ** @retval HI_SUCCESS function successful. ** @retval HI_MEM_ALLOC_FAIL memory allocation failed */ int hi_ui_server_lookup_init(SERVER_LOOKUP **ServerLookup) { *ServerLookup = KMapNew(free); if(*ServerLookup == NULL) { return HI_MEM_ALLOC_FAIL; } return HI_SUCCESS; }
/* * Function: ftp_bounce_lookup_init(BOUNCE_LOOKUP **BounceLookup) * * Purpose: Initialize the bounce_lookup structure. * * We need to initialize the bounce_lookup structure for * the FTP bounce configuration. Don't want a NULL pointer * flying around, when we have to look for allowable bounces. * * Arguments: BounceLookup => pointer to the pointer of the bounce * lookup structure. * * Returns: int => return code indicating error or success * */ int ftp_bounce_lookup_init(BOUNCE_LOOKUP **BounceLookup) { KMAP *km = KMapNew((KMapUserFreeFunc)FTPTelnetCleanupFTPBounceTo); *BounceLookup = km; if(*BounceLookup == NULL) { return FTPP_MEM_ALLOC_FAIL; } km->nocase = 1; return FTPP_SUCCESS; }
/* * Function: ftp_cmd_lookup_init(CMD_LOOKUP **CmdLookup) * * Purpose: Initialize the cmd_lookup structure. * * We need to initialize the cmd_lookup structure for * the FTP command configuration. Don't want a NULL pointer * flying around, when we have to look for FTP commands. * * Arguments: CmdLookup => pointer to the pointer of the cmd * lookup structure. * * Returns: int => return code indicating error or success * */ int ftp_cmd_lookup_init(CMD_LOOKUP **CmdLookup) { KMAP *km = KMapNew((KMapUserFreeFunc)FTPTelnetCleanupFTPCMDConf); *CmdLookup = km; if(*CmdLookup == NULL) { return FTPP_MEM_ALLOC_FAIL; } km->nocase = 1; return FTPP_SUCCESS; }
/* * Function: http_cmd_lookup_init(CMD_LOOKUP **CmdLookup) * * Purpose: Initialize the cmd_lookup structure. * * We need to initialize the cmd_lookup structure for * the HTTP command configuration. Don't want a NULL pointer * flying around, when we have to look for HTTP commands. * * Arguments: CmdLookup => pointer to the pointer of the cmd * lookup structure. * * Returns: int => return code indicating error or success * */ int http_cmd_lookup_init(CMD_LOOKUP **CmdLookup) { KMAP *km = KMapNew((KMapUserFreeFunc)HttpInspectCleanupHttpMethodsConf); *CmdLookup = km; if(*CmdLookup == NULL) { return -1; } km->nocase = 1; return 0; }