Icinga-core 1.4.0
next gen monitoring
common/objects.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * OBJECTS.C - Object addition and search functions for Icinga
00004  *
00005  * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
00007  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00008  *
00009  * License:
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2 as
00013  * published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  *
00024  *****************************************************************************/
00025 
00026 #include "../include/config.h"
00027 #include "../include/common.h"
00028 #include "../include/objects.h"
00029 #include "../include/skiplist.h"
00030 
00031 
00032 #ifdef NSCORE
00033 
00034 #ifdef USE_EVENT_BROKER
00035 #include "../include/nebmods.h"
00036 #endif
00037 
00038 #include "../include/icinga.h"
00039 #endif
00040 
00041 #ifdef NSCGI
00042 #include "../include/cgiutils.h"
00043 #endif
00044 
00045 /**** IMPLEMENTATION-SPECIFIC HEADER FILES ****/
00046 
00047 #ifdef USE_XODTEMPLATE                          /* template-based routines */
00048 #include "../xdata/xodtemplate.h"
00049 #endif
00050   
00051 
00052 host            *host_list=NULL,*host_list_tail=NULL;
00053 service         *service_list=NULL,*service_list_tail=NULL;
00054 contact         *contact_list=NULL,*contact_list_tail=NULL;
00055 contactgroup    *contactgroup_list=NULL,*contactgroup_list_tail=NULL;
00056 hostgroup       *hostgroup_list=NULL,*hostgroup_list_tail=NULL;
00057 servicegroup    *servicegroup_list=NULL,*servicegroup_list_tail=NULL;
00058 command         *command_list=NULL,*command_list_tail=NULL;
00059 timeperiod      *timeperiod_list=NULL,*timeperiod_list_tail=NULL;
00060 serviceescalation *serviceescalation_list=NULL,*serviceescalation_list_tail=NULL;
00061 servicedependency *servicedependency_list=NULL,*servicedependency_list_tail=NULL;
00062 hostdependency  *hostdependency_list=NULL,*hostdependency_list_tail=NULL;
00063 hostescalation  *hostescalation_list=NULL,*hostescalation_list_tail=NULL;
00064 module          *module_list=NULL,*module_list_tail=NULL;
00065 
00066 skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
00067 
00068 
00069 #ifdef NSCORE
00070 /* keep this for compatibility */
00071 int __nagios_object_structure_version=CURRENT_OBJECT_STRUCTURE_VERSION;
00072 /* this will be used for IDOUtils, Michael Friedrich, 05-19-2010 */
00073 int __icinga_object_structure_version=CURRENT_OBJECT_STRUCTURE_VERSION;
00074 extern int use_precached_objects;
00075 #endif
00076 
00077 
00078 
00079 /******************************************************************/
00080 /******* TOP-LEVEL HOST CONFIGURATION DATA INPUT FUNCTION *********/
00081 /******************************************************************/
00082 
00083 
00084 /* read all host configuration data from external source */
00085 int read_object_config_data(char *main_config_file, int options, int cache, int precache){
00086         int result=OK;
00087 
00088         /* initialize object skiplists */
00089         init_object_skiplists();
00090 
00091         /********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
00092 #ifdef USE_XODTEMPLATE
00093         /* read in data from all text host config files (template-based) */
00094         result=xodtemplate_read_config_data(main_config_file,options,cache,precache);
00095         if(result!=OK)
00096                 return ERROR;
00097 #endif
00098 
00099         return result;
00100         }
00101 
00102 
00103 
00104 /******************************************************************/
00105 /******************** SKIPLIST FUNCTIONS **************************/
00106 /******************************************************************/
00107 
00108 int init_object_skiplists(void){
00109         int x=0;
00110 
00111         for(x=0;x<NUM_OBJECT_SKIPLISTS;x++)
00112                 object_skiplists[x]=NULL;
00113 
00114         object_skiplists[HOST_SKIPLIST]=skiplist_new(15,0.5,FALSE,FALSE,skiplist_compare_host);
00115         object_skiplists[SERVICE_SKIPLIST]=skiplist_new(15,0.5,FALSE,FALSE,skiplist_compare_service);
00116 
00117         object_skiplists[COMMAND_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_command);
00118         object_skiplists[TIMEPERIOD_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_timeperiod);
00119         object_skiplists[CONTACT_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_contact);
00120         object_skiplists[CONTACTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_contactgroup);
00121         object_skiplists[HOSTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_hostgroup);
00122         object_skiplists[SERVICEGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_servicegroup);
00123 
00124         object_skiplists[HOSTESCALATION_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_hostescalation);
00125         object_skiplists[SERVICEESCALATION_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_serviceescalation);
00126         object_skiplists[HOSTDEPENDENCY_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_hostdependency);
00127         object_skiplists[SERVICEDEPENDENCY_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_servicedependency);
00128 
00129         object_skiplists[MODULE_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_module);
00130 
00131         return OK;
00132         }
00133 
00134 
00135 
00136 int free_object_skiplists(void){
00137         int x=0;
00138 
00139         for(x=0;x<NUM_OBJECT_SKIPLISTS;x++)
00140                 skiplist_free(&object_skiplists[x]);
00141 
00142         return OK;
00143         }
00144 
00145 
00146 int skiplist_compare_text(const char *val1a, const char *val1b, const char *val2a, const char *val2b){
00147         int result=0;
00148 
00149         /* check first name */
00150         if(val1a==NULL && val2a==NULL)
00151                 result=0;
00152         else if(val1a==NULL)
00153                 result=1;
00154         else if(val2a==NULL)
00155                 result=-1;
00156         else
00157                 result=strcmp(val1a,val2a);
00158 
00159         /* check second name if necessary */
00160         if(result==0){
00161                 if(val1b==NULL && val2b==NULL)
00162                         result=0;
00163                 else if(val1b==NULL)
00164                         result=1;
00165                 else if(val2b==NULL)
00166                         result=-1;
00167                 else
00168                         result=strcmp(val1b,val2b);
00169                 }
00170 
00171         return result;
00172         }
00173 
00174 
00175 int skiplist_compare_host(void *a, void *b){
00176         host *oa=NULL;
00177         host *ob=NULL;
00178 
00179         oa=(host *)a;
00180         ob=(host *)b;
00181 
00182         if(oa==NULL && ob==NULL)
00183                 return 0;
00184         if(oa==NULL)
00185                 return 1;
00186         if(ob==NULL)
00187                 return -1;
00188 
00189         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
00190         }
00191 
00192 
00193 int skiplist_compare_service(void *a, void *b){
00194         service *oa=NULL;
00195         service *ob=NULL;
00196 
00197         oa=(service *)a;
00198         ob=(service *)b;
00199 
00200         if(oa==NULL && ob==NULL)
00201                 return 0;
00202         if(oa==NULL)
00203                 return 1;
00204         if(ob==NULL)
00205                 return -1;
00206 
00207         return skiplist_compare_text(oa->host_name,oa->description,ob->host_name,ob->description);
00208         }
00209 
00210 
00211 int skiplist_compare_command(void *a, void *b){
00212         command *oa=NULL;
00213         command *ob=NULL;
00214 
00215         oa=(command *)a;
00216         ob=(command *)b;
00217 
00218         if(oa==NULL && ob==NULL)
00219                 return 0;
00220         if(oa==NULL)
00221                 return 1;
00222         if(ob==NULL)
00223                 return -1;
00224 
00225         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
00226         }
00227 
00228 
00229 int skiplist_compare_timeperiod(void *a, void *b){
00230         timeperiod *oa=NULL;
00231         timeperiod *ob=NULL;
00232 
00233         oa=(timeperiod *)a;
00234         ob=(timeperiod *)b;
00235 
00236         if(oa==NULL && ob==NULL)
00237                 return 0;
00238         if(oa==NULL)
00239                 return 1;
00240         if(ob==NULL)
00241                 return -1;
00242 
00243         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
00244         }
00245 
00246 
00247 int skiplist_compare_contact(void *a, void *b){
00248         contact *oa=NULL;
00249         contact *ob=NULL;
00250 
00251         oa=(contact *)a;
00252         ob=(contact *)b;
00253 
00254         if(oa==NULL && ob==NULL)
00255                 return 0;
00256         if(oa==NULL)
00257                 return 1;
00258         if(ob==NULL)
00259                 return -1;
00260 
00261         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
00262         }
00263 
00264 
00265 int skiplist_compare_contactgroup(void *a, void *b){
00266         contactgroup *oa=NULL;
00267         contactgroup *ob=NULL;
00268 
00269         oa=(contactgroup *)a;
00270         ob=(contactgroup *)b;
00271 
00272         if(oa==NULL && ob==NULL)
00273                 return 0;
00274         if(oa==NULL)
00275                 return 1;
00276         if(ob==NULL)
00277                 return -1;
00278 
00279         return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
00280         }
00281 
00282 
00283 int skiplist_compare_hostgroup(void *a, void *b){
00284         hostgroup *oa=NULL;
00285         hostgroup *ob=NULL;
00286 
00287         oa=(hostgroup *)a;
00288         ob=(hostgroup *)b;
00289 
00290         if(oa==NULL && ob==NULL)
00291                 return 0;
00292         if(oa==NULL)
00293                 return 1;
00294         if(ob==NULL)
00295                 return -1;
00296 
00297         return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
00298         }
00299 
00300 
00301 int skiplist_compare_servicegroup(void *a, void *b){
00302         servicegroup *oa=NULL;
00303         servicegroup *ob=NULL;
00304 
00305         oa=(servicegroup *)a;
00306         ob=(servicegroup *)b;
00307 
00308         if(oa==NULL && ob==NULL)
00309                 return 0;
00310         if(oa==NULL)
00311                 return 1;
00312         if(ob==NULL)
00313                 return -1;
00314 
00315         return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
00316         }
00317 
00318 
00319 int skiplist_compare_hostescalation(void *a, void *b){
00320         hostescalation *oa=NULL;
00321         hostescalation *ob=NULL;
00322 
00323         oa=(hostescalation *)a;
00324         ob=(hostescalation *)b;
00325 
00326         if(oa==NULL && ob==NULL)
00327                 return 0;
00328         if(oa==NULL)
00329                 return 1;
00330         if(ob==NULL)
00331                 return -1;
00332 
00333         return skiplist_compare_text(oa->host_name,NULL,ob->host_name,NULL);
00334         }
00335 
00336 
00337 int skiplist_compare_serviceescalation(void *a, void *b){
00338         serviceescalation *oa=NULL;
00339         serviceescalation *ob=NULL;
00340 
00341         oa=(serviceescalation *)a;
00342         ob=(serviceescalation *)b;
00343 
00344         if(oa==NULL && ob==NULL)
00345                 return 0;
00346         if(oa==NULL)
00347                 return 1;
00348         if(ob==NULL)
00349                 return -1;
00350 
00351         return skiplist_compare_text(oa->host_name,oa->description,ob->host_name,ob->description);
00352         }
00353 
00354 
00355 int skiplist_compare_hostdependency(void *a, void *b){
00356         hostdependency *oa=NULL;
00357         hostdependency *ob=NULL;
00358 
00359         oa=(hostdependency *)a;
00360         ob=(hostdependency *)b;
00361 
00362         if(oa==NULL && ob==NULL)
00363                 return 0;
00364         if(oa==NULL)
00365                 return 1;
00366         if(ob==NULL)
00367                 return -1;
00368 
00369         return skiplist_compare_text(oa->dependent_host_name,NULL,ob->dependent_host_name,NULL);
00370         }
00371 
00372 
00373 int skiplist_compare_servicedependency(void *a, void *b){
00374         servicedependency *oa=NULL;
00375         servicedependency *ob=NULL;
00376 
00377         oa=(servicedependency *)a;
00378         ob=(servicedependency *)b;
00379 
00380         if(oa==NULL && ob==NULL)
00381                 return 0;
00382         if(oa==NULL)
00383                 return 1;
00384         if(ob==NULL)
00385                 return -1;
00386 
00387         return skiplist_compare_text(oa->dependent_host_name,oa->dependent_service_description,ob->dependent_host_name,ob->dependent_service_description);
00388         }
00389 
00390 int skiplist_compare_module(void *a, void *b){
00391         module *oa=NULL;
00392         module *ob=NULL;
00393 
00394         oa=(module *)a;
00395         ob=(module *)b;
00396 
00397         if(oa==NULL && ob==NULL)
00398                 return 0;
00399         if(oa==NULL)
00400                 return 1;
00401         if(ob==NULL)
00402                 return -1;
00403 
00404         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
00405         }
00406 
00407 
00408 int get_host_count(void){
00409 
00410         if(object_skiplists[HOST_SKIPLIST])
00411                 return object_skiplists[HOST_SKIPLIST]->items;
00412 
00413         return 0;
00414         }
00415 
00416 
00417 int get_service_count(void){
00418 
00419         if(object_skiplists[SERVICE_SKIPLIST])
00420                 return object_skiplists[SERVICE_SKIPLIST]->items;
00421 
00422         return 0;
00423         }
00424 
00425 
00426 
00427 
00428 /******************************************************************/
00429 /**************** OBJECT ADDITION FUNCTIONS ***********************/
00430 /******************************************************************/
00431 
00432 
00433 
00434 /* add a new timeperiod to the list in memory */
00435 timeperiod *add_timeperiod(char *name,char *alias){
00436         timeperiod *new_timeperiod=NULL;
00437         int result=OK;
00438 
00439         /* make sure we have the data we need */
00440         if((name==NULL || !strcmp(name,"")) || (alias==NULL || !strcmp(alias,""))){
00441                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Name or alias for timeperiod is NULL\n");
00442                 return NULL;
00443                 }
00444 
00445         /* allocate memory for the new timeperiod */
00446         if((new_timeperiod=calloc(1, sizeof(timeperiod)))==NULL)
00447                 return NULL;
00448 
00449         /* copy string vars */
00450         if((new_timeperiod->name=(char *)strdup(name))==NULL)
00451                 result=ERROR;
00452         if((new_timeperiod->alias=(char *)strdup(alias))==NULL)
00453                 result=ERROR;
00454 
00455         /* add new timeperiod to skiplist */
00456         if(result==OK){
00457                 result=skiplist_insert(object_skiplists[TIMEPERIOD_SKIPLIST],(void *)new_timeperiod);
00458                 switch(result){
00459                 case SKIPLIST_ERROR_DUPLICATE:
00460                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Timeperiod '%s' has already been defined\n",name);
00461                         result=ERROR;
00462                         break;
00463                 case SKIPLIST_OK:
00464                         result=OK;
00465                         break;
00466                 default:
00467                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add timeperiod '%s' to skiplist\n",name);
00468                         result=ERROR;
00469                         break;
00470                         }
00471                 }
00472 
00473         /* handle errors */
00474         if(result==ERROR){
00475                 my_free(new_timeperiod->alias);
00476                 my_free(new_timeperiod->name);
00477                 my_free(new_timeperiod);
00478                 return NULL;
00479                 }
00480 
00481         /* timeperiods are registered alphabetically, so add new items to tail of list */
00482         if(timeperiod_list==NULL){
00483                 timeperiod_list=new_timeperiod;
00484                 timeperiod_list_tail=timeperiod_list;
00485                 }
00486         else{
00487                 timeperiod_list_tail->next=new_timeperiod;
00488                 timeperiod_list_tail=new_timeperiod;
00489                 }
00490 
00491         return new_timeperiod;
00492         }
00493 
00494 
00495 
00496 
00497 /* adds a new exclusion to a timeperiod */
00498 timeperiodexclusion *add_exclusion_to_timeperiod(timeperiod *period, char *name){
00499         timeperiodexclusion *new_timeperiodexclusion=NULL;
00500 
00501         /* make sure we have enough data */
00502         if(period==NULL || name==NULL)
00503                 return NULL;
00504 
00505         if((new_timeperiodexclusion=(timeperiodexclusion *)malloc(sizeof(timeperiodexclusion)))==NULL)
00506                 return NULL;
00507 
00508         new_timeperiodexclusion->timeperiod_name=(char *)strdup(name);
00509 
00510         new_timeperiodexclusion->next=period->exclusions;
00511         period->exclusions=new_timeperiodexclusion;
00512 
00513         return new_timeperiodexclusion;
00514         }
00515 
00516 
00517 
00518 
00519 /* add a new timerange to a timeperiod */
00520 timerange *add_timerange_to_timeperiod(timeperiod *period, int day, unsigned long start_time, unsigned long end_time){
00521         timerange *new_timerange=NULL;
00522 
00523         /* make sure we have the data we need */
00524         if(period==NULL)
00525                 return NULL;
00526 
00527         if(day<0 || day>6){
00528                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Day %d is not valid for timeperiod '%s'\n",day,period->name);
00529                 return NULL;
00530                 }
00531         if(start_time<0 || start_time>86400){
00532                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Start time %lu on day %d is not valid for timeperiod '%s'\n",start_time,day,period->name);
00533                 return NULL;
00534                 }
00535         if(end_time<0 || end_time>86400){
00536                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: End time %lu on day %d is not value for timeperiod '%s'\n",end_time,day,period->name);
00537                 return NULL;
00538                 }
00539 
00540         /* allocate memory for the new time range */
00541         if((new_timerange=malloc(sizeof(timerange)))==NULL)
00542                 return NULL;
00543 
00544         new_timerange->range_start=start_time;
00545         new_timerange->range_end=end_time;
00546 
00547         /* add the new time range to the head of the range list for this day */
00548         new_timerange->next=period->days[day];
00549         period->days[day]=new_timerange;
00550 
00551         return new_timerange;
00552         }
00553 
00554 
00555 /* add a new exception to a timeperiod */
00556 daterange *add_exception_to_timeperiod(timeperiod *period, int type, int syear, int smon, int smday, int swday, int swday_offset, int eyear, int emon, int emday, int ewday, int ewday_offset, int skip_interval){
00557         daterange *new_daterange=NULL;
00558 
00559         /* make sure we have the data we need */
00560         if(period==NULL)
00561                 return NULL;
00562 
00563         /* allocate memory for the date range range */
00564         if((new_daterange=malloc(sizeof(daterange)))==NULL)
00565                 return NULL;
00566 
00567         new_daterange->times=NULL;
00568         new_daterange->next=NULL;
00569 
00570         new_daterange->type=type;
00571         new_daterange->syear=syear;
00572         new_daterange->smon=smon;
00573         new_daterange->smday=smday;
00574         new_daterange->swday=swday;
00575         new_daterange->swday_offset=swday_offset;
00576         new_daterange->eyear=eyear;
00577         new_daterange->emon=emon;
00578         new_daterange->emday=emday;
00579         new_daterange->ewday=ewday;
00580         new_daterange->ewday_offset=ewday_offset;
00581         new_daterange->skip_interval=skip_interval;
00582 
00583         /* add the new date range to the head of the range list for this exception type */
00584         new_daterange->next=period->exceptions[type];
00585         period->exceptions[type]=new_daterange;
00586 
00587         return new_daterange;
00588         }
00589 
00590 
00591 
00592 /* add a new timerange to a daterange */
00593 timerange *add_timerange_to_daterange(daterange *drange, unsigned long start_time, unsigned long end_time){
00594         timerange *new_timerange=NULL;
00595 
00596         /* make sure we have the data we need */
00597         if(drange==NULL)
00598                 return NULL;
00599 
00600         if(start_time<0 || start_time>86400){
00601                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Start time %lu is not valid for timeperiod\n",start_time);
00602                 return NULL;
00603                 }
00604         if(end_time<0 || end_time>86400){
00605                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: End time %lu is not value for timeperiod\n",end_time);
00606                 return NULL;
00607                 }
00608 
00609         /* allocate memory for the new time range */
00610         if((new_timerange=malloc(sizeof(timerange)))==NULL)
00611                 return NULL;
00612 
00613         new_timerange->range_start=start_time;
00614         new_timerange->range_end=end_time;
00615 
00616         /* add the new time range to the head of the range list for this date range */
00617         new_timerange->next=drange->times;
00618         drange->times=new_timerange;
00619 
00620         return new_timerange;
00621         }
00622 
00623 
00624 
00625 /* add a new host definition */
00626 host *add_host(char *name, char *display_name, char *alias, char *address, char *address6, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notify_up, int notify_down, int notify_unreachable, int notify_flapping, int notify_downtime, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_up, int flap_detection_on_down, int flap_detection_on_unreachable, int stalk_on_up, int stalk_on_down, int stalk_on_unreachable, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess_over_host){
00627         host *new_host=NULL;
00628         int result=OK;
00629 #ifdef NSCORE
00630         int x=0;
00631 #endif
00632 
00633         /* make sure we have the data we need */
00634         if((name==NULL || !strcmp(name,"")) || (address==NULL || !strcmp(address,""))){
00635                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host name or address is NULL\n");
00636                 return NULL;
00637                 }
00638 
00639         /* check values */
00640         if(max_attempts<=0){
00641                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid max_check_attempts value for host '%s'\n",name);
00642                 return NULL;
00643                 }
00644         if(check_interval<0){
00645                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid check_interval value for host '%s'\n",name);
00646                 return NULL;
00647                 }
00648         if(notification_interval<0){
00649                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification_interval value for host '%s'\n",name);
00650                 return NULL;
00651                 }
00652         if(first_notification_delay<0){
00653                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid first_notification_delay value for host '%s'\n",name);
00654                 return NULL;
00655                 }
00656         if(freshness_threshold<0){
00657                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid freshness_threshold value for host '%s'\n",name);
00658                 return NULL;
00659                 }
00660 
00661         /* allocate memory for a new host */
00662         if((new_host=(host *)calloc(1, sizeof(host)))==NULL)
00663                 return NULL;
00664 
00665         /* duplicate string vars */
00666         if((new_host->name=(char *)strdup(name))==NULL)
00667                 result=ERROR;
00668         if((new_host->display_name=(char *)strdup((display_name==NULL)?name:display_name))==NULL)
00669                 result=ERROR;
00670         if((new_host->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
00671                 result=ERROR;
00672         if((new_host->address=(char *)strdup(address))==NULL)
00673                 result=ERROR;
00674         if((new_host->address6=(char *)strdup(address6))==NULL)
00675                 result=ERROR;
00676         if(check_period){
00677                 if((new_host->check_period=(char *)strdup(check_period))==NULL)
00678                         result=ERROR;
00679                 }
00680         if(notification_period){
00681                 if((new_host->notification_period=(char *)strdup(notification_period))==NULL)
00682                         result=ERROR;
00683                 }
00684         if(check_command){
00685                 if((new_host->host_check_command=(char *)strdup(check_command))==NULL)
00686                         result=ERROR;
00687                 }
00688         if(event_handler){
00689                 if((new_host->event_handler=(char *)strdup(event_handler))==NULL)
00690                         result=ERROR;
00691                 }
00692         if(failure_prediction_options){
00693                 if((new_host->failure_prediction_options=(char *)strdup(failure_prediction_options))==NULL)
00694                         result=ERROR;
00695                 }
00696         if(notes){
00697                 if((new_host->notes=(char *)strdup(notes))==NULL)
00698                         result=ERROR;
00699                 }
00700         if(notes_url){
00701                 if((new_host->notes_url=(char *)strdup(notes_url))==NULL)
00702                         result=ERROR;
00703                 }
00704         if(action_url){
00705                 if((new_host->action_url=(char *)strdup(action_url))==NULL)
00706                         result=ERROR;
00707                 }
00708         if(icon_image){
00709                 if((new_host->icon_image=(char *)strdup(icon_image))==NULL)
00710                         result=ERROR;
00711                 }
00712         if(icon_image_alt){
00713                 if((new_host->icon_image_alt=(char *)strdup(icon_image_alt))==NULL)
00714                         result=ERROR;
00715                 }
00716         if(vrml_image){
00717                 if((new_host->vrml_image=(char *)strdup(vrml_image))==NULL)
00718                         result=ERROR;
00719                 }
00720         if(statusmap_image){
00721                 if((new_host->statusmap_image=(char *)strdup(statusmap_image))==NULL)
00722                         result=ERROR;
00723                 }
00724 
00725 
00726         /* duplicate non-string vars */
00727         new_host->max_attempts=max_attempts;
00728         new_host->check_interval=check_interval;
00729         new_host->retry_interval=retry_interval;
00730         new_host->notification_interval=notification_interval;
00731         new_host->first_notification_delay=first_notification_delay;
00732         new_host->notify_on_recovery=(notify_up>0)?TRUE:FALSE;
00733         new_host->notify_on_down=(notify_down>0)?TRUE:FALSE;
00734         new_host->notify_on_unreachable=(notify_unreachable>0)?TRUE:FALSE;
00735         new_host->notify_on_flapping=(notify_flapping>0)?TRUE:FALSE;
00736         new_host->notify_on_downtime=(notify_downtime>0)?TRUE:FALSE;
00737         new_host->flap_detection_enabled=(flap_detection_enabled>0)?TRUE:FALSE;
00738         new_host->low_flap_threshold=low_flap_threshold;
00739         new_host->high_flap_threshold=high_flap_threshold;
00740         new_host->flap_detection_on_up=(flap_detection_on_up>0)?TRUE:FALSE;
00741         new_host->flap_detection_on_down=(flap_detection_on_down>0)?TRUE:FALSE;
00742         new_host->flap_detection_on_unreachable=(flap_detection_on_unreachable>0)?TRUE:FALSE;
00743         new_host->stalk_on_up=(stalk_on_up>0)?TRUE:FALSE;
00744         new_host->stalk_on_down=(stalk_on_down>0)?TRUE:FALSE;
00745         new_host->stalk_on_unreachable=(stalk_on_unreachable>0)?TRUE:FALSE;
00746         new_host->process_performance_data=(process_perfdata>0)?TRUE:FALSE;
00747         new_host->check_freshness=(check_freshness>0)?TRUE:FALSE;
00748         new_host->freshness_threshold=freshness_threshold;
00749         new_host->checks_enabled=(checks_enabled>0)?TRUE:FALSE;
00750         new_host->accept_passive_host_checks=(accept_passive_checks>0)?TRUE:FALSE;
00751         new_host->event_handler_enabled=(event_handler_enabled>0)?TRUE:FALSE;
00752         new_host->failure_prediction_enabled=(failure_prediction_enabled>0)?TRUE:FALSE;
00753         new_host->x_2d=x_2d;
00754         new_host->y_2d=y_2d;
00755         new_host->have_2d_coords=(have_2d_coords>0)?TRUE:FALSE;
00756         new_host->x_3d=x_3d;
00757         new_host->y_3d=y_3d;
00758         new_host->z_3d=z_3d;
00759         new_host->have_3d_coords=(have_3d_coords>0)?TRUE:FALSE;
00760         new_host->should_be_drawn=(should_be_drawn>0)?TRUE:FALSE;
00761         new_host->obsess_over_host=(obsess_over_host>0)?TRUE:FALSE;
00762         new_host->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
00763         new_host->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
00764 #ifdef NSCORE
00765         new_host->current_state=initial_state;
00766         new_host->current_event_id=0L;
00767         new_host->last_event_id=0L;
00768         new_host->current_problem_id=0L;
00769         new_host->last_problem_id=0L;
00770         new_host->last_state=initial_state;
00771         new_host->last_hard_state=initial_state;
00772         new_host->check_type=HOST_CHECK_ACTIVE;
00773         new_host->last_host_notification=(time_t)0;
00774         new_host->next_host_notification=(time_t)0;
00775         new_host->next_check=(time_t)0;
00776         new_host->should_be_scheduled=TRUE;
00777         new_host->last_check=(time_t)0;
00778         new_host->current_attempt=(initial_state==HOST_UP)?1:max_attempts;
00779         new_host->state_type=HARD_STATE;
00780         new_host->execution_time=0.0;
00781         new_host->is_executing=FALSE;
00782         new_host->latency=0.0;
00783         new_host->last_state_change=(time_t)0;
00784         new_host->last_hard_state_change=(time_t)0;
00785         new_host->last_time_up=(time_t)0;
00786         new_host->last_time_down=(time_t)0;
00787         new_host->last_time_unreachable=(time_t)0;
00788         new_host->has_been_checked=FALSE;
00789         new_host->is_being_freshened=FALSE;
00790         new_host->problem_has_been_acknowledged=FALSE;
00791         new_host->acknowledgement_type=ACKNOWLEDGEMENT_NONE;
00792         new_host->notifications_enabled=(notifications_enabled>0)?TRUE:FALSE;
00793         new_host->notified_on_down=FALSE;
00794         new_host->notified_on_unreachable=FALSE;
00795         new_host->current_notification_number=0;
00796 #ifdef USE_ST_BASED_ESCAL_RANGES
00797         new_host->current_down_notification_number=0;
00798         new_host->current_unreachable_notification_number=0;
00799 #endif
00800         new_host->current_notification_id=0L;
00801         new_host->no_more_notifications=FALSE;
00802         new_host->check_flapping_recovery_notification=FALSE;
00803         new_host->scheduled_downtime_depth=0;
00804         new_host->check_options=CHECK_OPTION_NONE;
00805         new_host->pending_flex_downtime=0;
00806         for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
00807                 new_host->state_history[x]=STATE_OK;
00808         new_host->state_history_index=0;
00809         new_host->last_state_history_update=(time_t)0;
00810         new_host->is_flapping=FALSE;
00811         new_host->flapping_comment_id=0;
00812         new_host->percent_state_change=0.0;
00813         new_host->total_services=0;
00814         new_host->total_service_check_interval=0L;
00815         new_host->modified_attributes=MODATTR_NONE;
00816         new_host->circular_path_checked=FALSE;
00817         new_host->contains_circular_path=FALSE;
00818 #endif
00819 
00820         /* add new host to skiplist */
00821         if(result==OK){
00822                 result=skiplist_insert(object_skiplists[HOST_SKIPLIST],(void *)new_host);
00823                 switch(result){
00824                 case SKIPLIST_ERROR_DUPLICATE:
00825                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host '%s' has already been defined\n",name);
00826                         result=ERROR;
00827                         break;
00828                 case SKIPLIST_OK:
00829                         result=OK;
00830                         break;
00831                 default:
00832                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host '%s' to skiplist\n",name);
00833                         result=ERROR;
00834                         break;
00835                         }
00836                 }
00837 
00838         /* handle errors */
00839         if(result==ERROR){
00840 #ifdef NSCORE
00841                 my_free(new_host->plugin_output);
00842                 my_free(new_host->long_plugin_output);
00843                 my_free(new_host->perf_data);
00844 #endif
00845                 my_free(new_host->statusmap_image);
00846                 my_free(new_host->vrml_image);
00847                 my_free(new_host->icon_image_alt);
00848                 my_free(new_host->icon_image);
00849                 my_free(new_host->action_url);
00850                 my_free(new_host->notes_url);
00851                 my_free(new_host->notes);
00852                 my_free(new_host->failure_prediction_options);
00853                 my_free(new_host->event_handler);
00854                 my_free(new_host->host_check_command);
00855                 my_free(new_host->notification_period);
00856                 my_free(new_host->check_period);
00857                 my_free(new_host->address);
00858                 my_free(new_host->address6);
00859                 my_free(new_host->alias);
00860                 my_free(new_host->display_name);
00861                 my_free(new_host->name);
00862                 my_free(new_host);
00863                 return NULL;
00864                 }
00865 
00866         /* hosts are sorted alphabetically, so add new items to tail of list */
00867         if(host_list==NULL){
00868                 host_list=new_host;
00869                 host_list_tail=host_list;
00870                 }
00871         else{
00872                 host_list_tail->next=new_host;
00873                 host_list_tail=new_host;
00874                 }
00875 
00876         return new_host;
00877         }
00878 
00879 
00880 
00881 hostsmember *add_parent_host_to_host(host *hst,char *host_name){
00882         hostsmember *new_hostsmember=NULL;
00883         int result=OK;
00884 
00885         /* make sure we have the data we need */
00886         if(hst==NULL || host_name==NULL || !strcmp(host_name,"")){
00887                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host is NULL or parent host name is NULL\n");
00888                 return NULL;
00889                 }
00890 
00891         /* a host cannot be a parent/child of itself */
00892         if(!strcmp(host_name,hst->name)){
00893                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host '%s' cannot be a child/parent of itself\n",hst->name);
00894                 return NULL;
00895                 }
00896 
00897         /* allocate memory */
00898         if((new_hostsmember=(hostsmember *)calloc(1, sizeof(hostsmember)))==NULL)
00899                 return NULL;
00900 
00901         /* duplicate string vars */
00902         if((new_hostsmember->host_name=(char *)strdup(host_name))==NULL)
00903                 result=ERROR;
00904 
00905         /* handle errors */
00906         if(result==ERROR){
00907                 my_free(new_hostsmember->host_name);
00908                 my_free(new_hostsmember);
00909                 return NULL;
00910                 }
00911 
00912         /* add the parent host entry to the host definition */
00913         new_hostsmember->next=hst->parent_hosts;
00914         hst->parent_hosts=new_hostsmember;
00915 
00916         return new_hostsmember;
00917         }
00918 
00919 
00920 
00921 hostsmember *add_child_link_to_host(host *hst, host *child_ptr){
00922         hostsmember *new_hostsmember=NULL;
00923 
00924         /* make sure we have the data we need */
00925         if(hst==NULL || child_ptr==NULL)
00926                 return NULL;
00927 
00928         /* allocate memory */
00929         if((new_hostsmember=(hostsmember *)malloc(sizeof(hostsmember)))==NULL)
00930                 return NULL;
00931 
00932         /* initialize values */
00933         new_hostsmember->host_name=NULL;
00934 #ifdef NSCORE
00935         new_hostsmember->host_ptr=child_ptr;
00936 #endif
00937 
00938         /* add the child entry to the host definition */
00939         new_hostsmember->next=hst->child_hosts;
00940         hst->child_hosts=new_hostsmember;
00941 
00942         return new_hostsmember;
00943         }
00944 
00945 
00946 
00947 servicesmember *add_service_link_to_host(host *hst, service *service_ptr){
00948         servicesmember *new_servicesmember=NULL;
00949 
00950         /* make sure we have the data we need */
00951         if(hst==NULL || service_ptr==NULL)
00952                 return NULL;
00953 
00954         /* allocate memory */
00955         if((new_servicesmember=(servicesmember *)calloc(1, sizeof(servicesmember)))==NULL)
00956                 return NULL;
00957 
00958         /* initialize values */
00959 #ifdef NSCORE
00960         new_servicesmember->service_ptr=service_ptr;
00961 #endif
00962 
00963         /* add the child entry to the host definition */
00964         new_servicesmember->next=hst->services;
00965         hst->services=new_servicesmember;
00966 
00967         return new_servicesmember;
00968         }
00969 
00970 
00971 
00972 /* add a new contactgroup to a host */
00973 contactgroupsmember *add_contactgroup_to_host(host *hst, char *group_name){
00974         contactgroupsmember *new_contactgroupsmember=NULL;
00975         int result=OK;
00976 
00977         /* make sure we have the data we need */
00978         if(hst==NULL || (group_name==NULL || !strcmp(group_name,""))){
00979                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host or contactgroup member is NULL\n");
00980                 return NULL;
00981                 }
00982 
00983         /* allocate memory for a new member */
00984         if((new_contactgroupsmember=calloc(1, sizeof(contactgroupsmember)))==NULL)
00985                 return NULL;
00986         
00987         /* duplicate string vars */
00988         if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
00989                 result=ERROR;
00990 
00991         /* handle errors */
00992         if(result==ERROR){
00993                 my_free(new_contactgroupsmember->group_name);
00994                 my_free(new_contactgroupsmember);
00995                 return NULL;
00996                 }
00997         
00998         /* add the new member to the head of the member list */
00999         new_contactgroupsmember->next=hst->contact_groups;
01000         hst->contact_groups=new_contactgroupsmember;;
01001 
01002         return new_contactgroupsmember;
01003         }
01004 
01005 
01006 
01007 /* adds a contact to a host */
01008 contactsmember *add_contact_to_host(host *hst, char *contact_name){
01009 
01010         return add_contact_to_object(&hst->contacts,contact_name);
01011         }
01012 
01013 
01014 
01015 /* adds a custom variable to a host */
01016 customvariablesmember *add_custom_variable_to_host(host *hst, char *varname, char *varvalue){
01017 
01018         return add_custom_variable_to_object(&hst->custom_variables,varname,varvalue);
01019         }
01020 
01021 
01022 
01023 /* add a new host group to the list in memory */
01024 hostgroup *add_hostgroup(char *name, char *alias, char *notes, char *notes_url, char *action_url){
01025         hostgroup *new_hostgroup=NULL;
01026         int result=OK;
01027 
01028         /* make sure we have the data we need */
01029         if(name==NULL || !strcmp(name,"")){
01030                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup name is NULL\n");
01031                 return NULL;
01032                 }
01033 
01034         /* allocate memory */
01035         if((new_hostgroup=(hostgroup *)calloc(1, sizeof(hostgroup)))==NULL)
01036                 return NULL;
01037 
01038         /* duplicate vars */
01039         if((new_hostgroup->group_name=(char *)strdup(name))==NULL)
01040                 result=ERROR;
01041         if((new_hostgroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
01042                 result=ERROR;
01043         if(notes){
01044                 if((new_hostgroup->notes=(char *)strdup(notes))==NULL)
01045                         result=ERROR;
01046                 }
01047         if(notes_url){
01048                 if((new_hostgroup->notes_url=(char *)strdup(notes_url))==NULL)
01049                         result=ERROR;
01050                 }
01051         if(action_url){
01052                 if((new_hostgroup->action_url=(char *)strdup(action_url))==NULL)
01053                         result=ERROR;
01054                 }
01055 
01056         /* add new host group to skiplist */
01057         if(result==OK){
01058                 result=skiplist_insert(object_skiplists[HOSTGROUP_SKIPLIST],(void *)new_hostgroup);
01059                 switch(result){
01060                 case SKIPLIST_ERROR_DUPLICATE:
01061                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup '%s' has already been defined\n",name);
01062                         result=ERROR;
01063                         break;
01064                 case SKIPLIST_OK:
01065                         result=OK;
01066                         break;
01067                 default:
01068                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add hostgroup '%s' to skiplist\n",name);
01069                         result=ERROR;
01070                         break;
01071                         }
01072                 }
01073 
01074         /* handle errors */
01075         if(result==ERROR){
01076                 my_free(new_hostgroup->alias);
01077                 my_free(new_hostgroup->group_name);
01078                 my_free(new_hostgroup);
01079                 return NULL;
01080                 }
01081 
01082         /* hostgroups are sorted alphabetically, so add new items to tail of list */
01083         if(hostgroup_list==NULL){
01084                 hostgroup_list=new_hostgroup;
01085                 hostgroup_list_tail=hostgroup_list;
01086                 }
01087         else{
01088                 hostgroup_list_tail->next=new_hostgroup;
01089                 hostgroup_list_tail=new_hostgroup;
01090                 }
01091 
01092         return new_hostgroup;
01093         }
01094 
01095 
01096 /* add a new host to a host group */
01097 hostsmember *add_host_to_hostgroup(hostgroup *temp_hostgroup, char *host_name){
01098         hostsmember *new_member=NULL;
01099         hostsmember *last_member=NULL;
01100         hostsmember *temp_member=NULL;
01101         int result=OK;
01102 
01103         /* make sure we have the data we need */
01104         if(temp_hostgroup==NULL || (host_name==NULL || !strcmp(host_name,""))){
01105                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup or group member is NULL\n");
01106                 return NULL;
01107                 }
01108 
01109         /* allocate memory for a new member */
01110         if((new_member=calloc(1, sizeof(hostsmember)))==NULL)
01111                 return NULL;
01112 
01113         /* duplicate vars */
01114         if((new_member->host_name=(char *)strdup(host_name))==NULL)
01115                 result=ERROR;
01116 
01117         /* handle errors */
01118         if(result==ERROR){
01119                 my_free(new_member->host_name);
01120                 my_free(new_member);
01121                 return NULL;
01122                 }
01123         
01124         /* add the new member to the member list, sorted by host name */
01125         last_member=temp_hostgroup->members;
01126         for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
01127                 if(strcmp(new_member->host_name,temp_member->host_name)<0){
01128                         new_member->next=temp_member;
01129                         if(temp_member==temp_hostgroup->members)
01130                                 temp_hostgroup->members=new_member;
01131                         else
01132                                 last_member->next=new_member;
01133                         break;
01134                         }
01135                 else
01136                         last_member=temp_member;
01137                 }
01138         if(temp_hostgroup->members==NULL){
01139                 new_member->next=NULL;
01140                 temp_hostgroup->members=new_member;
01141                 }
01142         else if(temp_member==NULL){
01143                 new_member->next=NULL;
01144                 last_member->next=new_member;
01145                 }
01146 
01147         return new_member;
01148         }
01149 
01150 
01151 /* add a new service group to the list in memory */
01152 servicegroup *add_servicegroup(char *name, char *alias, char *notes, char *notes_url, char *action_url){
01153         servicegroup *new_servicegroup=NULL;
01154         int result=OK;
01155 
01156         /* make sure we have the data we need */
01157         if(name==NULL || !strcmp(name,"")){
01158                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup name is NULL\n");
01159                 return NULL;
01160                 }
01161 
01162         /* allocate memory */
01163         if((new_servicegroup=(servicegroup *)calloc(1, sizeof(servicegroup)))==NULL)
01164                 return NULL;
01165 
01166         /* duplicate vars */
01167         if((new_servicegroup->group_name=(char *)strdup(name))==NULL)
01168                 result=ERROR;
01169         if((new_servicegroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
01170                 result=ERROR;
01171         if(notes){
01172                 if((new_servicegroup->notes=(char *)strdup(notes))==NULL)
01173                         result=ERROR;
01174                 }
01175         if(notes_url){
01176                 if((new_servicegroup->notes_url=(char *)strdup(notes_url))==NULL)
01177                         result=ERROR;
01178                 }
01179         if(action_url){
01180                 if((new_servicegroup->action_url=(char *)strdup(action_url))==NULL)
01181                         result=ERROR;
01182                 }
01183 
01184         /* add new service group to skiplist */
01185         if(result==OK){
01186                 result=skiplist_insert(object_skiplists[SERVICEGROUP_SKIPLIST],(void *)new_servicegroup);
01187                 switch(result){
01188                 case SKIPLIST_ERROR_DUPLICATE:
01189                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup '%s' has already been defined\n",name);
01190                         result=ERROR;
01191                         break;
01192                 case SKIPLIST_OK:
01193                         result=OK;
01194                         break;
01195                 default:
01196                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add servicegroup '%s' to skiplist\n",name);
01197                         result=ERROR;
01198                         break;
01199                         }
01200                 }
01201 
01202         /* handle errors */
01203         if(result==ERROR){
01204                 my_free(new_servicegroup->alias);
01205                 my_free(new_servicegroup->group_name);
01206                 my_free(new_servicegroup);
01207                 return NULL;
01208                 }
01209 
01210         /* servicegroups are sorted alphabetically, so add new items to tail of list */
01211         if(servicegroup_list==NULL){
01212                 servicegroup_list=new_servicegroup;
01213                 servicegroup_list_tail=servicegroup_list;
01214                 }
01215         else{
01216                 servicegroup_list_tail->next=new_servicegroup;
01217                 servicegroup_list_tail=new_servicegroup;
01218                 }
01219 
01220         return new_servicegroup;
01221         }
01222 
01223 
01224 /* add a new service to a service group */
01225 servicesmember *add_service_to_servicegroup(servicegroup *temp_servicegroup, char *host_name, char *svc_description){
01226         servicesmember *new_member=NULL;
01227         servicesmember *last_member=NULL;
01228         servicesmember *temp_member=NULL;
01229         int result=OK;
01230 
01231         /* make sure we have the data we need */
01232         if(temp_servicegroup==NULL || (host_name==NULL || !strcmp(host_name,"")) || (svc_description==NULL || !strcmp(svc_description,""))){
01233                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup or group member is NULL\n");
01234                 return NULL;
01235                 }
01236 
01237         /* allocate memory for a new member */
01238         if((new_member=calloc(1, sizeof(servicesmember)))==NULL)
01239                 return NULL;
01240 
01241         /* duplicate vars */
01242         if((new_member->host_name=(char *)strdup(host_name))==NULL)
01243                 result=ERROR;
01244         if((new_member->service_description=(char *)strdup(svc_description))==NULL)
01245                 result=ERROR;
01246 
01247         /* handle errors */
01248         if(result==ERROR){
01249                 my_free(new_member->service_description);
01250                 my_free(new_member->host_name);
01251                 my_free(new_member);
01252                 return NULL;
01253                 }
01254         
01255         /* add new member to member list, sorted by host name then service description */
01256         last_member=temp_servicegroup->members;
01257         for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
01258 
01259                 if(strcmp(new_member->host_name,temp_member->host_name)<0){
01260                         new_member->next=temp_member;
01261                         if(temp_member==temp_servicegroup->members)
01262                                 temp_servicegroup->members=new_member;
01263                         else
01264                                 last_member->next=new_member;
01265                         break;
01266                         }
01267 
01268                 else if(strcmp(new_member->host_name,temp_member->host_name)==0 && strcmp(new_member->service_description,temp_member->service_description)<0){
01269                         new_member->next=temp_member;
01270                         if(temp_member==temp_servicegroup->members)
01271                                 temp_servicegroup->members=new_member;
01272                         else
01273                                 last_member->next=new_member;
01274                         break;
01275                         }
01276 
01277                 else
01278                         last_member=temp_member;
01279                 }
01280         if(temp_servicegroup->members==NULL){
01281                 new_member->next=NULL;
01282                 temp_servicegroup->members=new_member;
01283                 }
01284         else if(temp_member==NULL){
01285                 new_member->next=NULL;
01286                 last_member->next=new_member;
01287                 }
01288 
01289         return new_member;
01290         }
01291 
01292 
01293 /* add a new contact to the list in memory */
01294 contact *add_contact(char *name,char *alias, char *email, char *pager, char **addresses, char *svc_notification_period, char *host_notification_period,int notify_service_ok,int notify_service_critical,int notify_service_warning, int notify_service_unknown, int notify_service_flapping, int notify_service_downtime, int notify_host_up, int notify_host_down, int notify_host_unreachable, int notify_host_flapping, int notify_host_downtime, int host_notifications_enabled, int service_notifications_enabled, int can_submit_commands, int retain_status_information, int retain_nonstatus_information){
01295         contact *new_contact=NULL;
01296         int x=0;
01297         int result=OK;
01298 
01299         /* make sure we have the data we need */
01300         if(name==NULL || !strcmp(name,"")){
01301                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact name is NULL\n");
01302                 return NULL;
01303                 }
01304 
01305         /* allocate memory for a new contact */
01306         if((new_contact=(contact *)calloc(1, sizeof(contact)))==NULL)
01307                 return NULL;
01308 
01309         /* duplicate vars */
01310         if((new_contact->name=(char *)strdup(name))==NULL)
01311                 result=ERROR;
01312         if((new_contact->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
01313                 result=ERROR;
01314         if(email){
01315                 if((new_contact->email=(char *)strdup(email))==NULL)
01316                         result=ERROR;
01317                 }
01318         if(pager){
01319                 if((new_contact->pager=(char *)strdup(pager))==NULL)
01320                         result=ERROR;
01321                 }
01322         if(svc_notification_period){
01323                 if((new_contact->service_notification_period=(char *)strdup(svc_notification_period))==NULL)
01324                         result=ERROR;
01325                 }
01326         if(host_notification_period){
01327                 if((new_contact->host_notification_period=(char *)strdup(host_notification_period))==NULL)
01328                         result=ERROR;
01329                 }
01330         if(addresses){
01331                 for(x=0;x<MAX_CONTACT_ADDRESSES;x++){
01332                         if(addresses[x]){
01333                                 if((new_contact->address[x]=(char *)strdup(addresses[x]))==NULL)
01334                                         result=ERROR;
01335                                 }
01336                         }
01337                 }
01338 
01339         new_contact->notify_on_service_recovery=(notify_service_ok>0)?TRUE:FALSE;
01340         new_contact->notify_on_service_critical=(notify_service_critical>0)?TRUE:FALSE;
01341         new_contact->notify_on_service_warning=(notify_service_warning>0)?TRUE:FALSE;
01342         new_contact->notify_on_service_unknown=(notify_service_unknown>0)?TRUE:FALSE;
01343         new_contact->notify_on_service_flapping=(notify_service_flapping>0)?TRUE:FALSE;
01344         new_contact->notify_on_service_downtime=(notify_service_downtime>0)?TRUE:FALSE;
01345         new_contact->notify_on_host_recovery=(notify_host_up>0)?TRUE:FALSE;
01346         new_contact->notify_on_host_down=(notify_host_down>0)?TRUE:FALSE;
01347         new_contact->notify_on_host_unreachable=(notify_host_unreachable>0)?TRUE:FALSE;
01348         new_contact->notify_on_host_flapping=(notify_host_flapping>0)?TRUE:FALSE;
01349         new_contact->notify_on_host_downtime=(notify_host_downtime>0)?TRUE:FALSE;
01350         new_contact->host_notifications_enabled=(host_notifications_enabled>0)?TRUE:FALSE;
01351         new_contact->service_notifications_enabled=(service_notifications_enabled>0)?TRUE:FALSE;
01352         new_contact->can_submit_commands=(can_submit_commands>0)?TRUE:FALSE;
01353         new_contact->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
01354         new_contact->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
01355 #ifdef NSCORE
01356         new_contact->last_host_notification=(time_t)0L;
01357         new_contact->last_service_notification=(time_t)0L;
01358         new_contact->modified_attributes=MODATTR_NONE;
01359         new_contact->modified_host_attributes=MODATTR_NONE;
01360         new_contact->modified_service_attributes=MODATTR_NONE;
01361 
01362         new_contact->host_notification_period_ptr=NULL;
01363         new_contact->service_notification_period_ptr=NULL;
01364         new_contact->contactgroups_ptr=NULL;
01365 #endif
01366 
01367         /* add new contact to skiplist */
01368         if(result==OK){
01369                 result=skiplist_insert(object_skiplists[CONTACT_SKIPLIST],(void *)new_contact);
01370                 switch(result){
01371                 case SKIPLIST_ERROR_DUPLICATE:
01372                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact '%s' has already been defined\n",name);
01373                         result=ERROR;
01374                         break;
01375                 case SKIPLIST_OK:
01376                         result=OK;
01377                         break;
01378                 default:
01379                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to skiplist\n",name);
01380                         result=ERROR;
01381                         break;
01382                         }
01383                 }
01384 
01385         /* handle errors */
01386         if(result==ERROR){
01387                 for(x=0;x<MAX_CONTACT_ADDRESSES;x++)
01388                         my_free(new_contact->address[x]);
01389                 my_free(new_contact->name);
01390                 my_free(new_contact->alias);
01391                 my_free(new_contact->email);
01392                 my_free(new_contact->pager);
01393                 my_free(new_contact->service_notification_period);
01394                 my_free(new_contact->host_notification_period);
01395                 my_free(new_contact);
01396                 return NULL;
01397                 }
01398 
01399         /* contacts are sorted alphabetically, so add new items to tail of list */
01400         if(contact_list==NULL){
01401                 contact_list=new_contact;
01402                 contact_list_tail=contact_list;
01403                 }
01404         else{
01405                 contact_list_tail->next=new_contact;
01406                 contact_list_tail=new_contact;
01407                 }
01408 
01409         return new_contact;
01410         }
01411 
01412 
01413 
01414 /* adds a host notification command to a contact definition */
01415 commandsmember *add_host_notification_command_to_contact(contact *cntct,char *command_name){
01416         commandsmember *new_commandsmember=NULL;
01417         int result=OK;
01418 
01419         /* make sure we have the data we need */
01420         if(cntct==NULL || (command_name==NULL || !strcmp(command_name,""))){
01421                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact or host notification command is NULL\n");
01422                 return NULL;
01423                 }
01424 
01425         /* allocate memory */
01426         if((new_commandsmember=calloc(1, sizeof(commandsmember)))==NULL)
01427                 return NULL;
01428 
01429         /* duplicate vars */
01430         if((new_commandsmember->command=(char *)strdup(command_name))==NULL)
01431                 result=ERROR;
01432 
01433         /* handle errors */
01434         if(result==ERROR){
01435                 my_free(new_commandsmember->command);
01436                 my_free(new_commandsmember);
01437                 return NULL;
01438                 }
01439 
01440         /* add the notification command */
01441         new_commandsmember->next=cntct->host_notification_commands;
01442         cntct->host_notification_commands=new_commandsmember;
01443 
01444         return new_commandsmember;
01445         }
01446 
01447 
01448 
01449 /* adds a service notification command to a contact definition */
01450 commandsmember *add_service_notification_command_to_contact(contact *cntct,char *command_name){
01451         commandsmember *new_commandsmember=NULL;
01452         int result=OK;
01453 
01454         /* make sure we have the data we need */
01455         if(cntct==NULL || (command_name==NULL || !strcmp(command_name,""))){
01456                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact or service notification command is NULL\n");
01457                 return NULL;
01458                 }
01459 
01460         /* allocate memory */
01461         if((new_commandsmember=calloc(1, sizeof(commandsmember)))==NULL)
01462                 return NULL;
01463 
01464         /* duplicate vars */
01465         if((new_commandsmember->command=(char *)strdup(command_name))==NULL)
01466                 result=ERROR;
01467 
01468         /* handle errors */
01469         if(result==ERROR){
01470                 my_free(new_commandsmember->command);
01471                 my_free(new_commandsmember);
01472                 return NULL;
01473                 }
01474 
01475         /* add the notification command */
01476         new_commandsmember->next=cntct->service_notification_commands;
01477         cntct->service_notification_commands=new_commandsmember;
01478 
01479         return new_commandsmember;
01480         }
01481 
01482 
01483 
01484 /* adds a custom variable to a contact */
01485 customvariablesmember *add_custom_variable_to_contact(contact *cntct, char *varname, char *varvalue){
01486 
01487         return add_custom_variable_to_object(&cntct->custom_variables,varname,varvalue);
01488         }
01489 
01490 
01491 
01492 /* add a new contact group to the list in memory */
01493 contactgroup *add_contactgroup(char *name,char *alias){
01494         contactgroup *new_contactgroup=NULL;
01495         int result=OK;
01496 
01497         /* make sure we have the data we need */
01498         if(name==NULL || !strcmp(name,"")){
01499                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup name is NULL\n");
01500                 return NULL;
01501                 }
01502 
01503         /* allocate memory for a new contactgroup entry */
01504         if((new_contactgroup=calloc(1, sizeof(contactgroup)))==NULL)
01505                 return NULL;
01506 
01507         /* duplicate vars */
01508         if((new_contactgroup->group_name=(char *)strdup(name))==NULL)
01509                 result=ERROR;
01510         if((new_contactgroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
01511                 result=ERROR;
01512 
01513         /* add new contact group to skiplist */
01514         if(result==OK){
01515                 result=skiplist_insert(object_skiplists[CONTACTGROUP_SKIPLIST],(void *)new_contactgroup);
01516                 switch(result){
01517                 case SKIPLIST_ERROR_DUPLICATE:
01518                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup '%s' has already been defined\n",name);
01519                         result=ERROR;
01520                         break;
01521                 case SKIPLIST_OK:
01522                         result=OK;
01523                         break;
01524                 default:
01525                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to skiplist\n",name);
01526                         result=ERROR;
01527                         break;
01528                         }
01529                 }
01530 
01531         /* handle errors */
01532         if(result==ERROR){
01533                 my_free(new_contactgroup->alias);
01534                 my_free(new_contactgroup->group_name);
01535                 my_free(new_contactgroup);
01536                 return NULL;
01537                 }
01538 
01539         /* contactgroups are sorted alphabetically, so add new items to tail of list */
01540         if(contactgroup_list==NULL){
01541                 contactgroup_list=new_contactgroup;
01542                 contactgroup_list_tail=contactgroup_list;
01543                 }
01544         else{
01545                 contactgroup_list_tail->next=new_contactgroup;
01546                 contactgroup_list_tail=new_contactgroup;
01547                 }
01548 
01549         return new_contactgroup;
01550         }
01551 
01552 
01553 
01554 /* add a new member to a contact group */
01555 contactsmember *add_contact_to_contactgroup(contactgroup *grp, char *contact_name){
01556         contactsmember *new_contactsmember=NULL;
01557         int result=OK;
01558 
01559         /* make sure we have the data we need */
01560         if(grp==NULL || (contact_name==NULL || !strcmp(contact_name,""))){
01561                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup or contact name is NULL\n");
01562                 return NULL;
01563                 }
01564 
01565         /* allocate memory for a new member */
01566         if((new_contactsmember=calloc(1, sizeof(contactsmember)))==NULL)
01567                 return NULL;
01568 
01569         /* duplicate vars */
01570         if((new_contactsmember->contact_name=(char *)strdup(contact_name))==NULL)
01571                 result=ERROR;
01572 
01573         /* handle errors */
01574         if(result==ERROR){
01575                 my_free(new_contactsmember->contact_name);
01576                 my_free(new_contactsmember);
01577                 return NULL;
01578                 }
01579         
01580         /* add the new member to the head of the member list */
01581         new_contactsmember->next=grp->members;
01582         grp->members=new_contactsmember;
01583 
01584         return new_contactsmember;
01585         }
01586 
01587 
01588 
01589 /* add a new service to the list in memory */
01590 service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notify_downtime, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_ok, int flap_detection_on_warning, int flap_detection_on_unknown, int flap_detection_on_critical, int stalk_on_ok, int stalk_on_warning, int stalk_on_unknown, int stalk_on_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){
01591         service *new_service=NULL;
01592         int result=OK;
01593 #ifdef NSCORE
01594         int x=0;
01595 #endif
01596 
01597         /* make sure we have everything we need */
01598         if((host_name==NULL || !strcmp(host_name,"")) || (description==NULL || !strcmp(description,"")) || (check_command==NULL || !strcmp(check_command,""))){
01599                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service description, host name, or check command is NULL\n");
01600                 return NULL;
01601                 }
01602 
01603         /* check values */
01604         if(max_attempts<=0 || check_interval<0 || retry_interval<=0 || notification_interval<0){
01605                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid max_check_attempts, check_interval, retry_interval, or notification_interval value for service '%s' on host '%s'\n",description,host_name);
01606                 return NULL;
01607                 }
01608 
01609         if(first_notification_delay<0){
01610                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid first_notification_delay value for service '%s' on host '%s'\n",description,host_name);
01611                 return NULL;
01612                 }
01613 
01614         /* allocate memory */
01615         if((new_service=(service *)calloc(1, sizeof(service)))==NULL)
01616                 return NULL;
01617 
01618         /* duplicate vars */
01619         if((new_service->host_name=(char *)strdup(host_name))==NULL)
01620                 result=ERROR;
01621         if((new_service->description=(char *)strdup(description))==NULL)
01622                 result=ERROR;
01623         if((new_service->display_name=(char *)strdup((display_name==NULL)?description:display_name))==NULL)
01624                 result=ERROR;
01625         if((new_service->service_check_command=(char *)strdup(check_command))==NULL)
01626                 result=ERROR;
01627         if(event_handler){
01628                 if((new_service->event_handler=(char *)strdup(event_handler))==NULL)
01629                         result=ERROR;
01630                 }
01631         if(notification_period){
01632                 if((new_service->notification_period=(char *)strdup(notification_period))==NULL)
01633                         result=ERROR;
01634                 }
01635         if(check_period){
01636                 if((new_service->check_period=(char *)strdup(check_period))==NULL)
01637                         result=ERROR;
01638                 }
01639         if(failure_prediction_options){
01640                 if((new_service->failure_prediction_options=(char *)strdup(failure_prediction_options))==NULL)
01641                         result=ERROR;
01642                 }
01643         if(notes){
01644                 if((new_service->notes=(char *)strdup(notes))==NULL)
01645                         result=ERROR;
01646                 }
01647         if(notes_url){
01648                 if((new_service->notes_url=(char *)strdup(notes_url))==NULL)
01649                         result=ERROR;
01650                 }
01651         if(action_url){
01652                 if((new_service->action_url=(char *)strdup(action_url))==NULL)
01653                         result=ERROR;
01654                 }
01655         if(icon_image){
01656                 if((new_service->icon_image=(char *)strdup(icon_image))==NULL)
01657                         result=ERROR;
01658                 }
01659         if(icon_image_alt){
01660                 if((new_service->icon_image_alt=(char *)strdup(icon_image_alt))==NULL)
01661                         result=ERROR;
01662                 }
01663 
01664         new_service->check_interval=check_interval;
01665         new_service->retry_interval=retry_interval;
01666         new_service->max_attempts=max_attempts;
01667         new_service->parallelize=(parallelize>0)?TRUE:FALSE;
01668         new_service->notification_interval=notification_interval;
01669         new_service->first_notification_delay=first_notification_delay;
01670         new_service->notify_on_unknown=(notify_unknown>0)?TRUE:FALSE;
01671         new_service->notify_on_warning=(notify_warning>0)?TRUE:FALSE;
01672         new_service->notify_on_critical=(notify_critical>0)?TRUE:FALSE;
01673         new_service->notify_on_recovery=(notify_recovery>0)?TRUE:FALSE;
01674         new_service->notify_on_flapping=(notify_flapping>0)?TRUE:FALSE;
01675         new_service->notify_on_downtime=(notify_downtime>0)?TRUE:FALSE;
01676         new_service->is_volatile=(is_volatile>0)?((is_volatile==2)?VOLATILE_WITH_RENOTIFICATION_INTERVAL:TRUE):FALSE;
01677         new_service->flap_detection_enabled=(flap_detection_enabled>0)?TRUE:FALSE;
01678         new_service->low_flap_threshold=low_flap_threshold;
01679         new_service->high_flap_threshold=high_flap_threshold;
01680         new_service->flap_detection_on_ok=(flap_detection_on_ok>0)?TRUE:FALSE;
01681         new_service->flap_detection_on_warning=(flap_detection_on_warning>0)?TRUE:FALSE;
01682         new_service->flap_detection_on_unknown=(flap_detection_on_unknown>0)?TRUE:FALSE;
01683         new_service->flap_detection_on_critical=(flap_detection_on_critical>0)?TRUE:FALSE;
01684         new_service->stalk_on_ok=(stalk_on_ok>0)?TRUE:FALSE;
01685         new_service->stalk_on_warning=(stalk_on_warning>0)?TRUE:FALSE;
01686         new_service->stalk_on_unknown=(stalk_on_unknown>0)?TRUE:FALSE;
01687         new_service->stalk_on_critical=(stalk_on_critical>0)?TRUE:FALSE;
01688         new_service->process_performance_data=(process_perfdata>0)?TRUE:FALSE;
01689         new_service->check_freshness=(check_freshness>0)?TRUE:FALSE;
01690         new_service->freshness_threshold=freshness_threshold;
01691         new_service->accept_passive_service_checks=(accept_passive_checks>0)?TRUE:FALSE;
01692         new_service->event_handler_enabled=(event_handler_enabled>0)?TRUE:FALSE;
01693         new_service->checks_enabled=(checks_enabled>0)?TRUE:FALSE;
01694         new_service->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
01695         new_service->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
01696         new_service->notifications_enabled=(notifications_enabled>0)?TRUE:FALSE;
01697         new_service->obsess_over_service=(obsess_over_service>0)?TRUE:FALSE;
01698         new_service->failure_prediction_enabled=(failure_prediction_enabled>0)?TRUE:FALSE;
01699 #ifdef NSCORE
01700         new_service->problem_has_been_acknowledged=FALSE;
01701         new_service->acknowledgement_type=ACKNOWLEDGEMENT_NONE;
01702         new_service->check_type=SERVICE_CHECK_ACTIVE;
01703         new_service->current_attempt=(initial_state==STATE_OK)?1:max_attempts;
01704         new_service->current_state=initial_state;
01705         new_service->current_event_id=0L;
01706         new_service->last_event_id=0L;
01707         new_service->current_problem_id=0L;
01708         new_service->last_problem_id=0L;
01709         new_service->last_state=initial_state;
01710         new_service->last_hard_state=initial_state;
01711         new_service->state_type=HARD_STATE;
01712         new_service->host_problem_at_last_check=FALSE;
01713         new_service->check_flapping_recovery_notification=FALSE;
01714         new_service->next_check=(time_t)0;
01715         new_service->should_be_scheduled=TRUE;
01716         new_service->last_check=(time_t)0;
01717         new_service->last_notification=(time_t)0;
01718         new_service->next_notification=(time_t)0;
01719         new_service->no_more_notifications=FALSE;
01720         new_service->last_state_change=(time_t)0;
01721         new_service->last_hard_state_change=(time_t)0;
01722         new_service->last_time_ok=(time_t)0;
01723         new_service->last_time_warning=(time_t)0;
01724         new_service->last_time_unknown=(time_t)0;
01725         new_service->last_time_critical=(time_t)0;
01726         new_service->has_been_checked=FALSE;
01727         new_service->is_being_freshened=FALSE;
01728         new_service->notified_on_unknown=FALSE;
01729         new_service->notified_on_warning=FALSE;
01730         new_service->notified_on_critical=FALSE;
01731         new_service->current_notification_number=0;
01732 #ifdef USE_ST_BASED_ESCAL_RANGES
01733         new_service->current_warning_notification_number=0;
01734         new_service->current_critical_notification_number=0;
01735         new_service->current_unknown_notification_number=0;
01736 #endif
01737         new_service->current_notification_id=0L;
01738         new_service->latency=0.0;
01739         new_service->execution_time=0.0;
01740         new_service->is_executing=FALSE;
01741         new_service->check_options=CHECK_OPTION_NONE;
01742         new_service->scheduled_downtime_depth=0;
01743         new_service->pending_flex_downtime=0;
01744         for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
01745                 new_service->state_history[x]=STATE_OK;
01746         new_service->state_history_index=0;
01747         new_service->is_flapping=FALSE;
01748         new_service->flapping_comment_id=0;
01749         new_service->percent_state_change=0.0;
01750         new_service->modified_attributes=MODATTR_NONE;
01751 #endif
01752 
01753         /* add new service to skiplist */
01754         if(result==OK){
01755                 result=skiplist_insert(object_skiplists[SERVICE_SKIPLIST],(void *)new_service);
01756                 switch(result){
01757                 case SKIPLIST_ERROR_DUPLICATE:
01758                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service '%s' on host '%s' has already been defined\n",description,host_name);
01759                         result=ERROR;
01760                         break;
01761                 case SKIPLIST_OK:
01762                         result=OK;
01763                         break;
01764                 default:
01765                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service '%s' on host '%s' to skiplist\n",description,host_name);
01766                         result=ERROR;
01767                         break;
01768                         }
01769                 }
01770 
01771         /* handle errors */
01772         if(result==ERROR){
01773 #ifdef NSCORE
01774                 my_free(new_service->perf_data);
01775                 my_free(new_service->plugin_output);
01776                 my_free(new_service->long_plugin_output);
01777 #endif
01778                 my_free(new_service->failure_prediction_options);
01779                 my_free(new_service->notification_period);
01780                 my_free(new_service->event_handler);
01781                 my_free(new_service->service_check_command);
01782                 my_free(new_service->description);
01783                 my_free(new_service->host_name);
01784                 my_free(new_service);
01785                 return NULL;
01786                 }
01787 
01788         /* services are sorted alphabetically, so add new items to tail of list */
01789         if(service_list==NULL){
01790                 service_list=new_service;
01791                 service_list_tail=service_list;
01792                 }
01793         else{
01794                 service_list_tail->next=new_service;
01795                 service_list_tail=new_service;
01796                 }
01797 
01798         return new_service;
01799         }
01800 
01801 
01802 
01803 /* adds a contact group to a service */
01804 contactgroupsmember *add_contactgroup_to_service(service *svc,char *group_name){
01805         contactgroupsmember *new_contactgroupsmember=NULL;
01806         int result=OK;
01807 
01808         /* bail out if we weren't given the data we need */
01809         if(svc==NULL || (group_name==NULL || !strcmp(group_name,""))){
01810                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service or contactgroup name is NULL\n");
01811                 return NULL;
01812                 }
01813 
01814         /* allocate memory for the contactgroups member */
01815         if((new_contactgroupsmember=calloc(1, sizeof(contactgroupsmember)))==NULL)
01816                 return NULL;
01817 
01818         /* duplicate vars */
01819         if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
01820                 result=ERROR;
01821 
01822         /* handle errors */
01823         if(result==ERROR){
01824                 my_free(new_contactgroupsmember);
01825                 return NULL;
01826                 }
01827 
01828         /* add this contactgroup to the service */
01829         new_contactgroupsmember->next=svc->contact_groups;
01830         svc->contact_groups=new_contactgroupsmember;
01831 
01832         return new_contactgroupsmember;
01833         }
01834 
01835 
01836 
01837 /* adds a contact to a service */
01838 contactsmember *add_contact_to_service(service *svc, char *contact_name){
01839 
01840         return add_contact_to_object(&svc->contacts,contact_name);
01841         }
01842 
01843 
01844 
01845 /* adds a custom variable to a service */
01846 customvariablesmember *add_custom_variable_to_service(service *svc, char *varname, char *varvalue){
01847 
01848         return add_custom_variable_to_object(&svc->custom_variables,varname,varvalue);
01849         }
01850 
01851 
01852 
01853 /* add a new command to the list in memory */
01854 command *add_command(char *name,char *value){
01855         command *new_command=NULL;
01856         int result=OK;
01857 
01858         /* make sure we have the data we need */
01859         if((name==NULL || !strcmp(name,"")) || (value==NULL || !strcmp(value,""))){
01860                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Command name of command line is NULL\n");
01861                 return NULL;
01862                 }
01863 
01864         /* allocate memory for the new command */
01865         if((new_command=(command *)calloc(1, sizeof(command)))==NULL)
01866                 return NULL;
01867 
01868         /* duplicate vars */
01869         if((new_command->name=(char *)strdup(name))==NULL)
01870                 result=ERROR;
01871         if((new_command->command_line=(char *)strdup(value))==NULL)
01872                 result=ERROR;
01873 
01874         /* add new command to skiplist */
01875         if(result==OK){
01876                 result=skiplist_insert(object_skiplists[COMMAND_SKIPLIST],(void *)new_command);
01877                 switch(result){
01878                 case SKIPLIST_ERROR_DUPLICATE:
01879                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Command '%s' has already been defined\n",name);
01880                         result=ERROR;
01881                         break;
01882                 case SKIPLIST_OK:
01883                         result=OK;
01884                         break;
01885                 default:
01886                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add command '%s' to skiplist\n",name);
01887                         result=ERROR;
01888                         break;
01889                         }
01890                 }
01891 
01892         /* handle errors */
01893         if(result==ERROR){
01894                 my_free(new_command->command_line);
01895                 my_free(new_command->name);
01896                 my_free(new_command);
01897                 return NULL;
01898                 }
01899 
01900         /* commands are sorted alphabetically, so add new items to tail of list */
01901         if(command_list==NULL){
01902                 command_list=new_command;
01903                 command_list_tail=command_list;
01904                 }
01905         else {
01906                 command_list_tail->next=new_command;
01907                 command_list_tail=new_command;
01908                 }
01909 
01910         return new_command;
01911         }
01912 
01913 
01914 
01915 /* add a new service escalation to the list in memory */
01916 #ifndef USE_ST_BASED_ESCAL_RANGES
01917 serviceescalation *add_serviceescalation(char *host_name,char *description, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_recovery){
01918 #else
01919 serviceescalation *add_serviceescalation(char *host_name,char *description, int first_notification, int last_notification, int first_warning_notification, int last_warning_notification, int first_critical_notification, int last_critical_notification, int first_unknown_notification, int last_unknown_notification, double notification_interval, char *escalation_period, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_recovery){
01920 #endif
01921         serviceescalation *new_serviceescalation=NULL;
01922         int result=OK;
01923 
01924         /* make sure we have the data we need */
01925         if((host_name==NULL || !strcmp(host_name,"")) || (description==NULL || !strcmp(description,""))){
01926                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service escalation host name or description is NULL\n");
01927                 return NULL;
01928                 }
01929 
01930 #ifdef TEST
01931         printf("NEW SVC ESCALATION: %s/%s = %d/%d/%.3f\n",host_name,description,first_notification,last_notification,notification_interval);
01932 #endif
01933 
01934         /* allocate memory for a new service escalation entry */
01935         if((new_serviceescalation=calloc(1, sizeof(serviceescalation)))==NULL)
01936                 return NULL;
01937 
01938         /* duplicate vars */
01939         if((new_serviceescalation->host_name=(char *)strdup(host_name))==NULL)
01940                 result=ERROR;
01941         if((new_serviceescalation->description=(char *)strdup(description))==NULL)
01942                 result=ERROR;
01943         if(escalation_period){
01944                 if((new_serviceescalation->escalation_period=(char *)strdup(escalation_period))==NULL)
01945                         result=ERROR;
01946                 }
01947 
01948         new_serviceescalation->first_notification=first_notification;
01949         new_serviceescalation->last_notification=last_notification;
01950 #ifdef USE_ST_BASED_ESCAL_RANGES
01951         new_serviceescalation->first_warning_notification=first_warning_notification;
01952         new_serviceescalation->last_warning_notification=last_warning_notification;
01953         new_serviceescalation->first_critical_notification=first_critical_notification;
01954         new_serviceescalation->last_critical_notification=last_critical_notification;
01955         new_serviceescalation->first_unknown_notification=first_unknown_notification;
01956         new_serviceescalation->last_unknown_notification=last_unknown_notification;
01957 #endif
01958         new_serviceescalation->notification_interval=(notification_interval<=0)?0:notification_interval;
01959         new_serviceescalation->escalate_on_recovery=(escalate_on_recovery>0)?TRUE:FALSE;
01960         new_serviceescalation->escalate_on_warning=(escalate_on_warning>0)?TRUE:FALSE;
01961         new_serviceescalation->escalate_on_unknown=(escalate_on_unknown>0)?TRUE:FALSE;
01962         new_serviceescalation->escalate_on_critical=(escalate_on_critical>0)?TRUE:FALSE;
01963 
01964         /* add new serviceescalation to skiplist */
01965         if(result==OK){
01966                 result=skiplist_insert(object_skiplists[SERVICEESCALATION_SKIPLIST],(void *)new_serviceescalation);
01967                 switch(result){
01968                 case SKIPLIST_OK:
01969                         result=OK;
01970                         break;
01971                 default:
01972                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add escalation for service '%s' on host '%s' to skiplist\n",description,host_name);
01973                         result=ERROR;
01974                         break;
01975                         }
01976                 }
01977 
01978         /* handle errors */
01979         if(result==ERROR){
01980                 my_free(new_serviceescalation->host_name);
01981                 my_free(new_serviceescalation->description);
01982                 my_free(new_serviceescalation->escalation_period);
01983                 my_free(new_serviceescalation);
01984                 return NULL;
01985                 }
01986 
01987         /* service escalations are sorted alphabetically, so add new items to tail of list */
01988         if(serviceescalation_list==NULL){
01989                 serviceescalation_list=new_serviceescalation;
01990                 serviceescalation_list_tail=serviceescalation_list;
01991                 }
01992         else{
01993                 serviceescalation_list_tail->next=new_serviceescalation;
01994                 serviceescalation_list_tail=new_serviceescalation;
01995                 }
01996 
01997         return new_serviceescalation;
01998         }
01999 
02000 
02001 
02002 /* adds a contact group to a service escalation */
02003 contactgroupsmember *add_contactgroup_to_serviceescalation(serviceescalation *se,char *group_name){
02004         contactgroupsmember *new_contactgroupsmember=NULL;
02005         int result=OK;
02006 
02007         /* bail out if we weren't given the data we need */
02008         if(se==NULL || (group_name==NULL || !strcmp(group_name,""))){
02009                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service escalation or contactgroup name is NULL\n");
02010                 return NULL;
02011                 }
02012 
02013         /* allocate memory for the contactgroups member */
02014         if((new_contactgroupsmember=(contactgroupsmember *)calloc(1, sizeof(contactgroupsmember)))==NULL)
02015                 return NULL;
02016 
02017         /* duplicate vars */
02018         if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
02019                 result=ERROR;
02020 
02021         /* handle errors */
02022         if(result==ERROR){
02023                 my_free(new_contactgroupsmember->group_name);
02024                 my_free(new_contactgroupsmember);
02025                 return NULL;
02026                 }
02027 
02028         /* add this contactgroup to the service escalation */
02029         new_contactgroupsmember->next=se->contact_groups;
02030         se->contact_groups=new_contactgroupsmember;
02031 
02032         return new_contactgroupsmember;
02033         }
02034 
02035 
02036 
02037 /* adds a contact to a service escalation */
02038 contactsmember *add_contact_to_serviceescalation(serviceescalation *se, char *contact_name){
02039 
02040         return add_contact_to_object(&se->contacts,contact_name);
02041         }
02042 
02043 
02044 
02045 /* adds a service dependency definition */
02046 servicedependency *add_service_dependency(char *dependent_host_name, char *dependent_service_description, char *host_name, char *service_description, int dependency_type, int inherits_parent, int fail_on_ok, int fail_on_warning, int fail_on_unknown, int fail_on_critical, int fail_on_pending, char *dependency_period){
02047         servicedependency *new_servicedependency=NULL;
02048         int result=OK;
02049 
02050         /* make sure we have what we need */
02051         if((host_name==NULL || !strcmp(host_name,"")) || (service_description==NULL || !strcmp(service_description,""))){
02052                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL master service description/host name in service dependency definition\n");
02053                 return NULL;
02054                 }
02055         if((dependent_host_name==NULL || !strcmp(dependent_host_name,"")) || (dependent_service_description==NULL || !strcmp(dependent_service_description,""))){
02056                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL dependent service description/host name in service dependency definition\n");
02057                 return NULL;
02058                 }
02059 
02060         /* allocate memory for a new service dependency entry */
02061         if((new_servicedependency=(servicedependency *)calloc(1, sizeof(servicedependency)))==NULL)
02062                 return NULL;
02063 
02064         /* duplicate vars */
02065         if((new_servicedependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
02066                 result=ERROR;
02067         if((new_servicedependency->dependent_service_description=(char *)strdup(dependent_service_description))==NULL)
02068                 result=ERROR;
02069         if((new_servicedependency->host_name=(char *)strdup(host_name))==NULL)
02070                 result=ERROR;
02071         if((new_servicedependency->service_description=(char *)strdup(service_description))==NULL)
02072                 result=ERROR;
02073         if(dependency_period){
02074                 if((new_servicedependency->dependency_period=(char *)strdup(dependency_period))==NULL)
02075                         result=ERROR;
02076                 }
02077 
02078         new_servicedependency->dependency_type=(dependency_type==EXECUTION_DEPENDENCY)?EXECUTION_DEPENDENCY:NOTIFICATION_DEPENDENCY;
02079         new_servicedependency->inherits_parent=(inherits_parent>0)?TRUE:FALSE;
02080         new_servicedependency->fail_on_ok=(fail_on_ok==1)?TRUE:FALSE;
02081         new_servicedependency->fail_on_warning=(fail_on_warning==1)?TRUE:FALSE;
02082         new_servicedependency->fail_on_unknown=(fail_on_unknown==1)?TRUE:FALSE;
02083         new_servicedependency->fail_on_critical=(fail_on_critical==1)?TRUE:FALSE;
02084         new_servicedependency->fail_on_pending=(fail_on_pending==1)?TRUE:FALSE;
02085 #ifdef NSCORE
02086         new_servicedependency->circular_path_checked=FALSE;
02087         new_servicedependency->contains_circular_path=FALSE;
02088 #endif
02089 
02090         /* add new service dependency to skiplist */
02091         if(result==OK){
02092                 result=skiplist_insert(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],(void *)new_servicedependency);
02093                 switch(result){
02094                 case SKIPLIST_OK:
02095                         result=OK;
02096                         break;
02097                 default:
02098                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service dependency to skiplist\n");
02099                         result=ERROR;
02100                         break;
02101                         }
02102                 }
02103 
02104         /* handle errors */
02105         if(result==ERROR){
02106                 my_free(new_servicedependency->host_name);
02107                 my_free(new_servicedependency->service_description);
02108                 my_free(new_servicedependency->dependent_host_name);
02109                 my_free(new_servicedependency->dependent_service_description);
02110                 my_free(new_servicedependency);
02111                 return NULL;
02112                 }
02113 
02114         /* service dependencies are sorted alphabetically, so add new items to tail of list */
02115         if(servicedependency_list==NULL){
02116                 servicedependency_list=new_servicedependency;
02117                 servicedependency_list_tail=servicedependency_list;
02118                 }
02119         else{
02120                 servicedependency_list_tail->next=new_servicedependency;
02121                 servicedependency_list_tail=new_servicedependency;
02122                 }
02123 
02124         return new_servicedependency;
02125         }
02126 
02127 
02128 /* adds a host dependency definition */
02129 hostdependency *add_host_dependency(char *dependent_host_name, char *host_name, int dependency_type, int inherits_parent, int fail_on_up, int fail_on_down, int fail_on_unreachable, int fail_on_pending, char *dependency_period){
02130         hostdependency *new_hostdependency=NULL;
02131         int result=OK;
02132 
02133         /* make sure we have what we need */
02134         if((dependent_host_name==NULL || !strcmp(dependent_host_name,"")) || (host_name==NULL || !strcmp(host_name,""))){
02135                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL host name in host dependency definition\n");
02136                 return NULL;
02137                 }
02138 
02139         /* allocate memory for a new host dependency entry */
02140         if((new_hostdependency=(hostdependency *)calloc(1, sizeof(hostdependency)))==NULL)
02141                 return NULL;
02142 
02143         /* duplicate vars */
02144         if((new_hostdependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
02145                 result=ERROR;
02146         if((new_hostdependency->host_name=(char *)strdup(host_name))==NULL)
02147                 result=ERROR;
02148         if(dependency_period){
02149                 if((new_hostdependency->dependency_period=(char *)strdup(dependency_period))==NULL)
02150                         result=ERROR;
02151                 }
02152 
02153         new_hostdependency->dependency_type=(dependency_type==EXECUTION_DEPENDENCY)?EXECUTION_DEPENDENCY:NOTIFICATION_DEPENDENCY;
02154         new_hostdependency->inherits_parent=(inherits_parent>0)?TRUE:FALSE;
02155         new_hostdependency->fail_on_up=(fail_on_up==1)?TRUE:FALSE;
02156         new_hostdependency->fail_on_down=(fail_on_down==1)?TRUE:FALSE;
02157         new_hostdependency->fail_on_unreachable=(fail_on_unreachable==1)?TRUE:FALSE;
02158         new_hostdependency->fail_on_pending=(fail_on_pending==1)?TRUE:FALSE;
02159 #ifdef NSCORE
02160         new_hostdependency->circular_path_checked=FALSE;
02161         new_hostdependency->contains_circular_path=FALSE;
02162 #endif
02163 
02164         /* add new host dependency to skiplist */
02165         if(result==OK){
02166                 result=skiplist_insert(object_skiplists[HOSTDEPENDENCY_SKIPLIST],(void *)new_hostdependency);
02167                 switch(result){
02168                 case SKIPLIST_OK:
02169                         result=OK;
02170                         break;
02171                 default:
02172                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host dependency to skiplist\n");
02173                         result=ERROR;
02174                         break;
02175                         }
02176                 }
02177 
02178         /* handle errors */
02179         if(result==ERROR){
02180                 my_free(new_hostdependency->host_name);
02181                 my_free(new_hostdependency->dependent_host_name);
02182                 my_free(new_hostdependency);
02183                 return NULL;
02184                 }
02185 
02186         /* host dependencies are sorted alphabetically, so add new items to tail of list */
02187         if(hostdependency_list==NULL){
02188                 hostdependency_list=new_hostdependency;
02189                 hostdependency_list_tail=hostdependency_list;
02190                 }
02191         else {
02192                 hostdependency_list_tail->next=new_hostdependency;
02193                 hostdependency_list_tail=new_hostdependency;
02194                 }
02195 
02196         return new_hostdependency;
02197         }
02198 
02199 
02200 
02201 /* add a new host escalation to the list in memory */
02202 #ifndef USE_ST_BASED_ESCAL_RANGES
02203 hostescalation *add_hostescalation(char *host_name,int first_notification,int last_notification, double notification_interval, char *escalation_period, int escalate_on_down, int escalate_on_unreachable, int escalate_on_recovery){
02204 #else
02205 hostescalation *add_hostescalation(char *host_name,int first_notification,int last_notification, int first_down_notification, int last_down_notification, int first_unreachable_notification, int last_unreachable_notification, double notification_interval, char *escalation_period, int escalate_on_down, int escalate_on_unreachable, int escalate_on_recovery){
02206 #endif
02207         hostescalation *new_hostescalation=NULL;
02208         int result=OK;
02209 
02210         /* make sure we have the data we need */
02211         if(host_name==NULL || !strcmp(host_name,"")){
02212                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host escalation host name is NULL\n");
02213                 return NULL;
02214                 }
02215 
02216 #ifdef TEST
02217         printf("NEW HST ESCALATION: %s = %d/%d/%.3f\n",host_name,first_notification,last_notification,notification_interval);
02218 #endif
02219 
02220         /* allocate memory for a new host escalation entry */
02221         if((new_hostescalation=calloc(1, sizeof(hostescalation)))==NULL)
02222                 return NULL;
02223 
02224         /* duplicate vars */
02225         if((new_hostescalation->host_name=(char *)strdup(host_name))==NULL)
02226                 result=ERROR;
02227         if(escalation_period){
02228                 if((new_hostescalation->escalation_period=(char *)strdup(escalation_period))==NULL)
02229                         result=ERROR;
02230                 }
02231 
02232         new_hostescalation->first_notification=first_notification;
02233         new_hostescalation->last_notification=last_notification;
02234 #ifdef USE_ST_BASED_ESCAL_RANGES
02235         new_hostescalation->first_down_notification=first_down_notification;
02236         new_hostescalation->last_down_notification=last_down_notification;
02237         new_hostescalation->first_unreachable_notification=first_unreachable_notification;
02238         new_hostescalation->last_unreachable_notification=last_unreachable_notification;
02239 #endif
02240         new_hostescalation->notification_interval=(notification_interval<=0)?0:notification_interval;
02241         new_hostescalation->escalate_on_recovery=(escalate_on_recovery>0)?TRUE:FALSE;
02242         new_hostescalation->escalate_on_down=(escalate_on_down>0)?TRUE:FALSE;
02243         new_hostescalation->escalate_on_unreachable=(escalate_on_unreachable>0)?TRUE:FALSE;
02244 
02245         /* add new hostescalation to skiplist */
02246         if(result==OK){
02247                 result=skiplist_insert(object_skiplists[HOSTESCALATION_SKIPLIST],(void *)new_hostescalation);
02248                 switch(result){
02249                 case SKIPLIST_OK:
02250                         result=OK;
02251                         break;
02252                 default:
02253                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add hostescalation '%s' to skiplist\n",host_name);
02254                         result=ERROR;
02255                         break;
02256                         }
02257                 }
02258 
02259         /* handle errors */
02260         if(result==ERROR){
02261                 my_free(new_hostescalation->host_name);
02262                 my_free(new_hostescalation->escalation_period);
02263                 my_free(new_hostescalation);
02264                 return NULL;
02265                 }
02266 
02267         /* host escalations are sorted alphabetically, so add new items to tail of list */
02268         if(hostescalation_list==NULL){
02269                 hostescalation_list=new_hostescalation;
02270                 hostescalation_list_tail=hostescalation_list;
02271                 }
02272         else{
02273                 hostescalation_list_tail->next=new_hostescalation;
02274                 hostescalation_list_tail=new_hostescalation;
02275                 }
02276 
02277         return new_hostescalation;
02278         }
02279 
02280 /* add a condition to a (host or service) escalation in memory */
02281 escalation_condition *add_host_service_escalation_condition(hostescalation *my_hostescalation, serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
02282         escalation_condition *new_escalation_condition=NULL;
02283         int result=OK;
02284           
02285         /* make sure we have the data we need */
02286         if(host_name==NULL || !strcmp(host_name,"")){
02287                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: escalation condition: host name is NULL\n");
02288                 return NULL;
02289         }
02290        
02291 #ifdef TEST
02292         printf("NEW ESCALATION CONDITION: host = %s; service = %s; connector = %d/\n",host_name,service_description,connector);
02293  #endif 
02294        
02295         /* remove whitespaces */
02296         strip(host_name);
02297         strip(service_description);
02298        
02299         /* allocate memory for a new escalation_condition entry */
02300         if((new_escalation_condition=malloc(sizeof(escalation_condition)))==NULL)
02301                 return NULL;
02302        
02303         /* initialize vars */
02304         new_escalation_condition->host_name=NULL;
02305         new_escalation_condition->service_description=NULL;
02306         new_escalation_condition->next=NULL;
02307         new_escalation_condition->escalate_on_warning=FALSE;
02308         new_escalation_condition->escalate_on_unknown=FALSE;
02309         new_escalation_condition->escalate_on_critical=FALSE;
02310         new_escalation_condition->escalate_on_ok=FALSE;
02311         new_escalation_condition->escalate_on_down=FALSE;
02312         new_escalation_condition->escalate_on_unreachable=FALSE;
02313         
02314         /* service condition */
02315         if(service_description!=NULL && strcmp(service_description,"")
02316                                 && host_name!=NULL && strcmp(host_name,"")) {
02317                 if((new_escalation_condition->host_name=(char *)strdup(host_name))==NULL)
02318                         result=ERROR;
02319                 if((new_escalation_condition->service_description=(char *)strdup(service_description))==NULL)
02320                         result=ERROR;
02321                         
02322                 new_escalation_condition->escalate_on_warning=(escalate_on_warning>0)?TRUE:FALSE;
02323                 new_escalation_condition->escalate_on_unknown=(escalate_on_unknown>0)?TRUE:FALSE;
02324                 new_escalation_condition->escalate_on_critical=(escalate_on_critical>0)?TRUE:FALSE;
02325                 new_escalation_condition->escalate_on_ok=(escalate_on_ok>0)?TRUE:FALSE;
02326         }
02327         
02328         /* host condition */
02329         else if(host_name!=NULL && strcmp(host_name,"")) {
02330                 if((new_escalation_condition->host_name=(char *)strdup(host_name))==NULL)
02331                         result=ERROR;
02332                        
02333                 new_escalation_condition->escalate_on_down=(escalate_on_down>0)?TRUE:FALSE;
02334                 new_escalation_condition->escalate_on_unreachable=(escalate_on_unreachable>0)?TRUE:FALSE;
02335                 new_escalation_condition->escalate_on_ok=(escalate_on_ok>0)?TRUE:FALSE;
02336         }
02337        
02338         /* connector to next condition */
02339         new_escalation_condition->connector=(connector>=0 && connector<=2)?connector : EC_CONNECTOR_NO;
02340        
02341         /* handle errors */
02342         if(result==ERROR){
02343                 my_free(new_escalation_condition->host_name);
02344                 my_free(new_escalation_condition->service_description);
02345                 my_free(new_escalation_condition);
02346                 return NULL;
02347                 }
02348         
02349         /* if head of escalation condition is NULL set it to new condition */
02350         if(my_serviceescalation!=NULL && my_serviceescalation->condition==NULL){
02351                 my_serviceescalation->condition=new_escalation_condition;
02352         }
02353         else if(my_hostescalation!=NULL && my_hostescalation->condition==NULL){
02354                 my_hostescalation->condition=new_escalation_condition;
02355         }
02356         /* else add new condition to the tail of condition list */
02357         else {
02358                 last_condition->next=new_escalation_condition;
02359         }
02360         return new_escalation_condition;
02361 }
02362 
02363 /* add a condition to a host escalation in memory */
02364 escalation_condition *add_hostescalation_condition(hostescalation *my_hostescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
02365         return add_host_service_escalation_condition(my_hostescalation, NULL, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
02366 }
02367 
02368 /* add a condition to a service escalation in memory */
02369 escalation_condition *add_serviceescalation_condition(serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
02370         return add_host_service_escalation_condition(NULL, my_serviceescalation, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
02371 }
02372 
02373 /* adds a contact group to a host escalation */
02374 contactgroupsmember *add_contactgroup_to_hostescalation(hostescalation *he,char *group_name){
02375         contactgroupsmember *new_contactgroupsmember=NULL;
02376         int result=OK;
02377 
02378         /* bail out if we weren't given the data we need */
02379         if(he==NULL || (group_name==NULL || !strcmp(group_name,""))){
02380                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host escalation or contactgroup name is NULL\n");
02381                 return NULL;
02382                 }
02383 
02384         /* allocate memory for the contactgroups member */
02385         if((new_contactgroupsmember=(contactgroupsmember *)calloc(1, sizeof(contactgroupsmember)))==NULL)
02386                 return NULL;
02387 
02388         /* duplicate vars */
02389         if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
02390                 result=ERROR;
02391 
02392         /* handle errors */
02393         if(result==ERROR){
02394                 my_free(new_contactgroupsmember->group_name);
02395                 my_free(new_contactgroupsmember);
02396                 return NULL;
02397                 }
02398 
02399         /* add this contactgroup to the host escalation */
02400         new_contactgroupsmember->next=he->contact_groups;
02401         he->contact_groups=new_contactgroupsmember;
02402 
02403         return new_contactgroupsmember;
02404         }
02405 
02406 
02407 
02408 /* adds a contact to a host escalation */
02409 contactsmember *add_contact_to_hostescalation(hostescalation *he, char *contact_name){
02410 
02411         return add_contact_to_object(&he->contacts,contact_name);
02412         }
02413 
02414 
02415 
02416 /* adds a contact to an object */
02417 contactsmember *add_contact_to_object(contactsmember **object_ptr, char *contactname){
02418         contactsmember *new_contactsmember=NULL;
02419 
02420         /* make sure we have the data we need */
02421         if(object_ptr==NULL){
02422                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact object is NULL\n");
02423                 return NULL;
02424                 }
02425 
02426         if(contactname==NULL || !strcmp(contactname,"")){
02427                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact name is NULL\n");
02428                 return NULL;
02429                 }
02430 
02431         /* allocate memory for a new member */
02432         if((new_contactsmember=malloc(sizeof(contactsmember)))==NULL){
02433                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for contact\n");
02434                 return NULL;
02435                 }
02436         if((new_contactsmember->contact_name=(char *)strdup(contactname))==NULL){
02437                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for contact name\n");
02438                 my_free(new_contactsmember);
02439                 return NULL;
02440                 }
02441 
02442         /* set initial values */
02443 #ifdef NSCORE
02444         new_contactsmember->contact_ptr=NULL;
02445 #endif
02446 
02447         /* add the new contact to the head of the contact list */
02448         new_contactsmember->next=*object_ptr;
02449         *object_ptr=new_contactsmember;
02450 
02451         return new_contactsmember;
02452         }
02453 
02454 
02455 
02456 /* adds a custom variable to an object */
02457 customvariablesmember *add_custom_variable_to_object(customvariablesmember **object_ptr, char *varname, char *varvalue){
02458         customvariablesmember *new_customvariablesmember=NULL;
02459 
02460         /* make sure we have the data we need */
02461         if(object_ptr==NULL){
02462                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Custom variable object is NULL\n");
02463                 return NULL;
02464                 }
02465 
02466         if(varname==NULL || !strcmp(varname,"")){
02467                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Custom variable name is NULL\n");
02468                 return NULL;
02469                 }
02470 
02471         /* allocate memory for a new member */
02472         if((new_customvariablesmember=malloc(sizeof(customvariablesmember)))==NULL){
02473                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable\n");
02474                 return NULL;
02475                 }
02476         if((new_customvariablesmember->variable_name=(char *)strdup(varname))==NULL){
02477                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable name\n");
02478                 my_free(new_customvariablesmember);
02479                 return NULL;
02480                 }
02481         if(varvalue){
02482                 if((new_customvariablesmember->variable_value=(char *)strdup(varvalue))==NULL){
02483                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable value\n");
02484                         my_free(new_customvariablesmember->variable_name);
02485                         my_free(new_customvariablesmember);
02486                         return NULL;
02487                         }
02488                 }
02489         else
02490                 new_customvariablesmember->variable_value=NULL;
02491 
02492         /* set initial values */
02493         new_customvariablesmember->has_been_modified=FALSE;
02494 
02495         /* add the new member to the head of the member list */
02496         new_customvariablesmember->next=*object_ptr;
02497         *object_ptr=new_customvariablesmember;
02498 
02499         return new_customvariablesmember;
02500         }
02501 
02502 
02503 /* add a new module to the list in memory */
02504 module *add_module(char *name,char *type,char *path,char *args){
02505         module *new_module=NULL;
02506         int result=OK;
02507                 
02508         /* make sure we have the data we need */
02509         if((name==NULL || !strcmp(name,"")) || (path==NULL || !strcmp(path,""))){
02510                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Module name or path is NULL\n");
02511                 return NULL;
02512                 }
02513 
02514         /* allocate memory for the new module */
02515         if((new_module=(module *)calloc(1, sizeof(module)))==NULL)
02516                 return NULL;
02517 
02518         /* duplicate vars */
02519         if((new_module->name=(char *)strdup(name))==NULL)
02520                 result=ERROR;
02521         if((new_module->type=(char *)strdup(type))==NULL)
02522                 result=ERROR;
02523         if((new_module->path=(char *)strdup(path))==NULL)
02524                 result=ERROR;
02525         if((new_module->args=(char *)strdup(args))==NULL)
02526                 result=ERROR;
02527 
02528         /* add new command to skiplist */
02529         if(result==OK){
02530                 result=skiplist_insert(object_skiplists[MODULE_SKIPLIST],(void *)new_module);
02531                 switch(result){
02532                 case SKIPLIST_ERROR_DUPLICATE:
02533                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Module '%s' has already been defined\n",name);
02534                         result=ERROR;
02535                         break;
02536                 case SKIPLIST_OK:
02537                         result=OK;
02538                         break;
02539                 default:
02540                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add module '%s' to skiplist\n",name);
02541                         result=ERROR;
02542                         break;
02543                         }
02544                 }
02545 
02546         /* handle errors */
02547         if(result==ERROR){
02548                 my_free(new_module->args);
02549                 my_free(new_module->path);
02550                 my_free(new_module->type);
02551                 my_free(new_module->name);
02552                 my_free(new_module);
02553                 return NULL;
02554                 }
02555 
02556         /* modules are sorted alphabetically, so add new items to tail of list */
02557         if(module_list==NULL){
02558                 module_list=new_module;
02559                 module_list_tail=module_list;
02560                 }
02561         else {
02562                 module_list_tail->next=new_module;
02563                 module_list_tail=new_module;
02564                 }
02565 
02566         return new_module;
02567         }
02568 
02569 #ifdef NSCORE
02570 int add_module_objects_to_neb(void){
02571         module *temp_module;
02572         int total_objects=0;
02573 
02574         for(temp_module=module_list,total_objects=0;temp_module!=NULL;temp_module=temp_module->next,total_objects++){
02575 
02576                 /* just an idea to re-use the type a bit better - MF 2011-04-30 FIXME */
02577                 //if!strcmp(temp_module->module_type,"neb"){
02578 #ifdef USE_EVENT_BROKER
02579                 neb_add_module(temp_module->path,temp_module->args,TRUE);
02580 #endif
02581                 //}
02582         }
02583 
02584         return OK;
02585 
02586 }
02587 #endif
02588 
02589 /******************************************************************/
02590 /******************** OBJECT SEARCH FUNCTIONS *********************/
02591 /******************************************************************/
02592 
02593 /* given a timeperiod name and a starting point, find a timeperiod from the list in memory */
02594 timeperiod * find_timeperiod(char *name){
02595         timeperiod temp_timeperiod;
02596 
02597         if(name==NULL)
02598                 return NULL;
02599 
02600         temp_timeperiod.name=name;
02601 
02602         return skiplist_find_first(object_skiplists[TIMEPERIOD_SKIPLIST],&temp_timeperiod,NULL);
02603         }
02604 
02605 
02606 /* given a host name, find it in the list in memory */
02607 host * find_host(char *name){
02608         host temp_host;
02609 
02610         if(name==NULL)
02611                 return NULL;
02612 
02613         temp_host.name=name;
02614 
02615         return skiplist_find_first(object_skiplists[HOST_SKIPLIST],&temp_host,NULL);
02616         }
02617 
02618 
02619 /* find a hostgroup from the list in memory */
02620 hostgroup * find_hostgroup(char *name){
02621         hostgroup temp_hostgroup;
02622 
02623         if(name==NULL)
02624                 return NULL;
02625 
02626         temp_hostgroup.group_name=name;
02627 
02628         return skiplist_find_first(object_skiplists[HOSTGROUP_SKIPLIST],&temp_hostgroup,NULL);
02629         }
02630 
02631 
02632 /* find a servicegroup from the list in memory */
02633 servicegroup * find_servicegroup(char *name){
02634         servicegroup temp_servicegroup;
02635 
02636         if(name==NULL)
02637                 return NULL;
02638 
02639         temp_servicegroup.group_name=name;
02640 
02641         return skiplist_find_first(object_skiplists[SERVICEGROUP_SKIPLIST],&temp_servicegroup,NULL);
02642         }
02643 
02644 
02645 /* find a contact from the list in memory */
02646 contact * find_contact(char *name){
02647         contact temp_contact;
02648 
02649         if(name==NULL)
02650                 return NULL;
02651 
02652         temp_contact.name=name;
02653 
02654         return skiplist_find_first(object_skiplists[CONTACT_SKIPLIST],&temp_contact,NULL);
02655         }
02656 
02657 
02658 /* find a contact group from the list in memory */
02659 contactgroup * find_contactgroup(char *name){
02660         contactgroup temp_contactgroup;
02661 
02662         if(name==NULL)
02663                 return NULL;
02664 
02665         temp_contactgroup.group_name=name;
02666 
02667         return skiplist_find_first(object_skiplists[CONTACTGROUP_SKIPLIST],&temp_contactgroup,NULL);
02668         }
02669 
02670 
02671 /* given a command name, find a command from the list in memory */
02672 command * find_command(char *name){
02673         command temp_command;
02674 
02675         if(name==NULL)
02676                 return NULL;
02677 
02678         temp_command.name=name;
02679 
02680         return skiplist_find_first(object_skiplists[COMMAND_SKIPLIST],&temp_command,NULL);
02681         }
02682 
02683 
02684 /* given a host/service name, find the service in the list in memory */
02685 service * find_service(char *host_name,char *svc_desc){
02686         service temp_service;
02687 
02688         if(host_name==NULL || svc_desc==NULL)
02689                 return NULL;
02690 
02691         temp_service.host_name=host_name;
02692         temp_service.description=svc_desc;
02693 
02694         return skiplist_find_first(object_skiplists[SERVICE_SKIPLIST],&temp_service,NULL);
02695         }
02696 
02697 
02698 /* given a module name, find a module from the list in memory */
02699 module * find_module(char *name){
02700         module temp_module;
02701 
02702         if(name==NULL)
02703                 return NULL;
02704 
02705         temp_module.name=name;
02706 
02707         return skiplist_find_first(object_skiplists[MODULE_SKIPLIST],&temp_module,NULL);
02708         }
02709 
02710 
02711 
02712 /******************************************************************/
02713 /******************* OBJECT TRAVERSAL FUNCTIONS *******************/
02714 /******************************************************************/
02715 
02716 hostescalation *get_first_hostescalation_by_host(char *host_name, void **ptr){
02717         hostescalation temp_hostescalation;
02718 
02719         if(host_name==NULL)
02720                 return NULL;
02721 
02722         temp_hostescalation.host_name=host_name;
02723 
02724         return skiplist_find_first(object_skiplists[HOSTESCALATION_SKIPLIST],&temp_hostescalation,ptr);
02725         }
02726 
02727 
02728 hostescalation *get_next_hostescalation_by_host(char *host_name, void **ptr){
02729         hostescalation temp_hostescalation;
02730 
02731         if(host_name==NULL)
02732                 return NULL;
02733 
02734         temp_hostescalation.host_name=host_name;
02735 
02736         return skiplist_find_next(object_skiplists[HOSTESCALATION_SKIPLIST],&temp_hostescalation,ptr);
02737         }
02738 
02739 
02740 serviceescalation *get_first_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr){
02741         serviceescalation temp_serviceescalation;
02742 
02743         if(host_name==NULL || svc_description==NULL)
02744                 return NULL;
02745 
02746         temp_serviceescalation.host_name=host_name;
02747         temp_serviceescalation.description=svc_description;
02748 
02749         return skiplist_find_first(object_skiplists[SERVICEESCALATION_SKIPLIST],&temp_serviceescalation,ptr);
02750         }
02751 
02752 
02753 serviceescalation *get_next_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr){
02754         serviceescalation temp_serviceescalation;
02755 
02756         if(host_name==NULL || svc_description==NULL)
02757                 return NULL;
02758 
02759         temp_serviceescalation.host_name=host_name;
02760         temp_serviceescalation.description=svc_description;
02761 
02762         return skiplist_find_next(object_skiplists[SERVICEESCALATION_SKIPLIST],&temp_serviceescalation,ptr);
02763         }
02764 
02765 
02766 hostdependency *get_first_hostdependency_by_dependent_host(char *host_name, void **ptr){
02767         hostdependency temp_hostdependency;
02768 
02769         if(host_name==NULL)
02770                 return NULL;
02771 
02772         temp_hostdependency.dependent_host_name=host_name;
02773 
02774         return skiplist_find_first(object_skiplists[HOSTDEPENDENCY_SKIPLIST],&temp_hostdependency,ptr);
02775         }
02776 
02777 
02778 hostdependency *get_next_hostdependency_by_dependent_host(char *host_name, void **ptr){
02779         hostdependency temp_hostdependency;
02780 
02781         if(host_name==NULL || ptr==NULL)
02782                 return NULL;
02783 
02784         temp_hostdependency.dependent_host_name=host_name;
02785 
02786         return skiplist_find_next(object_skiplists[HOSTDEPENDENCY_SKIPLIST],&temp_hostdependency,ptr);
02787         }
02788 
02789 
02790 servicedependency *get_first_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr){
02791         servicedependency temp_servicedependency;
02792 
02793         if(host_name==NULL || svc_description==NULL)
02794                 return NULL;
02795 
02796         temp_servicedependency.dependent_host_name=host_name;
02797         temp_servicedependency.dependent_service_description=svc_description;
02798 
02799         return skiplist_find_first(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],&temp_servicedependency,ptr);
02800         }
02801 
02802 
02803 servicedependency *get_next_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr){
02804         servicedependency temp_servicedependency;
02805 
02806         if(host_name==NULL || svc_description==NULL || ptr==NULL)
02807                 return NULL;
02808 
02809         temp_servicedependency.dependent_host_name=host_name;
02810         temp_servicedependency.dependent_service_description=svc_description;
02811 
02812         return skiplist_find_next(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],&temp_servicedependency,ptr);
02813 
02814         return NULL;
02815         }
02816 
02817 
02818 #ifdef NSCORE
02819 /* adds a object to a list of objects */
02820 int add_object_to_objectlist(objectlist **list, void *object_ptr){
02821         objectlist *temp_item=NULL;
02822         objectlist *new_item=NULL;
02823 
02824         if(list==NULL || object_ptr==NULL)
02825                 return ERROR;
02826 
02827         /* skip this object if its already in the list */
02828         for(temp_item=*list;temp_item;temp_item=temp_item->next){
02829                 if(temp_item->object_ptr==object_ptr)
02830                         break;
02831                 }
02832         if(temp_item)
02833                 return OK;
02834 
02835         /* allocate memory for a new list item */
02836         if((new_item=(objectlist *)malloc(sizeof(objectlist)))==NULL)
02837                 return ERROR;
02838 
02839         /* initialize vars */
02840         new_item->object_ptr=object_ptr;
02841 
02842         /* add new item to head of list */
02843         new_item->next=*list;
02844         *list=new_item;
02845 
02846         return OK;
02847         }
02848 
02849 
02850 
02851 /* frees memory allocated to a temporary object list */
02852 int free_objectlist(objectlist **temp_list){
02853         objectlist *this_objectlist=NULL;
02854         objectlist *next_objectlist=NULL;
02855 
02856         if(temp_list==NULL)
02857                 return ERROR;
02858 
02859         /* free memory allocated to object list */
02860         for(this_objectlist=*temp_list;this_objectlist!=NULL;this_objectlist=next_objectlist){
02861                 next_objectlist=this_objectlist->next;
02862                 my_free(this_objectlist);
02863                 }
02864 
02865         *temp_list=NULL;
02866 
02867         return OK;
02868         }
02869 #endif
02870 
02871 
02872 
02873 /******************************************************************/
02874 /********************* OBJECT QUERY FUNCTIONS *********************/
02875 /******************************************************************/
02876 
02877 /* determines whether or not a specific host is an immediate child of another host */
02878 int is_host_immediate_child_of_host(host *parent_host,host *child_host){
02879         hostsmember *temp_hostsmember=NULL;
02880 
02881         /* not enough data */
02882         if(child_host==NULL)
02883                 return FALSE;
02884 
02885         /* root/top-level hosts */
02886         if(parent_host==NULL){
02887                 if(child_host->parent_hosts==NULL)
02888                         return TRUE;
02889                 }
02890 
02891         /* mid-level/bottom hosts */
02892         else{
02893 
02894                 for(temp_hostsmember=child_host->parent_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
02895 #ifdef NSCORE
02896                         if(temp_hostsmember->host_ptr==parent_host)
02897                                 return TRUE;
02898 #else
02899                         if(!strcmp(temp_hostsmember->host_name,parent_host->name))
02900                                 return TRUE;
02901 #endif
02902                         }
02903                 }
02904 
02905         return FALSE;
02906         }
02907 
02908 
02909 /* determines whether or not a specific host is an immediate parent of another host */
02910 int is_host_immediate_parent_of_host(host *child_host,host *parent_host){
02911 
02912         if(is_host_immediate_child_of_host(parent_host,child_host)==TRUE)
02913                 return TRUE;
02914 
02915         return FALSE;
02916         }
02917 
02918 
02919 /* returns a count of the immediate children for a given host */
02920 /* NOTE: This function is only used by the CGIS */
02921 int number_of_immediate_child_hosts(host *hst){
02922         int children=0;
02923         host *temp_host=NULL;
02924 
02925         for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02926                 if(is_host_immediate_child_of_host(hst,temp_host)==TRUE)
02927                         children++;
02928                 }
02929 
02930         return children;
02931         }
02932 
02933 
02934 /* returns a count of the total children for a given host */
02935 /* NOTE: This function is only used by the CGIS */
02936 int number_of_total_child_hosts(host *hst){
02937         int children=0;
02938         host *temp_host=NULL;
02939 
02940         for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02941                 if(is_host_immediate_child_of_host(hst,temp_host)==TRUE)
02942                         children+=number_of_total_child_hosts(temp_host)+1;
02943                 }
02944 
02945         return children;
02946         }
02947 
02948 
02949 /* get the number of immediate parent hosts for a given host */
02950 /* NOTE: This function is only used by the CGIS */
02951 int number_of_immediate_parent_hosts(host *hst){
02952         int parents=0;
02953         host *temp_host=NULL;
02954 
02955         for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02956                 if(is_host_immediate_parent_of_host(hst,temp_host)==TRUE){
02957                         parents++;
02958                         }
02959                 }
02960 
02961         return parents;
02962         }
02963 
02964 
02965 /* get the total number of parent hosts for a given host */
02966 /* NOTE: This function is only used by the CGIS */
02967 int number_of_total_parent_hosts(host *hst){
02968         int parents=0;
02969         host *temp_host=NULL;
02970 
02971         for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02972                 if(is_host_immediate_parent_of_host(hst,temp_host)==TRUE){
02973                         parents+=number_of_total_parent_hosts(temp_host)+1;
02974                         }
02975                 }
02976 
02977         return parents;
02978         }
02979 
02980 
02981 /*  tests whether a host is a member of a particular hostgroup */
02982 /* NOTE: This function is only used by the CGIS */
02983 int is_host_member_of_hostgroup(hostgroup *group, host *hst){
02984         hostsmember *temp_hostsmember=NULL;
02985 
02986         if(group==NULL || hst==NULL)
02987                 return FALSE;
02988 
02989         for(temp_hostsmember=group->members;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
02990 #ifdef NSCORE
02991                 if(temp_hostsmember->host_ptr==hst)
02992                         return TRUE;
02993 #else
02994                 if(!strcmp(temp_hostsmember->host_name,hst->name))
02995                         return TRUE;
02996 #endif
02997                 }
02998 
02999         return FALSE;
03000         }
03001 
03002 
03003 /*  tests whether a host is a member of a particular servicegroup */
03004 /* NOTE: This function is only used by the CGIS */
03005 int is_host_member_of_servicegroup(servicegroup *group, host *hst){
03006         servicesmember *temp_servicesmember=NULL;
03007 
03008         if(group==NULL || hst==NULL)
03009                 return FALSE;
03010 
03011         for(temp_servicesmember=group->members;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
03012 #ifdef NSCORE
03013                 if(temp_servicesmember->service_ptr!=NULL && temp_servicesmember->service_ptr->host_ptr==hst)
03014                         return TRUE;
03015 #else
03016                 if(!strcmp(temp_servicesmember->host_name,hst->name))
03017                         return TRUE;
03018 #endif
03019                 }
03020 
03021         return FALSE;
03022         }
03023 
03024 
03025 /*  tests whether a service is a member of a particular servicegroup */
03026 /* NOTE: This function is only used by the CGIS */
03027 int is_service_member_of_servicegroup(servicegroup *group, service *svc){
03028         servicesmember *temp_servicesmember=NULL;
03029 
03030         if(group==NULL || svc==NULL)
03031                 return FALSE;
03032 
03033         for(temp_servicesmember=group->members;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
03034 #ifdef NSCORE
03035                 if(temp_servicesmember->service_ptr==svc)
03036                         return TRUE;
03037 #else
03038                 if(!strcmp(temp_servicesmember->host_name,svc->host_name) && !strcmp(temp_servicesmember->service_description,svc->description))
03039                         return TRUE;
03040 #endif
03041                 }
03042 
03043         return FALSE;
03044         }
03045 
03046 /* 06/14/10 MF all 3 functions mandatory for mk_livestatus */
03047 /*  tests whether a contact is a member of a particular contactgroup - used only by the CGIs */
03048 int is_contact_member_of_contactgroup(contactgroup *group, contact *cntct){
03049         contactsmember *member;
03050         contact *temp_contact=NULL;
03051 
03052         if (!group || !cntct)
03053                 return FALSE;
03054 
03055         /* search all contacts in this contact group */
03056         for (member = group->members; member; member = member->next) {
03057 #ifdef NSCORE
03058                 temp_contact=member->contact_ptr;
03059 #else
03060                 temp_contact=find_contact(member->contact_name);
03061 #endif
03062                 if(temp_contact==NULL)
03063                         continue;
03064                 if (temp_contact == cntct)
03065                         return TRUE;
03066         }
03067 
03068         return FALSE;
03069 }
03070 
03071 
03072 /*  tests whether a contact is a contact for a particular host */
03073 int is_contact_for_host(host *hst, contact *cntct){
03074         contactsmember *temp_contactsmember=NULL;
03075         contact *temp_contact=NULL;
03076         contactgroupsmember *temp_contactgroupsmember=NULL;
03077         contactgroup *temp_contactgroup=NULL;
03078 
03079         if(hst==NULL || cntct==NULL){
03080                 return FALSE;
03081                 }
03082 
03083         /* search all individual contacts of this host */
03084         for(temp_contactsmember=hst->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
03085 #ifdef NSCORE
03086                 temp_contact=temp_contactsmember->contact_ptr;
03087 #else
03088                 temp_contact=find_contact(temp_contactsmember->contact_name);
03089 #endif
03090                 if(temp_contact==NULL)
03091                         continue;
03092                 if(temp_contact==cntct)
03093                         return TRUE;
03094                 }
03095 
03096         /* search all contactgroups of this host */
03097         for(temp_contactgroupsmember=hst->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
03098 #ifdef NSCORE
03099                 temp_contactgroup=temp_contactgroupsmember->group_ptr;
03100 #else
03101                 temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
03102 #endif
03103                 if(temp_contactgroup==NULL)
03104                         continue;
03105 
03106                 if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
03107                         return TRUE;
03108                 }
03109 
03110         return FALSE;
03111         }
03112 
03113 
03114 
03115 /* tests whether or not a contact is an escalated contact for a particular host */
03116 int is_escalated_contact_for_host(host *hst, contact *cntct){
03117         contactsmember *temp_contactsmember=NULL;
03118         contact *temp_contact=NULL;
03119         hostescalation *temp_hostescalation=NULL;
03120         contactgroupsmember *temp_contactgroupsmember=NULL;
03121         contactgroup *temp_contactgroup=NULL;
03122         void *ptr=NULL;
03123 
03124 
03125         /* search all host escalations */
03126         for(temp_hostescalation=get_first_hostescalation_by_host(hst->name,&ptr);temp_hostescalation!=NULL;temp_hostescalation=get_next_hostescalation_by_host(hst->name,&ptr)){
03127 
03128                 /* search all contacts of this host escalation */
03129                 for(temp_contactsmember=temp_hostescalation->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
03130 #ifdef NSCORE
03131                         temp_contact=temp_contactsmember->contact_ptr;
03132 #else
03133                         temp_contact=find_contact(temp_contactsmember->contact_name);
03134 #endif
03135                         if(temp_contact==NULL)
03136                                 continue;
03137                         if(temp_contact==cntct)
03138                                 return TRUE;
03139                         }
03140                 
03141                 /* search all contactgroups of this host escalation */
03142                 for(temp_contactgroupsmember=temp_hostescalation->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
03143 #ifdef NSCORE
03144                         temp_contactgroup=temp_contactgroupsmember->group_ptr;
03145 #else
03146                         temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
03147 #endif
03148                         if(temp_contactgroup==NULL)
03149                                 continue;
03150 
03151                         if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
03152                                 return TRUE;
03153 
03154                         }
03155                 }
03156 
03157         return FALSE;
03158         }
03159 
03160 
03161 /*  tests whether a contact is a contact for a particular service */
03162 int is_contact_for_service(service *svc, contact *cntct){
03163         contactsmember *temp_contactsmember=NULL;
03164         contact *temp_contact=NULL;
03165         contactgroupsmember *temp_contactgroupsmember=NULL;
03166         contactgroup *temp_contactgroup=NULL;
03167 
03168         if(svc==NULL || cntct==NULL)
03169                 return FALSE;
03170 
03171         /* search all individual contacts of this service */
03172         for(temp_contactsmember=svc->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
03173 #ifdef NSCORE
03174                 temp_contact=temp_contactsmember->contact_ptr;
03175 #else
03176                 temp_contact=find_contact(temp_contactsmember->contact_name);
03177 #endif
03178                 
03179                 if(temp_contact==cntct)
03180                         return TRUE;
03181                 }
03182 
03183         /* search all contactgroups of this service */
03184         for(temp_contactgroupsmember=svc->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
03185 #ifdef NSCORE
03186                 temp_contactgroup=temp_contactgroupsmember->group_ptr;
03187 #else
03188                 temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
03189 #endif
03190                 if(temp_contactgroup==NULL)
03191                         continue;
03192 
03193                 if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
03194                         return TRUE;
03195 
03196                 }
03197 
03198         return FALSE;
03199         }
03200 
03201 
03202 
03203 /* tests whether or not a contact is an escalated contact for a particular service */
03204 int is_escalated_contact_for_service(service *svc, contact *cntct){
03205         serviceescalation *temp_serviceescalation=NULL;
03206         contactsmember *temp_contactsmember=NULL;
03207         contact *temp_contact=NULL;
03208         contactgroupsmember *temp_contactgroupsmember=NULL;
03209         contactgroup *temp_contactgroup=NULL;
03210         void *ptr=NULL;
03211 
03212         /* search all the service escalations */
03213         for(temp_serviceescalation=get_first_serviceescalation_by_service(svc->host_name,svc->description,&ptr);temp_serviceescalation!=NULL;temp_serviceescalation=get_next_serviceescalation_by_service(svc->host_name,svc->description,&ptr)){
03214 
03215                 /* search all contacts of this service escalation */
03216                 for(temp_contactsmember=temp_serviceescalation->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
03217 #ifdef NSCORE
03218                         temp_contact=temp_contactsmember->contact_ptr;
03219 #else
03220                         temp_contact=find_contact(temp_contactsmember->contact_name);
03221 #endif
03222                         if(temp_contact==NULL)
03223                                 continue;
03224                         if(temp_contact==cntct)
03225                                 return TRUE;
03226                         }
03227                 
03228                 /* search all contactgroups of this service escalation */
03229                 for(temp_contactgroupsmember=temp_serviceescalation->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
03230 #ifdef NSCORE
03231                         temp_contactgroup=temp_contactgroupsmember->group_ptr;
03232 #else
03233                         temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
03234 #endif
03235                         if(temp_contactgroup==NULL)
03236                                 continue;
03237 
03238                         if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
03239                                 return TRUE;
03240 
03241                         }
03242                 }
03243 
03244         return FALSE;
03245         }
03246 
03247 
03248 #ifdef NSCORE
03249 
03250 /* checks to see if there exists a circular dependency for a service */
03251 int check_for_circular_servicedependency_path(servicedependency *root_dep, servicedependency *dep, int dependency_type){
03252         servicedependency *temp_sd=NULL;
03253 
03254         if(root_dep==NULL || dep==NULL)
03255                 return FALSE;
03256 
03257         /* this is not the proper dependency type */
03258         if(root_dep->dependency_type!=dependency_type || dep->dependency_type!=dependency_type)
03259                 return FALSE;
03260 
03261         /* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
03262         if(root_dep->contains_circular_path==TRUE)
03263                 return TRUE;
03264 
03265         /* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
03266         /* this should speed up detection for some loops */
03267         if(dep->circular_path_checked==TRUE)
03268                 return FALSE;
03269 
03270         /* set the check flag so we don't get into an infinite loop */
03271         dep->circular_path_checked=TRUE;
03272 
03273         /* is this service dependent on the root service? */
03274         if(dep!=root_dep){
03275                 if(root_dep->dependent_service_ptr==dep->master_service_ptr){
03276                         root_dep->contains_circular_path=TRUE;
03277                         dep->contains_circular_path=TRUE;
03278                         return TRUE;
03279                         }
03280                 }
03281 
03282         /* notification dependencies are ok at this point as long as they don't inherit */
03283         if(dependency_type==NOTIFICATION_DEPENDENCY && dep->inherits_parent==FALSE)
03284                 return FALSE;
03285 
03286         /* check all parent dependencies */
03287         for(temp_sd=servicedependency_list;temp_sd!=NULL;temp_sd=temp_sd->next){
03288 
03289                 /* only check parent dependencies */
03290                 if(dep->master_service_ptr!=temp_sd->dependent_service_ptr)
03291                         continue;
03292 
03293                 if(check_for_circular_servicedependency_path(root_dep,temp_sd,dependency_type)==TRUE)
03294                         return TRUE;
03295                 }
03296 
03297         return FALSE;
03298         }
03299 
03300 
03301 /* checks to see if there exists a circular dependency for a host */
03302 int check_for_circular_hostdependency_path(hostdependency *root_dep, hostdependency *dep, int dependency_type){
03303         hostdependency *temp_hd=NULL;
03304 
03305         if(root_dep==NULL || dep==NULL)
03306                 return FALSE;
03307 
03308         /* this is not the proper dependency type */
03309         if(root_dep->dependency_type!=dependency_type || dep->dependency_type!=dependency_type)
03310                 return FALSE;
03311 
03312         /* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
03313         if(root_dep->contains_circular_path==TRUE)
03314                 return TRUE;
03315 
03316         /* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
03317         /* this should speed up detection for some loops */
03318         if(dep->circular_path_checked==TRUE)
03319                 return FALSE;
03320 
03321         /* set the check flag so we don't get into an infinite loop */
03322         dep->circular_path_checked=TRUE;
03323 
03324         /* is this host dependent on the root host? */
03325         if(dep!=root_dep){
03326                 if(root_dep->dependent_host_ptr==dep->master_host_ptr){
03327                         root_dep->contains_circular_path=TRUE;
03328                         dep->contains_circular_path=TRUE;
03329                         return TRUE;
03330                         }
03331                 }
03332 
03333         /* notification dependencies are ok at this point as long as they don't inherit */
03334         if(dependency_type==NOTIFICATION_DEPENDENCY && dep->inherits_parent==FALSE)
03335                 return FALSE;
03336 
03337         /* check all parent dependencies */
03338         for(temp_hd=hostdependency_list;temp_hd!=NULL;temp_hd=temp_hd->next){
03339 
03340                 /* only check parent dependencies */
03341                 if(dep->master_host_ptr!=temp_hd->dependent_host_ptr)
03342                         continue;
03343 
03344                 if(check_for_circular_hostdependency_path(root_dep,temp_hd,dependency_type)==TRUE)
03345                         return TRUE;
03346                 }
03347 
03348         return FALSE;
03349         }
03350 
03351 #endif
03352 
03353 
03354 
03355 
03356 /******************************************************************/
03357 /******************* OBJECT DELETION FUNCTIONS ********************/
03358 /******************************************************************/
03359 
03360 
03361 /* free all allocated memory for objects */
03362 int free_object_data(void){
03363         timeperiod *this_timeperiod=NULL;
03364         timeperiod *next_timeperiod=NULL;
03365         daterange *this_daterange=NULL;
03366         daterange *next_daterange=NULL;
03367         timerange *this_timerange=NULL;
03368         timerange *next_timerange=NULL;
03369         timeperiodexclusion *this_timeperiodexclusion=NULL;
03370         timeperiodexclusion *next_timeperiodexclusion=NULL;
03371         host *this_host=NULL;
03372         host *next_host=NULL;
03373         hostsmember *this_hostsmember=NULL;
03374         hostsmember *next_hostsmember=NULL;
03375         hostgroup *this_hostgroup=NULL;
03376         hostgroup *next_hostgroup=NULL;
03377         servicegroup *this_servicegroup=NULL;
03378         servicegroup *next_servicegroup=NULL;
03379         servicesmember *this_servicesmember=NULL;
03380         servicesmember *next_servicesmember=NULL;
03381         contact *this_contact=NULL;
03382         contact *next_contact=NULL;
03383         contactgroup *this_contactgroup=NULL;
03384         contactgroup *next_contactgroup=NULL;
03385         contactsmember *this_contactsmember=NULL;
03386         contactsmember *next_contactsmember=NULL;
03387         contactgroupsmember *this_contactgroupsmember=NULL;
03388         contactgroupsmember *next_contactgroupsmember=NULL;
03389         customvariablesmember *this_customvariablesmember=NULL;
03390         customvariablesmember *next_customvariablesmember=NULL;
03391         service *this_service=NULL;
03392         service *next_service=NULL;
03393         command *this_command=NULL;
03394         command *next_command=NULL;
03395         commandsmember *this_commandsmember=NULL;
03396         commandsmember *next_commandsmember=NULL;
03397         serviceescalation *this_serviceescalation=NULL;
03398         serviceescalation *next_serviceescalation=NULL;
03399         servicedependency *this_servicedependency=NULL;
03400         servicedependency *next_servicedependency=NULL;
03401         hostdependency *this_hostdependency=NULL;
03402         hostdependency *next_hostdependency=NULL;
03403         hostescalation *this_hostescalation=NULL;
03404         hostescalation *next_hostescalation=NULL;
03405         escalation_condition *this_escalation_condition=NULL;
03406         escalation_condition *next_escalation_condition=NULL;
03407         module *this_module=NULL;
03408         module *next_module=NULL;
03409         register int x=0;
03410         register int i=0;
03411 
03412 
03413         /**** free memory for the timeperiod list ****/
03414         this_timeperiod=timeperiod_list;
03415         while(this_timeperiod!=NULL){
03416 
03417                 /* free the exception time ranges contained in this timeperiod */
03418                 for(x=0;x<DATERANGE_TYPES;x++){
03419 
03420                         for(this_daterange=this_timeperiod->exceptions[x];this_daterange!=NULL;this_daterange=next_daterange){
03421                                 next_daterange=this_daterange->next;
03422                                 for(this_timerange=this_daterange->times;this_timerange!=NULL;this_timerange=next_timerange){
03423                                         next_timerange=this_timerange->next;
03424                                         my_free(this_timerange);
03425                                         }
03426                                 my_free(this_daterange);
03427                                 }
03428                         }
03429 
03430                 /* free the day time ranges contained in this timeperiod */
03431                 for(x=0;x<7;x++){
03432 
03433                         for(this_timerange=this_timeperiod->days[x];this_timerange!=NULL;this_timerange=next_timerange){
03434                                 next_timerange=this_timerange->next;
03435                                 my_free(this_timerange);
03436                                 }
03437                         }
03438 
03439                 /* free exclusions */
03440                 for(this_timeperiodexclusion=this_timeperiod->exclusions;this_timeperiodexclusion!=NULL;this_timeperiodexclusion=next_timeperiodexclusion){
03441                         next_timeperiodexclusion=this_timeperiodexclusion->next;
03442                         my_free(this_timeperiodexclusion->timeperiod_name);
03443                         my_free(this_timeperiodexclusion);
03444                         }
03445 
03446                 next_timeperiod=this_timeperiod->next;
03447                 my_free(this_timeperiod->name);
03448                 my_free(this_timeperiod->alias);
03449                 my_free(this_timeperiod);
03450                 this_timeperiod=next_timeperiod;
03451                 }
03452 
03453         /* reset pointers */
03454         timeperiod_list=NULL;
03455 
03456 
03457         /**** free memory for the host list ****/
03458         this_host=host_list;
03459         while(this_host!=NULL){
03460 
03461                 next_host=this_host->next;
03462 
03463                 /* free memory for parent hosts */
03464                 this_hostsmember=this_host->parent_hosts;
03465                 while(this_hostsmember!=NULL){
03466                         next_hostsmember=this_hostsmember->next;
03467                         my_free(this_hostsmember->host_name);
03468                         my_free(this_hostsmember);
03469                         this_hostsmember=next_hostsmember;
03470                         }
03471 
03472                 /* free memory for child host links */
03473                 this_hostsmember=this_host->child_hosts;
03474                 while(this_hostsmember!=NULL){
03475                         next_hostsmember=this_hostsmember->next;
03476                         my_free(this_hostsmember->host_name);
03477                         my_free(this_hostsmember);
03478                         this_hostsmember=next_hostsmember;
03479                         }
03480 
03481                 /* free memory for service links */
03482                 this_servicesmember=this_host->services;
03483                 while(this_servicesmember!=NULL){
03484                         next_servicesmember=this_servicesmember->next;
03485                         my_free(this_servicesmember->host_name);
03486                         my_free(this_servicesmember->service_description);
03487                         my_free(this_servicesmember);
03488                         this_servicesmember=next_servicesmember;
03489                         }
03490 
03491                 /* free memory for contact groups */
03492                 this_contactgroupsmember=this_host->contact_groups;
03493                 while(this_contactgroupsmember!=NULL){
03494                         next_contactgroupsmember=this_contactgroupsmember->next;
03495                         my_free(this_contactgroupsmember->group_name);
03496                         my_free(this_contactgroupsmember);
03497                         this_contactgroupsmember=next_contactgroupsmember;
03498                         }
03499 
03500                 /* free memory for contacts */
03501                 this_contactsmember=this_host->contacts;
03502                 while(this_contactsmember!=NULL){
03503                         next_contactsmember=this_contactsmember->next;
03504                         my_free(this_contactsmember->contact_name);
03505                         my_free(this_contactsmember);
03506                         this_contactsmember=next_contactsmember;
03507                         }
03508 
03509                 /* free memory for custom variables */
03510                 this_customvariablesmember=this_host->custom_variables;
03511                 while(this_customvariablesmember!=NULL){
03512                         next_customvariablesmember=this_customvariablesmember->next;
03513                         my_free(this_customvariablesmember->variable_name);
03514                         my_free(this_customvariablesmember->variable_value);
03515                         my_free(this_customvariablesmember);
03516                         this_customvariablesmember=next_customvariablesmember;
03517                         }
03518 
03519                 my_free(this_host->name);
03520                 my_free(this_host->display_name);
03521                 my_free(this_host->alias);
03522                 my_free(this_host->address);
03523                 my_free(this_host->address6);
03524 #ifdef NSCORE
03525                 my_free(this_host->plugin_output);
03526                 my_free(this_host->long_plugin_output);
03527                 my_free(this_host->perf_data);
03528                 my_free(this_host->processed_command);
03529 
03530                 free_objectlist(&this_host->hostgroups_ptr);
03531 #endif
03532                 my_free(this_host->check_period);
03533                 my_free(this_host->host_check_command);
03534                 my_free(this_host->event_handler);
03535                 my_free(this_host->failure_prediction_options);
03536                 my_free(this_host->notification_period);
03537                 my_free(this_host->notes);
03538                 my_free(this_host->notes_url);
03539                 my_free(this_host->action_url);
03540                 my_free(this_host->icon_image);
03541                 my_free(this_host->icon_image_alt);
03542                 my_free(this_host->vrml_image);
03543                 my_free(this_host->statusmap_image);
03544                 my_free(this_host);
03545                 this_host=next_host;
03546                 }
03547 
03548         /* reset pointers */
03549         host_list=NULL;
03550 
03551 
03552         /**** free memory for the host group list ****/
03553         this_hostgroup=hostgroup_list;
03554         while(this_hostgroup!=NULL){
03555 
03556                 /* free memory for the group members */
03557                 this_hostsmember=this_hostgroup->members;
03558                 while(this_hostsmember!=NULL){
03559                         next_hostsmember=this_hostsmember->next;
03560                         my_free(this_hostsmember->host_name);
03561                         my_free(this_hostsmember);
03562                         this_hostsmember=next_hostsmember;
03563                         }
03564 
03565                 next_hostgroup=this_hostgroup->next;
03566                 my_free(this_hostgroup->group_name);
03567                 my_free(this_hostgroup->alias);
03568                 my_free(this_hostgroup->notes);
03569                 my_free(this_hostgroup->notes_url);
03570                 my_free(this_hostgroup->action_url);
03571                 my_free(this_hostgroup);
03572                 this_hostgroup=next_hostgroup;
03573                 }
03574 
03575         /* reset pointers */
03576         hostgroup_list=NULL;
03577 
03578 
03579         /**** free memory for the service group list ****/
03580         this_servicegroup=servicegroup_list;
03581         while(this_servicegroup!=NULL){
03582 
03583                 /* free memory for the group members */
03584                 this_servicesmember=this_servicegroup->members;
03585                 while(this_servicesmember!=NULL){
03586                         next_servicesmember=this_servicesmember->next;
03587                         my_free(this_servicesmember->host_name);
03588                         my_free(this_servicesmember->service_description);
03589                         my_free(this_servicesmember);
03590                         this_servicesmember=next_servicesmember;
03591                         }
03592 
03593                 next_servicegroup=this_servicegroup->next;
03594                 my_free(this_servicegroup->group_name);
03595                 my_free(this_servicegroup->alias);
03596                 my_free(this_servicegroup->notes);
03597                 my_free(this_servicegroup->notes_url);
03598                 my_free(this_servicegroup->action_url);
03599                 my_free(this_servicegroup);
03600                 this_servicegroup=next_servicegroup;
03601                 }
03602 
03603         /* reset pointers */
03604         servicegroup_list=NULL;
03605 
03606 
03607         /**** free memory for the contact list ****/
03608         this_contact=contact_list;
03609         while(this_contact!=NULL){
03610           
03611                 /* free memory for the host notification commands */
03612                 this_commandsmember=this_contact->host_notification_commands;
03613                 while(this_commandsmember!=NULL){
03614                         next_commandsmember=this_commandsmember->next;
03615                         if(this_commandsmember->command!=NULL)
03616                                 my_free(this_commandsmember->command);
03617                         my_free(this_commandsmember);
03618                         this_commandsmember=next_commandsmember;
03619                         }
03620 
03621                 /* free memory for the service notification commands */
03622                 this_commandsmember=this_contact->service_notification_commands;
03623                 while(this_commandsmember!=NULL){
03624                         next_commandsmember=this_commandsmember->next;
03625                         if(this_commandsmember->command!=NULL)
03626                                 my_free(this_commandsmember->command);
03627                         my_free(this_commandsmember);
03628                         this_commandsmember=next_commandsmember;
03629                         }
03630 
03631                 /* free memory for custom variables */
03632                 this_customvariablesmember=this_contact->custom_variables;
03633                 while(this_customvariablesmember!=NULL){
03634                         next_customvariablesmember=this_customvariablesmember->next;
03635                         my_free(this_customvariablesmember->variable_name);
03636                         my_free(this_customvariablesmember->variable_value);
03637                         my_free(this_customvariablesmember);
03638                         this_customvariablesmember=next_customvariablesmember;
03639                         }
03640 
03641                 next_contact=this_contact->next;
03642                 my_free(this_contact->name);
03643                 my_free(this_contact->alias);
03644                 my_free(this_contact->email);
03645                 my_free(this_contact->pager);
03646                 for(i=0;i<MAX_CONTACT_ADDRESSES;i++)
03647                         my_free(this_contact->address[i]);
03648                 my_free(this_contact->host_notification_period);
03649                 my_free(this_contact->service_notification_period);
03650 
03651 #ifdef NSCORE
03652                 free_objectlist(&this_contact->contactgroups_ptr);
03653 #endif
03654 
03655                 my_free(this_contact);
03656                 this_contact=next_contact;
03657                 }
03658 
03659         /* reset pointers */
03660         contact_list=NULL;
03661 
03662 
03663         /**** free memory for the contact group list ****/
03664         this_contactgroup=contactgroup_list;
03665         while(this_contactgroup!=NULL){
03666 
03667                 /* free memory for the group members */
03668                 this_contactsmember=this_contactgroup->members;
03669                 while(this_contactsmember!=NULL){
03670                         next_contactsmember=this_contactsmember->next;
03671                         my_free(this_contactsmember->contact_name);
03672                         my_free(this_contactsmember);
03673                         this_contactsmember=next_contactsmember;
03674                         }
03675 
03676                 next_contactgroup=this_contactgroup->next;
03677                 my_free(this_contactgroup->group_name);
03678                 my_free(this_contactgroup->alias);
03679                 my_free(this_contactgroup);
03680                 this_contactgroup=next_contactgroup;
03681                 }
03682 
03683         /* reset pointers */
03684         contactgroup_list=NULL;
03685 
03686 
03687         /**** free memory for the service list ****/
03688         this_service=service_list;
03689         while(this_service!=NULL){
03690 
03691                 next_service=this_service->next;
03692 
03693                 /* free memory for contact groups */
03694                 this_contactgroupsmember=this_service->contact_groups;
03695                 while(this_contactgroupsmember!=NULL){
03696                         next_contactgroupsmember=this_contactgroupsmember->next;
03697                         my_free(this_contactgroupsmember->group_name);
03698                         my_free(this_contactgroupsmember);
03699                         this_contactgroupsmember=next_contactgroupsmember;
03700                         }
03701 
03702                 /* free memory for contacts */
03703                 this_contactsmember=this_service->contacts;
03704                 while(this_contactsmember!=NULL){
03705                         next_contactsmember=this_contactsmember->next;
03706                         my_free(this_contactsmember->contact_name);
03707                         my_free(this_contactsmember);
03708                         this_contactsmember=next_contactsmember;
03709                         }
03710 
03711                 /* free memory for custom variables */
03712                 this_customvariablesmember=this_service->custom_variables;
03713                 while(this_customvariablesmember!=NULL){
03714                         next_customvariablesmember=this_customvariablesmember->next;
03715                         my_free(this_customvariablesmember->variable_name);
03716                         my_free(this_customvariablesmember->variable_value);
03717                         my_free(this_customvariablesmember);
03718                         this_customvariablesmember=next_customvariablesmember;
03719                         }
03720 
03721                 my_free(this_service->host_name);
03722                 my_free(this_service->description);
03723                 my_free(this_service->display_name);
03724                 my_free(this_service->service_check_command);
03725 #ifdef NSCORE
03726                 my_free(this_service->plugin_output);
03727                 my_free(this_service->long_plugin_output);
03728                 my_free(this_service->perf_data);
03729                 my_free(this_service->processed_command);
03730 
03731                 my_free(this_service->event_handler_args);
03732                 my_free(this_service->check_command_args);
03733 
03734                 free_objectlist(&this_service->servicegroups_ptr);
03735 #endif
03736                 my_free(this_service->notification_period);
03737                 my_free(this_service->check_period);
03738                 my_free(this_service->event_handler);
03739                 my_free(this_service->failure_prediction_options);
03740                 my_free(this_service->notes);
03741                 my_free(this_service->notes_url);
03742                 my_free(this_service->action_url);
03743                 my_free(this_service->icon_image);
03744                 my_free(this_service->icon_image_alt);
03745                 my_free(this_service);
03746                 this_service=next_service;
03747                 }
03748 
03749         /* reset pointers */
03750         service_list=NULL;
03751 
03752 
03753         /**** free memory for the command list ****/
03754         this_command=command_list;
03755         while(this_command!=NULL){
03756                 next_command=this_command->next;
03757                 my_free(this_command->name);
03758                 my_free(this_command->command_line);
03759                 my_free(this_command);
03760                 this_command=next_command;
03761                 }
03762 
03763         /* reset pointers */
03764         command_list=NULL;
03765 
03766 
03767         /**** free memory for the service escalation list ****/
03768         this_serviceescalation=serviceescalation_list;
03769         while(this_serviceescalation!=NULL){
03770 
03771                 /* free memory for the contact group members */
03772                 this_contactgroupsmember=this_serviceescalation->contact_groups;
03773                 while(this_contactgroupsmember!=NULL){
03774                         next_contactgroupsmember=this_contactgroupsmember->next;
03775                         my_free(this_contactgroupsmember->group_name);
03776                         my_free(this_contactgroupsmember);
03777                         this_contactgroupsmember=next_contactgroupsmember;
03778                         }
03779 
03780                 /* free memory for contacts */
03781                 this_contactsmember=this_serviceescalation->contacts;
03782                 while(this_contactsmember!=NULL){
03783                         next_contactsmember=this_contactsmember->next;
03784                         my_free(this_contactsmember->contact_name);
03785                         my_free(this_contactsmember);
03786                         this_contactsmember=next_contactsmember;
03787                         }
03788 
03789                 /* free memory for escalation_conditions */
03790                 this_escalation_condition=this_serviceescalation->condition;
03791                 while(this_escalation_condition!=NULL){
03792                         next_escalation_condition=this_escalation_condition->next;
03793                         my_free(this_escalation_condition->host_name);
03794                         my_free(this_escalation_condition->service_description);
03795                         my_free(this_escalation_condition);
03796                         this_escalation_condition=next_escalation_condition;
03797                         }
03798 
03799                 next_serviceescalation=this_serviceescalation->next;
03800                 my_free(this_serviceescalation->host_name);
03801                 my_free(this_serviceescalation->description);
03802                 my_free(this_serviceescalation->escalation_period);
03803                 my_free(this_serviceescalation);
03804                 this_serviceescalation=next_serviceescalation;
03805                 }
03806 
03807         /* reset pointers */
03808         serviceescalation_list=NULL;
03809 
03810 
03811         /**** free memory for the service dependency list ****/
03812         this_servicedependency=servicedependency_list;
03813         while(this_servicedependency!=NULL){
03814                 next_servicedependency=this_servicedependency->next;
03815                 my_free(this_servicedependency->dependency_period);
03816                 my_free(this_servicedependency->dependent_host_name);
03817                 my_free(this_servicedependency->dependent_service_description);
03818                 my_free(this_servicedependency->host_name);
03819                 my_free(this_servicedependency->service_description);
03820                 my_free(this_servicedependency);
03821                 this_servicedependency=next_servicedependency;
03822                 }
03823 
03824         /* reset pointers */
03825         servicedependency_list=NULL;
03826 
03827 
03828         /**** free memory for the host dependency list ****/
03829         this_hostdependency=hostdependency_list;
03830         while(this_hostdependency!=NULL){
03831                 next_hostdependency=this_hostdependency->next;
03832                 my_free(this_hostdependency->dependency_period);
03833                 my_free(this_hostdependency->dependent_host_name);
03834                 my_free(this_hostdependency->host_name);
03835                 my_free(this_hostdependency);
03836                 this_hostdependency=next_hostdependency;
03837                 }
03838 
03839         /* reset pointers */
03840         hostdependency_list=NULL;
03841 
03842 
03843         /**** free memory for the host escalation list ****/
03844         this_hostescalation=hostescalation_list;
03845         while(this_hostescalation!=NULL){
03846 
03847                 /* free memory for the contact group members */
03848                 this_contactgroupsmember=this_hostescalation->contact_groups;
03849                 while(this_contactgroupsmember!=NULL){
03850                         next_contactgroupsmember=this_contactgroupsmember->next;
03851                         my_free(this_contactgroupsmember->group_name);
03852                         my_free(this_contactgroupsmember);
03853                         this_contactgroupsmember=next_contactgroupsmember;
03854                         }
03855 
03856                 /* free memory for contacts */
03857                 this_contactsmember=this_hostescalation->contacts;
03858                 while(this_contactsmember!=NULL){
03859                         next_contactsmember=this_contactsmember->next;
03860                         my_free(this_contactsmember->contact_name);
03861                         my_free(this_contactsmember);
03862                         this_contactsmember=next_contactsmember;
03863                         }
03864 
03865                 /* free memory for escalation_conditions */
03866                 this_escalation_condition=this_hostescalation->condition;
03867                 while(this_escalation_condition!=NULL){
03868                         next_escalation_condition=this_escalation_condition->next;
03869                         my_free(this_escalation_condition->host_name);
03870                         my_free(this_escalation_condition->service_description);
03871                         my_free(this_escalation_condition);
03872                         this_escalation_condition=next_escalation_condition;
03873                         }
03874 
03875                 next_hostescalation=this_hostescalation->next;
03876                 my_free(this_hostescalation->host_name);
03877                 my_free(this_hostescalation->escalation_period);
03878                 my_free(this_hostescalation);
03879                 this_hostescalation=next_hostescalation;
03880                 }
03881 
03882         /* reset pointers */
03883         hostescalation_list=NULL;
03884 
03885         /**** free memory for the module list ****/
03886         this_module=module_list;
03887         while(this_module!=NULL){
03888                 next_module=this_module->next;
03889                 my_free(this_module->name);
03890                 my_free(this_module->type);
03891                 my_free(this_module->path);
03892                 my_free(this_module->args);
03893                 my_free(this_module);
03894                 this_module=next_module;
03895                 }
03896 
03897         /* reset pointers */
03898         module_list=NULL;
03899 
03900 
03901         /* free object skiplists */
03902         free_object_skiplists();
03903 
03904         return OK;
03905         }
03906 
 All Data Structures Files Functions Variables Typedefs Defines