nagios_comment *get_next_comment_by_host(char *host_name, nagios_comment *start) { nagios_comment *temp_comment = NULL; if(host_name == NULL || comment_hashlist == NULL) return NULL; if(start == NULL) temp_comment = comment_hashlist[hashfunc(host_name, NULL, COMMENT_HASHSLOTS)]; else temp_comment = start->nexthash; for(; temp_comment && compare_hashdata(temp_comment->host_name, NULL, host_name, NULL) < 0; temp_comment = temp_comment->nexthash); if(temp_comment && compare_hashdata(temp_comment->host_name, NULL, host_name, NULL) == 0) return temp_comment; return NULL; }
/* find a service status entry */ servicestatus *find_servicestatus(char *host_name,char *svc_desc){ servicestatus *temp_servicestatus=NULL; if(host_name==NULL || svc_desc==NULL || servicestatus_hashlist==NULL) return NULL; for(temp_servicestatus=servicestatus_hashlist[hashfunc(host_name,svc_desc,SERVICESTATUS_HASHSLOTS)];temp_servicestatus && compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,host_name,svc_desc)<0;temp_servicestatus=temp_servicestatus->nexthash); if(temp_servicestatus && (compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,host_name,svc_desc)==0)) return temp_servicestatus; return NULL; }
/* find a host status entry */ hoststatus *find_hoststatus(char *host_name){ hoststatus *temp_hoststatus=NULL; if(host_name==NULL || hoststatus_hashlist==NULL) return NULL; for(temp_hoststatus=hoststatus_hashlist[hashfunc(host_name,NULL,HOSTSTATUS_HASHSLOTS)];temp_hoststatus && compare_hashdata(temp_hoststatus->host_name,NULL,host_name,NULL)<0;temp_hoststatus=temp_hoststatus->nexthash); if(temp_hoststatus && (compare_hashdata(temp_hoststatus->host_name,NULL,host_name,NULL)==0)) return temp_hoststatus; return NULL; }
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus){ servicestatus *temp_servicestatus=NULL, *lastpointer=NULL; int hashslot=0; int i=0; /* initialize hash list */ if(servicestatus_hashlist==NULL){ servicestatus_hashlist=(servicestatus **)malloc(sizeof(servicestatus *)*SERVICESTATUS_HASHSLOTS); if(servicestatus_hashlist==NULL) return 0; for(i=0;i< SERVICESTATUS_HASHSLOTS;i++) servicestatus_hashlist[i]=NULL; } if(!new_servicestatus) return 0; hashslot=hashfunc(new_servicestatus->host_name,new_servicestatus->description,SERVICESTATUS_HASHSLOTS); lastpointer=NULL; for(temp_servicestatus=servicestatus_hashlist[hashslot];temp_servicestatus && compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,new_servicestatus->host_name,new_servicestatus->description)<0;temp_servicestatus=temp_servicestatus->nexthash) lastpointer=temp_servicestatus; if(!temp_servicestatus || (compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,new_servicestatus->host_name,new_servicestatus->description)!=0)){ if(lastpointer) lastpointer->nexthash=new_servicestatus; else servicestatus_hashlist[hashslot]=new_servicestatus; new_servicestatus->nexthash=temp_servicestatus; return 1; } /* else already exists */ return 0; }
/* adds hoststatus to hash list in memory */ int add_hoststatus_to_hashlist(hoststatus *new_hoststatus){ hoststatus *temp_hoststatus=NULL; hoststatus *lastpointer=NULL; int hashslot=0; int i=0; /* initialize hash list */ if(hoststatus_hashlist==NULL){ hoststatus_hashlist=(hoststatus **)malloc(sizeof(hoststatus *)*HOSTSTATUS_HASHSLOTS); if(hoststatus_hashlist==NULL) return 0; for(i=0;i<HOSTSTATUS_HASHSLOTS;i++) hoststatus_hashlist[i]=NULL; } if(!new_hoststatus) return 0; hashslot=hashfunc(new_hoststatus->host_name,NULL,HOSTSTATUS_HASHSLOTS); lastpointer=NULL; for(temp_hoststatus=hoststatus_hashlist[hashslot];temp_hoststatus && compare_hashdata(temp_hoststatus->host_name,NULL,new_hoststatus->host_name,NULL)<0;temp_hoststatus=temp_hoststatus->nexthash) lastpointer=temp_hoststatus; if(!temp_hoststatus || (compare_hashdata(temp_hoststatus->host_name,NULL,new_hoststatus->host_name,NULL)!=0)){ if(lastpointer) lastpointer->nexthash=new_hoststatus; else hoststatus_hashlist[hashslot]=new_hoststatus; new_hoststatus->nexthash=temp_hoststatus; return 1; } /* else already exists */ return 0; }
/* adds comment to hash list in memory */ int add_comment_to_hashlist(nagios_comment *new_comment) { nagios_comment *temp_comment = NULL; nagios_comment *lastpointer = NULL; int hashslot = 0; /* initialize hash list */ if(comment_hashlist == NULL) { int i; comment_hashlist = (nagios_comment **)malloc(sizeof(nagios_comment *) * COMMENT_HASHSLOTS); if(comment_hashlist == NULL) return 0; for(i = 0; i < COMMENT_HASHSLOTS; i++) comment_hashlist[i] = NULL; } if(!new_comment) return 0; hashslot = hashfunc(new_comment->host_name, NULL, COMMENT_HASHSLOTS); lastpointer = NULL; for(temp_comment = comment_hashlist[hashslot]; temp_comment && compare_hashdata(temp_comment->host_name, NULL, new_comment->host_name, NULL) < 0; temp_comment = temp_comment->nexthash) { if(compare_hashdata(temp_comment->host_name, NULL, new_comment->host_name, NULL) >= 0) break; lastpointer = temp_comment; } /* multiples are allowed */ if(lastpointer) lastpointer->nexthash = new_comment; else comment_hashlist[hashslot] = new_comment; new_comment->nexthash = temp_comment; return 1; }