Icinga-core 1.4.0
next gen monitoring
xdata/xodtemplate.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * XODTEMPLATE.C - Template-based object configuration data input routines
00004  *
00005  * Copyright (c) 1999-2009 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  * Description:
00010  *
00011  * Routines for parsing and resolving template-based object definitions.
00012  * Basic steps involved in this in the daemon are as follows:
00013  *
00014  *    1) Read
00015  *    2) Resolve
00016  *    3) Duplicate
00017  *    4) Recombobulate
00018  *    5) Cache
00019  *    7) Register
00020  *    8) Cleanup
00021  *
00022  * The steps involved for the CGIs differ a bit, since they read the cached
00023  * definitions which are already resolved, recombobulated and duplicated.  In
00024  * otherwords, they've already been "flattened"...
00025  *
00026  *    1) Read
00027  *    2) Register
00028  *    3) Cleanup
00029  *
00030  *
00031  * License:
00032  *
00033  * This program is free software; you can redistribute it and/or modify
00034  * it under the terms of the GNU General Public License version 2 as
00035  * published by the Free Software Foundation.
00036  *
00037  * This program is distributed in the hope that it will be useful,
00038  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00039  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00040  * GNU General Public License for more details.
00041  *
00042  * You should have received a copy of the GNU General Public License
00043  * along with this program; if not, write to the Free Software
00044  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00045  *
00046  *****************************************************************************/
00047 
00048 
00049 /*********** COMMON HEADER FILES ***********/
00050 
00051 #include "../include/config.h"
00052 #include "../include/common.h"
00053 #include "../include/objects.h"
00054 #include "../include/locations.h"
00055 #include "../include/macros.h"
00056 #include "../include/skiplist.h"
00057 
00058 /**** CORE OR CGI SPECIFIC HEADER FILES ****/
00059 
00060 #ifdef NSCORE
00061 #include "../include/icinga.h"
00062 #endif
00063 
00064 #ifdef NSCGI
00065 #include "../include/cgiutils.h"
00066 #endif
00067 
00068 /**** DATA INPUT-SPECIFIC HEADER FILES ****/
00069 
00070 #include "xodtemplate.h"
00071 
00072 
00073 #ifdef NSCORE
00074 extern int use_regexp_matches;
00075 extern int use_true_regexp_matching;
00076 extern int verify_config;
00077 extern int test_scheduling;
00078 extern int use_precached_objects;
00079 #endif
00080 
00081 xodtemplate_timeperiod *xodtemplate_timeperiod_list=NULL;
00082 xodtemplate_command *xodtemplate_command_list=NULL;
00083 xodtemplate_contactgroup *xodtemplate_contactgroup_list=NULL;
00084 xodtemplate_hostgroup *xodtemplate_hostgroup_list=NULL;
00085 xodtemplate_servicegroup *xodtemplate_servicegroup_list=NULL;
00086 xodtemplate_servicedependency *xodtemplate_servicedependency_list=NULL;
00087 xodtemplate_serviceescalation *xodtemplate_serviceescalation_list=NULL;
00088 xodtemplate_contact *xodtemplate_contact_list=NULL;
00089 xodtemplate_host *xodtemplate_host_list=NULL;
00090 xodtemplate_service *xodtemplate_service_list=NULL;
00091 xodtemplate_hostdependency *xodtemplate_hostdependency_list=NULL;
00092 xodtemplate_hostescalation *xodtemplate_hostescalation_list=NULL;
00093 xodtemplate_hostextinfo *xodtemplate_hostextinfo_list=NULL;
00094 xodtemplate_serviceextinfo *xodtemplate_serviceextinfo_list=NULL;
00095 xodtemplate_module *xodtemplate_module_list=NULL;
00096 
00097 xodtemplate_timeperiod *xodtemplate_timeperiod_list_tail=NULL;
00098 xodtemplate_command *xodtemplate_command_list_tail=NULL;
00099 xodtemplate_contactgroup *xodtemplate_contactgroup_list_tail=NULL;
00100 xodtemplate_hostgroup *xodtemplate_hostgroup_list_tail=NULL;
00101 xodtemplate_servicegroup *xodtemplate_servicegroup_list_tail=NULL;
00102 xodtemplate_servicedependency *xodtemplate_servicedependency_list_tail=NULL;
00103 xodtemplate_serviceescalation *xodtemplate_serviceescalation_list_tail=NULL;
00104 xodtemplate_contact *xodtemplate_contact_list_tail=NULL;
00105 xodtemplate_host *xodtemplate_host_list_tail=NULL;
00106 xodtemplate_service *xodtemplate_service_list_tail=NULL;
00107 xodtemplate_hostdependency *xodtemplate_hostdependency_list_tail=NULL;
00108 xodtemplate_hostescalation *xodtemplate_hostescalation_list_tail=NULL;
00109 xodtemplate_hostextinfo *xodtemplate_hostextinfo_list_tail=NULL;
00110 xodtemplate_serviceextinfo *xodtemplate_serviceextinfo_list_tail=NULL;
00111 xodtemplate_module *xodtemplate_module_list_tail=NULL;
00112 
00113 
00114 skiplist *xobject_template_skiplists[NUM_XOBJECT_SKIPLISTS];
00115 skiplist *xobject_skiplists[NUM_XOBJECT_SKIPLISTS];
00116 
00117 
00118 void *xodtemplate_current_object=NULL;
00119 int xodtemplate_current_object_type=XODTEMPLATE_NONE;
00120 
00121 int xodtemplate_current_config_file=0;
00122 char **xodtemplate_config_files=NULL;
00123 
00124 char *xodtemplate_cache_file=NULL;
00125 char *xodtemplate_precache_file=NULL;
00126 
00127 int presorted_objects=FALSE;
00128 
00129 extern int allow_empty_hostgroup_assignment;
00130 
00131 int xodtemplate_create_escalation_condition(char*, xodtemplate_escalation_condition*);
00132 
00133 /*
00134  * Macro magic used to determine if a service is assigned
00135  * via hostgroup_name or host_name. Those assigned via host_name
00136  * take precedence.
00137  */
00138 #define X_SERVICE_IS_FROM_HOSTGROUP      (1 << 1)  /* flag to know if service come from a hostgroup def, apply on srv->have_initial_state */
00139 #define xodtemplate_set_service_is_from_hostgroup(srv) \
00140         srv->have_initial_state |= X_SERVICE_IS_FROM_HOSTGROUP
00141 #define xodtemplate_unset_service_is_from_hostgroup(srv) \
00142         srv->have_initial_state &= ~X_SERVICE_IS_FROM_HOSTGROUP
00143 #define xodtemplate_is_service_is_from_hostgroup(srv) \
00144         ((srv->have_initial_state & X_SERVICE_IS_FROM_HOSTGROUP) != 0)
00145 
00146 /* returns the name of a numbered config file */
00147 static char *xodtemplate_config_file_name(int config_file){
00148         if(config_file<=xodtemplate_current_config_file)
00149                 return xodtemplate_config_files[config_file-1];
00150 
00151         return "?";
00152 }
00153 
00154 
00155 /******************************************************************/
00156 /************* TOP-LEVEL CONFIG DATA INPUT FUNCTION ***************/
00157 /******************************************************************/
00158 
00159 /* process all config files - both core and CGIs pass in name of main config file */
00160 int xodtemplate_read_config_data(char *main_config_file, int options, int cache, int precache){
00161 #ifdef NSCORE
00162         char *config_file=NULL;
00163         char *config_base_dir=NULL;
00164         char *input=NULL;
00165         char *var=NULL;
00166         char *val=NULL;
00167         char *temp_buffer=NULL;
00168         struct timeval tv[14];
00169         double runtime[14];
00170         mmapfile *thefile=NULL;
00171         int dummy; /* reduce compiler warnings */
00172 #endif
00173         int result=OK;
00174 
00175 
00176         if(main_config_file==NULL){
00177 #ifdef NSCORE
00178                 printf("Error: No main config file passed to object routines!\n");
00179 #endif
00180                 return ERROR;
00181                 }
00182 
00183         /* get variables from main config file */
00184         xodtemplate_grab_config_info(main_config_file);
00185 
00186         /* initialize variables */
00187         xodtemplate_timeperiod_list=NULL;
00188         xodtemplate_command_list=NULL;
00189         xodtemplate_contactgroup_list=NULL;
00190         xodtemplate_hostgroup_list=NULL;
00191         xodtemplate_servicegroup_list=NULL;
00192         xodtemplate_servicedependency_list=NULL;
00193         xodtemplate_serviceescalation_list=NULL;
00194         xodtemplate_contact_list=NULL;
00195         xodtemplate_host_list=NULL;
00196         xodtemplate_service_list=NULL;
00197         xodtemplate_hostdependency_list=NULL;
00198         xodtemplate_hostescalation_list=NULL;
00199         xodtemplate_hostextinfo_list=NULL;
00200         xodtemplate_serviceextinfo_list=NULL;
00201         xodtemplate_module_list=NULL;
00202 
00203         /* initialize skiplists */
00204         xodtemplate_init_xobject_skiplists();
00205 
00206         xodtemplate_current_object=NULL;
00207         xodtemplate_current_object_type=XODTEMPLATE_NONE;
00208 
00209         /* allocate memory for 256 config files (increased dynamically) */
00210         xodtemplate_current_config_file=0;
00211         xodtemplate_config_files=(char **)malloc(256*sizeof(char **));
00212         if(xodtemplate_config_files==NULL){
00213 #ifdef NSCORE
00214                 printf("Unable to allocate memory!\n");
00215 #endif
00216                 return ERROR;
00217                 }
00218 
00219         /* are the objects we're reading already pre-sorted? */
00220         presorted_objects=FALSE;
00221 #ifdef NSCORE
00222         presorted_objects=(use_precached_objects==TRUE)?TRUE:FALSE;
00223 #endif
00224 
00225 #ifdef NSCORE
00226         if(test_scheduling==TRUE)
00227                 gettimeofday(&tv[0],NULL);
00228 
00229         /* only process the precached object file as long as we're not regenerating it and we're not verifying the config */
00230         if(use_precached_objects==TRUE)
00231                 result=xodtemplate_process_config_file(xodtemplate_precache_file,options);
00232 
00233         /* process object config files normally... */
00234         else{
00235 
00236                 /* determine the directory of the main config file */
00237                 if((config_file=(char *)strdup(main_config_file))==NULL){
00238                         my_free(xodtemplate_config_files);
00239 #ifdef NSCORE
00240                         printf("Unable to allocate memory!\n");
00241 #endif
00242                         return ERROR;
00243                         }
00244                 config_base_dir=(char *)strdup(dirname(config_file));
00245                 my_free(config_file);
00246 
00247                 /* open the main config file for reading (we need to find all the config files to read) */
00248                 if((thefile=mmap_fopen(main_config_file))==NULL){
00249                         my_free(config_base_dir);
00250                         my_free(xodtemplate_config_files);
00251 #ifdef NSCORE
00252                         printf("Unable to open main config file '%s'\n",main_config_file);
00253 #endif
00254                         return ERROR;
00255                         }
00256 
00257                 /* daemon reads all config files/dirs specified in the main config file */
00258                 /* read in all lines from the main config file */
00259                 while(1){
00260 
00261                         /* free memory */
00262                         my_free(input);
00263 
00264                         /* get the next line */
00265                         if((input=mmap_fgets_multiline(thefile))==NULL)
00266                                 break;
00267 
00268                         /* strip input */
00269                         strip(input);
00270 
00271                         /* skip blank lines and comments */
00272                         if(input[0]=='#' || input[0]==';' || input[0]=='\x0')
00273                                 continue;
00274                         
00275                         if((var=strtok(input,"="))==NULL)
00276                                 continue;
00277                         
00278                         if((val=strtok(NULL,"\n"))==NULL)
00279                                 continue;
00280                         
00281                         /* process a single config file */
00282                         if(!strcmp(var,"xodtemplate_config_file") || !strcmp(var,"cfg_file")){
00283 
00284                                 temp_buffer=(char *)strdup(val);
00285                                 if(config_base_dir!=NULL && val[0]!='/')
00286                                         dummy=asprintf(&config_file,"%s/%s",config_base_dir,temp_buffer);
00287                                 else
00288                                         config_file=temp_buffer;
00289 
00290                                 /* process the config file... */
00291                                 result=xodtemplate_process_config_file(config_file,options);
00292 
00293                                 my_free(config_file);
00294                                 
00295                                 /* if there was an error processing the config file, break out of loop */
00296                                 if(result==ERROR)
00297                                         break;
00298                                 }
00299 
00300                         /* process all files in a config directory */
00301                         else if(!strcmp(var,"xodtemplate_config_dir") || !strcmp(var,"cfg_dir")){
00302                                 
00303                                 temp_buffer=(char *)strdup(val);
00304                                 if(config_base_dir!=NULL && val[0]!='/')
00305                                         dummy=asprintf(&config_file,"%s/%s",config_base_dir,temp_buffer);
00306                                 else
00307                                         config_file=temp_buffer;
00308 
00309                                 /* strip trailing / if necessary */
00310                                 if(config_file!=NULL && config_file[strlen(config_file)-1]=='/')
00311                                         config_file[strlen(config_file)-1]='\x0';
00312 
00313                                 /* process the config directory... */
00314                                 result=xodtemplate_process_config_dir(config_file,options);
00315 
00316                                 my_free(config_file);
00317 
00318                                 /* if there was an error processing the config file, break out of loop */
00319                                 if(result==ERROR)
00320                                         break;
00321                                 }
00322                         }
00323 
00324                 /* free memory and close the file */
00325                 my_free(config_base_dir);
00326                 my_free(input);
00327                 mmap_fclose(thefile);
00328                 }
00329 
00330         if(test_scheduling==TRUE)
00331                 gettimeofday(&tv[1],NULL);
00332 #endif
00333 
00334 #ifdef NSCGI
00335         /* CGIs process only one file - the cached objects file */
00336         result=xodtemplate_process_config_file(xodtemplate_cache_file,options);
00337 #endif
00338 
00339 #ifdef NSCORE
00340 
00341         /* only perform intensive operations if we're not using the precached object file */
00342         if(use_precached_objects==FALSE){
00343 
00344                 /* resolve objects definitions */
00345                 if(result==OK)
00346                         result=xodtemplate_resolve_objects();
00347                 if(test_scheduling==TRUE)
00348                         gettimeofday(&tv[2],NULL);
00349 
00350                 /* cleanup some additive inheritance stuff... */
00351                 xodtemplate_clean_additive_strings();
00352 
00353                 /* do the meat and potatoes stuff... */
00354                 if(result==OK)
00355                         result=xodtemplate_recombobulate_contactgroups();
00356                 if(test_scheduling==TRUE)
00357                         gettimeofday(&tv[3],NULL);
00358                 
00359                 if(result==OK)
00360                         result=xodtemplate_recombobulate_hostgroups();
00361                 if(test_scheduling==TRUE)
00362                         gettimeofday(&tv[4],NULL);
00363                 
00364                 if(result==OK)
00365                         result=xodtemplate_duplicate_services();
00366                 if(test_scheduling==TRUE)
00367                         gettimeofday(&tv[5],NULL);
00368                 
00369                 if(result==OK)
00370                         result=xodtemplate_recombobulate_servicegroups();
00371                 if(test_scheduling==TRUE)
00372                         gettimeofday(&tv[6],NULL);
00373 
00374                 if(result==OK)
00375                         result=xodtemplate_duplicate_objects();
00376                 if(test_scheduling==TRUE)
00377                         gettimeofday(&tv[7],NULL);
00378 
00379                 /* NOTE: some missing defaults (notification options, etc.) are also applied here */
00380                 if(result==OK)
00381                         result=xodtemplate_inherit_object_properties();
00382                 if(test_scheduling==TRUE)
00383                         gettimeofday(&tv[8],NULL);
00384 
00385                 if(result==OK)
00386                         result=xodtemplate_recombobulate_object_contacts();
00387                 if(test_scheduling==TRUE)
00388                         gettimeofday(&tv[9],NULL);
00389 
00390                 /* sort objects */
00391                 if(result==OK)
00392                         result=xodtemplate_sort_objects();
00393                 if(test_scheduling==TRUE)
00394                         gettimeofday(&tv[10],NULL);
00395                 }
00396 
00397         if(result==OK){
00398 
00399                 /* merge host/service extinfo definitions with host/service definitions */
00400                 /* this will be removed in Nagios 4.x */
00401                 xodtemplate_merge_extinfo_ojects();
00402 
00403                 /* cache object definitions for the CGIs and external apps */
00404                 if(cache==TRUE)
00405                         xodtemplate_cache_objects(xodtemplate_cache_file);
00406 
00407                 /* precache object definitions for future runs */
00408                 if(precache==TRUE)
00409                         xodtemplate_cache_objects(xodtemplate_precache_file);
00410                 }
00411 
00412         if(test_scheduling==TRUE)
00413                 gettimeofday(&tv[11],NULL);
00414 
00415 #endif
00416 
00417         /* register objects */
00418         if(result==OK)
00419                 result=xodtemplate_register_objects();
00420 #ifdef NSCORE
00421         if(test_scheduling==TRUE)
00422                 gettimeofday(&tv[12],NULL);
00423 #endif
00424 
00425         /* cleanup */
00426         xodtemplate_free_memory();
00427 #ifdef NSCORE
00428         if(test_scheduling==TRUE)
00429                 gettimeofday(&tv[13],NULL);
00430 #endif
00431 
00432         /* free memory */
00433         my_free(xodtemplate_cache_file);
00434         my_free(xodtemplate_precache_file);
00435 
00436 #ifdef NSCORE
00437         if(test_scheduling==TRUE){
00438 
00439                 runtime[0]=(double)((double)(tv[1].tv_sec-tv[0].tv_sec)+(double)((tv[1].tv_usec-tv[0].tv_usec)/1000.0)/1000.0);
00440                 if(use_precached_objects==FALSE){
00441                         runtime[1]=(double)((double)(tv[2].tv_sec-tv[1].tv_sec)+(double)((tv[2].tv_usec-tv[1].tv_usec)/1000.0)/1000.0);
00442                         runtime[2]=(double)((double)(tv[3].tv_sec-tv[2].tv_sec)+(double)((tv[3].tv_usec-tv[2].tv_usec)/1000.0)/1000.0);
00443                         runtime[3]=(double)((double)(tv[4].tv_sec-tv[3].tv_sec)+(double)((tv[4].tv_usec-tv[3].tv_usec)/1000.0)/1000.0);
00444                         runtime[4]=(double)((double)(tv[5].tv_sec-tv[4].tv_sec)+(double)((tv[5].tv_usec-tv[4].tv_usec)/1000.0)/1000.0);
00445                         runtime[5]=(double)((double)(tv[6].tv_sec-tv[5].tv_sec)+(double)((tv[6].tv_usec-tv[5].tv_usec)/1000.0)/1000.0);
00446                         runtime[6]=(double)((double)(tv[7].tv_sec-tv[6].tv_sec)+(double)((tv[7].tv_usec-tv[6].tv_usec)/1000.0)/1000.0);
00447                         runtime[7]=(double)((double)(tv[8].tv_sec-tv[7].tv_sec)+(double)((tv[8].tv_usec-tv[7].tv_usec)/1000.0)/1000.0);
00448                         runtime[8]=(double)((double)(tv[9].tv_sec-tv[8].tv_sec)+(double)((tv[9].tv_usec-tv[8].tv_usec)/1000.0)/1000.0);
00449                         runtime[9]=(double)((double)(tv[10].tv_sec-tv[9].tv_sec)+(double)((tv[10].tv_usec-tv[9].tv_usec)/1000.0)/1000.0);
00450                         runtime[10]=(double)((double)(tv[11].tv_sec-tv[10].tv_sec)+(double)((tv[11].tv_usec-tv[10].tv_usec)/1000.0)/1000.0);
00451                         runtime[11]=(double)((double)(tv[12].tv_sec-tv[11].tv_sec)+(double)((tv[12].tv_usec-tv[11].tv_usec)/1000.0)/1000.0);
00452                         }
00453                 else{
00454                         runtime[1]=0.0;
00455                         runtime[2]=0.0;
00456                         runtime[3]=0.0;
00457                         runtime[4]=0.0;
00458                         runtime[5]=0.0;
00459                         runtime[6]=0.0;
00460                         runtime[7]=0.0;
00461                         runtime[8]=0.0;
00462                         runtime[9]=0.0;
00463                         runtime[10]=0.0;
00464                         runtime[11]=(double)((double)(tv[12].tv_sec-tv[1].tv_sec)+(double)((tv[12].tv_usec-tv[1].tv_usec)/1000.0)/1000.0);
00465                         }
00466                 runtime[12]=(double)((double)(tv[13].tv_sec-tv[12].tv_sec)+(double)((tv[13].tv_usec-tv[12].tv_usec)/1000.0)/1000.0);
00467                 runtime[13]=(double)((double)(tv[13].tv_sec-tv[0].tv_sec)+(double)((tv[13].tv_usec-tv[0].tv_usec)/1000.0)/1000.0);
00468 
00469                 printf("Timing information on object configuration processing is listed\n");
00470                 printf("below.  You can use this information to see if precaching your\n");
00471                 printf("object configuration would be useful.\n\n");
00472 
00473                 printf("Object Config Source: %s\n\n",(use_precached_objects==TRUE)?"Pre-cached config file":"Config files (uncached)");
00474 
00475                 printf("OBJECT CONFIG PROCESSING TIMES      (* = Potential for precache savings with -u option)\n");
00476                 printf("----------------------------------\n");
00477                 printf("Read:                 %.6lf sec\n",runtime[0]);
00478                 printf("Resolve:              %.6lf sec  *\n",runtime[1]);
00479                 printf("Recomb Contactgroups: %.6lf sec  *\n",runtime[2]);
00480                 printf("Recomb Hostgroups:    %.6lf sec  *\n",runtime[3]);
00481                 printf("Dup Services:         %.6lf sec  *\n",runtime[4]);
00482                 printf("Recomb Servicegroups: %.6lf sec  *\n",runtime[5]);
00483                 printf("Duplicate:            %.6lf sec  *\n",runtime[6]);
00484                 printf("Inherit:              %.6lf sec  *\n",runtime[7]);
00485                 printf("Recomb Contacts:      %.6lf sec  *\n",runtime[8]);
00486                 printf("Sort:                 %.6lf sec  *\n",runtime[9]);
00487 /*              printf("Cache:                %.6lf sec\n",runtime[10]);*/
00488                 printf("Register:             %.6lf sec\n",runtime[11]);
00489                 printf("Free:                 %.6lf sec\n",runtime[12]);
00490                 printf("                      ============\n");
00491                 printf("TOTAL:                %.6lf sec  ",runtime[13]);
00492                 if(use_precached_objects==FALSE)
00493                         printf("* = %.6lf sec (%.2f%%) estimated savings",runtime[13]-runtime[12]-runtime[11]-runtime[0],((runtime[13]-runtime[12]-runtime[11]-runtime[0])/runtime[13])*100.0);
00494                 printf("\n");
00495                 printf("\n\n");
00496                 }
00497 #endif
00498 
00499         return result;
00500         }
00501 
00502 
00503 
00504 /* grab config variable from main config file */
00505 int xodtemplate_grab_config_info(char *main_config_file){
00506         char *input=NULL;
00507         char *var=NULL;
00508         char *val=NULL;
00509         mmapfile *thefile=NULL;
00510 #ifdef NSCORE
00511         icinga_macros *mac;
00512 #endif
00513 
00514         /* open the main config file for reading */
00515         if((thefile=mmap_fopen(main_config_file))==NULL)
00516                 return ERROR;
00517 
00518         /* read in all lines from the main config file */
00519         while(1){
00520 
00521                 /* free memory */
00522                 my_free(input);
00523 
00524                 /* read the next line */
00525                 if((input=mmap_fgets_multiline(thefile))==NULL)
00526                         break;
00527 
00528                 /* strip input */
00529                 strip(input);
00530 
00531                 /* skip blank lines and comments */
00532                 if(input[0]=='#' || input[0]==';' || input[0]=='\x0')
00533                         continue;
00534 
00535                 if((var=strtok(input,"="))==NULL)
00536                         continue;
00537 
00538                 if((val=strtok(NULL,"\n"))==NULL)
00539                         continue;
00540 
00541                 /* cached object file definition (overrides default location) */
00542                 if(!strcmp(var,"object_cache_file"))
00543                         xodtemplate_cache_file=(char *)strdup(val);
00544 
00545                 /* pre-cached object file definition */
00546                 if(!strcmp(var,"precached_object_file"))
00547                         xodtemplate_precache_file=(char *)strdup(val);
00548                 }
00549 
00550         /* close the file */
00551         mmap_fclose(thefile);
00552 
00553         /* default locations */
00554         if(xodtemplate_cache_file==NULL)
00555                 xodtemplate_cache_file=(char *)strdup(DEFAULT_OBJECT_CACHE_FILE);
00556         if(xodtemplate_precache_file==NULL)
00557                 xodtemplate_precache_file=(char *)strdup(DEFAULT_PRECACHED_OBJECT_FILE);
00558 
00559         /* make sure we have what we need */
00560         if(xodtemplate_cache_file==NULL || xodtemplate_precache_file==NULL)
00561                 return ERROR;
00562 
00563 #ifdef NSCORE
00564         mac = get_global_macros();
00565 
00566         /* save the object cache file macro */
00567         my_free(mac->x[MACRO_OBJECTCACHEFILE]);
00568         if((mac->x[MACRO_OBJECTCACHEFILE]=(char *)strdup(xodtemplate_cache_file)))
00569                 strip(mac->x[MACRO_OBJECTCACHEFILE]);
00570 #endif
00571 
00572         return OK;
00573         }
00574 
00575 
00576 
00577 /* process all files in a specific config directory */
00578 int xodtemplate_process_config_dir(char *dirname, int options){
00579         char file[MAX_FILENAME_LENGTH];
00580         DIR *dirp=NULL;
00581         struct dirent *dirfile=NULL;
00582         int result=OK;
00583         register int x=0;
00584         struct stat stat_buf;
00585 
00586 #ifdef NSCORE
00587         if(verify_config==TRUE)
00588                 printf("Processing object config directory '%s'...\n",dirname);
00589 #endif
00590 
00591         /* open the directory for reading */
00592         dirp=opendir(dirname);
00593         if(dirp==NULL){
00594                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not open config directory '%s' for reading.\n",dirname);
00595                 return ERROR;
00596                 }
00597 
00598         /* process all files in the directory... */
00599         while((dirfile=readdir(dirp))!=NULL){
00600 
00601                 /* skip hidden files and directories, and current and parent dir */
00602                 if(dirfile->d_name[0]=='.')
00603                         continue;
00604 
00605                 /* create /path/to/file */
00606                 snprintf(file,sizeof(file),"%s/%s",dirname,dirfile->d_name);
00607                 file[sizeof(file)-1]='\x0';
00608 
00609                 /* process this if it's a non-hidden config file... */
00610                 if(stat(file,&stat_buf)==-1){
00611                         logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Could not open config directory member '%s' for reading.\n",file);
00612                         closedir(dirp);
00613                         return ERROR;
00614                         }
00615 
00616                 switch(stat_buf.st_mode & S_IFMT){
00617 
00618                 case S_IFREG:
00619                         x=strlen(dirfile->d_name);
00620                         if(x<=4 || strcmp(dirfile->d_name+(x-4),".cfg"))
00621                                 break;
00622 
00623                         /* process the config file */
00624                         result=xodtemplate_process_config_file(file,options);
00625 
00626                         if(result==ERROR){
00627                                 closedir(dirp);
00628                                 return ERROR;
00629                                 }
00630 
00631                         break;
00632 
00633                 case S_IFDIR:
00634                         /* recurse into subdirectories... */
00635                         result=xodtemplate_process_config_dir(file,options);
00636 
00637                         if(result==ERROR){
00638                                 closedir(dirp);
00639                                 return ERROR;
00640                                 }
00641 
00642                         break;
00643 
00644                 default:
00645                         /* everything else we ignore */
00646                         break;
00647                         }
00648                 }
00649 
00650         closedir(dirp);
00651 
00652         return result;
00653         }
00654 
00655 
00656 /* process data in a specific config file */
00657 int xodtemplate_process_config_file(char *filename, int options){
00658         mmapfile *thefile=NULL;
00659         char *input=NULL;
00660         register int in_definition=FALSE;
00661         register int current_line=0;
00662         int result=OK;
00663         register int x=0;
00664         register int y=0;
00665         char *ptr=NULL;
00666         int empty_def=TRUE;
00667 
00668 
00669 #ifdef NSCORE
00670         if(verify_config==TRUE)
00671                 printf("Processing object config file '%s'...\n",filename);
00672 #endif
00673 
00674         /* save config file name */
00675         xodtemplate_config_files[xodtemplate_current_config_file++]=(char *)strdup(filename);
00676 
00677         /* reallocate memory for config files */
00678         if(!(xodtemplate_current_config_file%256)){
00679                 xodtemplate_config_files=(char **)realloc(xodtemplate_config_files,(xodtemplate_current_config_file+256)*sizeof(char **));
00680                 if(xodtemplate_config_files==NULL)
00681                         return ERROR;
00682                 }
00683 
00684         /* open the config file for reading */
00685         if((thefile=mmap_fopen(filename))==NULL){
00686                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Cannot open config file '%s' for reading: %s\n",filename,strerror(errno));
00687                 return ERROR;
00688                 }
00689 
00690         /* read in all lines from the config file */
00691         while(1){
00692 
00693                 /* free memory */
00694                 my_free(input);
00695 
00696                 /* read the next line */
00697                 if((input=mmap_fgets_multiline(thefile))==NULL)
00698                         break;
00699 
00700                 current_line=thefile->current_line;
00701 
00702                 /* grab data before comment delimiter - faster than a strtok() and strncpy()... */
00703                 for(x=0;input[x]!='\x0';x++){
00704                         if(input[x]==';'){
00705                                 if(x==0)
00706                                         break;
00707                                 else if(input[x-1]!='\\')
00708                                         break;
00709                                 }
00710                         }
00711                 input[x]='\x0';
00712 
00713                 /* strip input */
00714                 strip(input);
00715 
00716                 /* skip empty lines */
00717                 if(input[0]=='\x0' || input[0]=='#')
00718                         continue;
00719 
00720                 /* this is the start of an object definition */
00721                 if(strstr(input,"define")==input){
00722 
00723                         /* get the type of object we're defining... */
00724                         for(x=6;input[x]!='\x0';x++)
00725                                 if(input[x]!=' ' && input[x]!='\t')
00726                                         break;
00727                         for(y=0;input[x]!='\x0';x++){
00728                                 if(input[x]==' ' || input[x]=='\t' ||  input[x]=='{')
00729                                         break;
00730                                 else
00731                                         input[y++]=input[x];
00732                                 }
00733                         input[y]='\x0';
00734 
00735                         /* make sure an object type is specified... */
00736                         if(input[0]=='\x0'){
00737                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: No object type specified in file '%s' on line %d.\n",filename,current_line);
00738                                 result=ERROR;
00739                                 break;
00740                                 }
00741 
00742                         /* check validity of object type */
00743                         if(strcmp(input,"timeperiod") && strcmp(input,"command") && strcmp(input,"contact") && strcmp(input,"contactgroup") && strcmp(input,"host") && strcmp(input,"hostgroup") && strcmp(input,"servicegroup") && strcmp(input,"service") && strcmp(input,"servicedependency") && strcmp(input,"serviceescalation") && strcmp(input,"hostgroupescalation") && strcmp(input,"hostdependency") && strcmp(input,"hostescalation") && strcmp(input,"hostextinfo") && strcmp(input,"serviceextinfo") && strcmp(input,"module")){
00744                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid object definition type '%s' in file '%s' on line %d.\n",input,filename,current_line);
00745                                 result=ERROR;
00746                                 break;
00747                                 }
00748 
00749                         /* we're already in an object definition... */
00750                         if(in_definition==TRUE){
00751                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Unexpected start of object definition in file '%s' on line %d.  Make sure you close preceding objects before starting a new one.\n",filename,current_line);
00752                                 result=ERROR;
00753                                 break;
00754                                 }
00755 
00756                         /* start a new definition */
00757                         if(xodtemplate_begin_object_definition(input,options,xodtemplate_current_config_file,current_line)==ERROR){
00758                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add object definition in file '%s' on line %d.\n",filename,current_line);
00759                                 result=ERROR;
00760                                 break;
00761                                 }
00762 
00763                         in_definition=TRUE;
00764                         empty_def=TRUE; /* set the default at the beginning */
00765                         }
00766 
00767                 /* we're currently inside an object definition */
00768                 else if(in_definition==TRUE){
00769 
00770                         /* this is the close of an object definition */
00771                         if(!strcmp(input,"}")){
00772 
00773                                 /* check if definition is empty */
00774                                 if(empty_def==TRUE){
00775                                         /* this is a hack in order to not register this empty object! */
00776                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Empty definition found in file '%s' on line %d.\n",filename,current_line);
00777                                         xodtemplate_add_object_property("register 0",options);
00778                                 }
00779 
00780                                 in_definition=FALSE;
00781 
00782                                 /* close out current definition */
00783                                 if(xodtemplate_end_object_definition(options)==ERROR){
00784                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not complete object definition in file '%s' on line %d.\n",filename,current_line);
00785                                         result=ERROR;
00786                                         break;
00787                                         }
00788                                 }
00789 
00790                         /* this is a directive inside an object definition */
00791                         else{
00792 
00793                                 /* add directive to object definition */
00794                                 if(xodtemplate_add_object_property(input,options)==ERROR){
00795                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add object property in file '%s' on line %d.\n",filename,current_line);
00796                                         result=ERROR;
00797                                         break;
00798                                         }
00799 
00800                                 empty_def=FALSE; /* indicate that we just registered an attribute */
00801 
00802                                 }
00803                         }
00804 
00805                 /* include another file */
00806                 else if(strstr(input,"include_file=")==input){
00807 
00808                         ptr=strtok(input,"=");
00809                         ptr=strtok(NULL,"\n");
00810 
00811                         if(ptr!=NULL){
00812                                 result=xodtemplate_process_config_file(ptr,options);
00813                                 if(result==ERROR)
00814                                         break;
00815                                 }
00816                         }
00817 
00818                 /* include a directory */
00819                 else if(strstr(input,"include_dir")==input){
00820 
00821                         ptr=strtok(input,"=");
00822                         ptr=strtok(NULL,"\n");
00823 
00824                         if(ptr!=NULL){
00825                                 result=xodtemplate_process_config_dir(ptr,options);
00826                                 if(result==ERROR)
00827                                         break;
00828                                 }
00829                         }
00830 
00831                 /* unexpected token or statement */
00832                 else{
00833                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Unexpected token or statement in file '%s' on line %d.\n",filename,current_line);
00834                         result=ERROR;
00835                         break;
00836                         }
00837                 }
00838 
00839         /* free memory and close file */
00840         my_free(input);
00841         mmap_fclose(thefile);
00842 
00843         /* whoops - EOF while we were in the middle of an object definition... */
00844         if(in_definition==TRUE && result==OK){
00845                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Unexpected EOF in file '%s' on line %d - check for a missing closing bracket.\n",filename,current_line);
00846                 result=ERROR;
00847                 }
00848 
00849         return result;
00850         }
00851 
00852 
00853 
00854 
00855 
00856 /******************************************************************/
00857 /***************** OBJECT DEFINITION FUNCTIONS ********************/
00858 /******************************************************************/
00859 
00860 /*
00861  * all objects start the same way, so we can get rid of quite
00862  * a lot of code with this struct-offset-insensitive macro
00863  * Credits to Andreas Ericsson
00864  */
00865 #define xod_begin_def(type) \
00866         do { \
00867                 new_##type = (xodtemplate_##type *)calloc(1, sizeof(*new_##type)); \
00868                 if (new_##type == NULL) \
00869                         return ERROR; \
00870                 new_##type->register_object=TRUE; \
00871                 new_##type->_config_file=config_file; \
00872                 new_##type->_start_line=start_line; \
00873         \
00874                 /* precached object files are already sorted, so add to tail */ \
00875                 if(presorted_objects==TRUE){ \
00876                         \
00877                         if(xodtemplate_##type##_list==NULL){ \
00878                                 xodtemplate_##type##_list=new_##type; \
00879                                 xodtemplate_##type##_list_tail=xodtemplate_##type##_list; \
00880                         } else { \
00881                                 xodtemplate_##type##_list_tail->next=new_##type; \
00882                                 xodtemplate_##type##_list_tail=new_##type; \
00883                         } \
00884         \
00885                         /* update current object pointer */ \
00886                         xodtemplate_current_object=xodtemplate_##type##_list_tail; \
00887                 } else { \
00888                         /* add new object to head of list in memory */ \
00889                         new_##type->next=xodtemplate_##type##_list; \
00890                         xodtemplate_##type##_list=new_##type; \
00891         \
00892                         /* update current object pointer */ \
00893                         xodtemplate_current_object=xodtemplate_##type##_list; \
00894                 } \
00895         } while (0)
00896 
00897 /* starts a new object definition */
00898 int xodtemplate_begin_object_definition(char *input, int options, int config_file, int start_line){
00899         int result=OK;
00900         xodtemplate_timeperiod *new_timeperiod=NULL;
00901         xodtemplate_command *new_command=NULL;
00902         xodtemplate_contactgroup *new_contactgroup=NULL;
00903         xodtemplate_hostgroup *new_hostgroup=NULL;
00904         xodtemplate_servicegroup *new_servicegroup=NULL;
00905         xodtemplate_servicedependency *new_servicedependency=NULL;
00906         xodtemplate_serviceescalation *new_serviceescalation=NULL;
00907         xodtemplate_contact *new_contact=NULL;
00908         xodtemplate_host *new_host=NULL;
00909         xodtemplate_service *new_service=NULL;
00910         xodtemplate_hostdependency *new_hostdependency=NULL;
00911         xodtemplate_hostescalation *new_hostescalation=NULL;
00912         xodtemplate_hostextinfo *new_hostextinfo=NULL;
00913         xodtemplate_serviceextinfo *new_serviceextinfo=NULL;
00914         xodtemplate_module *new_module=NULL;
00915 
00916 
00917         if(!strcmp(input,"service"))
00918                 xodtemplate_current_object_type=XODTEMPLATE_SERVICE;
00919         else if(!strcmp(input,"host"))
00920                 xodtemplate_current_object_type=XODTEMPLATE_HOST;
00921         else if(!strcmp(input,"command"))
00922                 xodtemplate_current_object_type=XODTEMPLATE_COMMAND;
00923         else if(!strcmp(input,"contact"))
00924                 xodtemplate_current_object_type=XODTEMPLATE_CONTACT;
00925         else if(!strcmp(input,"contactgroup"))
00926                 xodtemplate_current_object_type=XODTEMPLATE_CONTACTGROUP;
00927         else if(!strcmp(input,"hostgroup"))
00928                 xodtemplate_current_object_type=XODTEMPLATE_HOSTGROUP;
00929         else if(!strcmp(input,"servicegroup"))
00930                 xodtemplate_current_object_type=XODTEMPLATE_SERVICEGROUP;
00931         else if(!strcmp(input,"timeperiod"))
00932                 xodtemplate_current_object_type=XODTEMPLATE_TIMEPERIOD;
00933         else if(!strcmp(input,"servicedependency"))
00934                 xodtemplate_current_object_type=XODTEMPLATE_SERVICEDEPENDENCY;
00935         else if(!strcmp(input,"serviceescalation"))
00936                 xodtemplate_current_object_type=XODTEMPLATE_SERVICEESCALATION;
00937         else if(!strcmp(input,"hostdependency"))
00938                 xodtemplate_current_object_type=XODTEMPLATE_HOSTDEPENDENCY;
00939         else if(!strcmp(input,"hostescalation"))
00940                 xodtemplate_current_object_type=XODTEMPLATE_HOSTESCALATION;
00941         else if(!strcmp(input,"hostextinfo"))
00942                 xodtemplate_current_object_type=XODTEMPLATE_HOSTEXTINFO;
00943         else if(!strcmp(input,"serviceextinfo"))
00944                 xodtemplate_current_object_type=XODTEMPLATE_SERVICEEXTINFO;
00945         else if(!strcmp(input,"module"))
00946                 xodtemplate_current_object_type=XODTEMPLATE_MODULE;
00947         else
00948                 return ERROR;
00949 
00950 
00951         /* check to see if we should process this type of object */
00952         switch(xodtemplate_current_object_type){
00953         case XODTEMPLATE_TIMEPERIOD:
00954                 if(!(options & READ_TIMEPERIODS))
00955                         return OK;
00956                 break;
00957         case XODTEMPLATE_COMMAND:
00958                 if(!(options & READ_COMMANDS))
00959                         return OK;
00960                 break;
00961         case XODTEMPLATE_CONTACT:
00962                 if(!(options & READ_CONTACTS))
00963                         return OK;
00964                 break;
00965         case XODTEMPLATE_CONTACTGROUP:
00966                 if(!(options & READ_CONTACTGROUPS))
00967                         return OK;
00968                 break;
00969         case XODTEMPLATE_HOST:
00970                 if(!(options & READ_HOSTS))
00971                         return OK;
00972                 break;
00973         case XODTEMPLATE_HOSTGROUP:
00974                 if(!(options & READ_HOSTGROUPS))
00975                         return OK;
00976                 break;
00977         case XODTEMPLATE_SERVICEGROUP:
00978                 if(!(options & READ_SERVICEGROUPS))
00979                         return OK;
00980                 break;
00981         case XODTEMPLATE_SERVICE:
00982                 if(!(options & READ_SERVICES))
00983                         return OK;
00984                 break;
00985         case XODTEMPLATE_SERVICEDEPENDENCY:
00986                 if(!(options & READ_SERVICEDEPENDENCIES))
00987                         return OK;
00988                 break;
00989         case XODTEMPLATE_SERVICEESCALATION:
00990                 if(!(options & READ_SERVICEESCALATIONS))
00991                         return OK;
00992                 break;
00993         case XODTEMPLATE_HOSTDEPENDENCY:
00994                 if(!(options & READ_HOSTDEPENDENCIES))
00995                         return OK;
00996                 break;
00997         case XODTEMPLATE_HOSTESCALATION:
00998                 if(!(options & READ_HOSTESCALATIONS))
00999                         return OK;
01000                 break;
01001         case XODTEMPLATE_HOSTEXTINFO:
01002                 if(!(options & READ_HOSTEXTINFO))
01003                         return OK;
01004                 break;
01005         case XODTEMPLATE_SERVICEEXTINFO:
01006                 if(!(options & READ_SERVICEEXTINFO))
01007                         return OK;
01008                 break;
01009         case XODTEMPLATE_MODULE:
01010                 if(!(options & READ_MODULES))
01011                         return OK;
01012                 break;
01013         default:
01014                 return ERROR;
01015                 break;
01016                 }
01017 
01018 
01019 
01020         /* add a new (blank) object */
01021         switch(xodtemplate_current_object_type){
01022 
01023         case XODTEMPLATE_TIMEPERIOD:
01024                 xod_begin_def(timeperiod);
01025                 break;
01026 
01027         case XODTEMPLATE_COMMAND:
01028                 xod_begin_def(command);
01029                 break;
01030 
01031         case XODTEMPLATE_CONTACTGROUP:
01032                 xod_begin_def(contactgroup);
01033                 break;
01034 
01035         case XODTEMPLATE_HOSTGROUP:
01036                 xod_begin_def(hostgroup);
01037                 break;
01038 
01039         case XODTEMPLATE_SERVICEGROUP:
01040                 xod_begin_def(servicegroup);
01041                 break;
01042 
01043         case XODTEMPLATE_SERVICEDEPENDENCY:
01044                 xod_begin_def(servicedependency);
01045                 break;
01046 
01047         case XODTEMPLATE_SERVICEESCALATION:
01048                 xod_begin_def(serviceescalation);
01049                 new_serviceescalation->first_notification=-2;
01050                 new_serviceescalation->last_notification=-2;
01051 #ifdef USE_ST_BASED_ESCAL_RANGES
01052                 new_serviceescalation->first_warning_notification=-2;
01053                 new_serviceescalation->last_warning_notification=-2;
01054                 new_serviceescalation->first_critical_notification=-2;
01055                 new_serviceescalation->last_critical_notification=-2;
01056                 new_serviceescalation->first_unknown_notification=-2;
01057                 new_serviceescalation->last_unknown_notification=-2;
01058                 new_serviceescalation->notification_interval=-2.0;
01059 #endif
01060                 break;
01061 
01062         case XODTEMPLATE_CONTACT:
01063                 xod_begin_def(contact);
01064                 new_contact->host_notifications_enabled=TRUE;
01065                 new_contact->service_notifications_enabled=TRUE;
01066                 new_contact->can_submit_commands=TRUE;
01067                 new_contact->retain_status_information=TRUE;
01068                 new_contact->retain_nonstatus_information=TRUE;
01069                 break;
01070 
01071         case XODTEMPLATE_HOST:
01072                 xod_begin_def(host);
01073                 new_host->check_interval=5.0;
01074                 new_host->retry_interval=1.0;
01075                 new_host->active_checks_enabled=TRUE;
01076                 new_host->passive_checks_enabled=TRUE;
01077                 new_host->obsess_over_host=TRUE;
01078                 new_host->max_check_attempts=-2;
01079                 new_host->event_handler_enabled=TRUE;
01080                 new_host->flap_detection_enabled=TRUE;
01081                 new_host->flap_detection_on_up=TRUE;
01082                 new_host->flap_detection_on_down=TRUE;
01083                 new_host->flap_detection_on_unreachable=TRUE;
01084                 new_host->notifications_enabled=TRUE;
01085                 new_host->notification_interval=30.0;
01086                 new_host->process_perf_data=TRUE;
01087                 new_host->failure_prediction_enabled=TRUE;
01088                 new_host->x_2d=-1;
01089                 new_host->y_2d=-1;
01090                 new_host->retain_status_information=TRUE;
01091                 new_host->retain_nonstatus_information=TRUE;
01092                 break;
01093 
01094         case XODTEMPLATE_SERVICE:
01095                 xod_begin_def(service);
01096                 new_service->initial_state=STATE_OK;
01097                 new_service->max_check_attempts=-2;
01098                 new_service->check_interval=5.0;
01099                 new_service->retry_interval=1.0;
01100                 new_service->active_checks_enabled=TRUE;
01101                 new_service->passive_checks_enabled=TRUE;
01102                 new_service->parallelize_check=TRUE;
01103                 new_service->obsess_over_service=TRUE;
01104                 new_service->event_handler_enabled=TRUE;
01105                 new_service->flap_detection_enabled=TRUE;
01106                 new_service->flap_detection_on_ok=TRUE;
01107                 new_service->flap_detection_on_warning=TRUE;
01108                 new_service->flap_detection_on_unknown=TRUE;
01109                 new_service->flap_detection_on_critical=TRUE;
01110                 new_service->notifications_enabled=TRUE;
01111                 new_service->notification_interval=30.0;
01112                 new_service->process_perf_data=TRUE;
01113                 new_service->failure_prediction_enabled=TRUE;
01114                 new_service->retain_status_information=TRUE;
01115                 new_service->retain_nonstatus_information=TRUE;
01116                 
01117                 /* true service, so is not from host group, must be set AFTER have_initial_state*/
01118                 xodtemplate_unset_service_is_from_hostgroup(new_service);
01119                 break;
01120 
01121         case XODTEMPLATE_HOSTDEPENDENCY:
01122                 xod_begin_def(hostdependency);
01123                 break;
01124 
01125         case XODTEMPLATE_HOSTESCALATION:
01126                 xod_begin_def(hostescalation);
01127                 new_hostescalation->first_notification=-2;
01128                 new_hostescalation->last_notification=-2;
01129 #ifdef USE_ST_BASED_ESCAL_RANGE         
01130                 new_hostescalation->first_down_notification=-2;
01131                 new_hostescalation->last_down_notification=-2;
01132                 new_hostescalation->first_unreachable_notification=-2;
01133                 new_hostescalation->last_unreachable_notification=-2;
01134                 new_hostescalation->notification_interval=-2.0;
01135 #endif
01136                 break;
01137 
01138         case XODTEMPLATE_HOSTEXTINFO:
01139                 xod_begin_def(hostextinfo);
01140                 new_hostextinfo->x_2d=-1;
01141                 new_hostextinfo->y_2d=-1;
01142                 break;
01143 
01144         case XODTEMPLATE_SERVICEEXTINFO:
01145                 xod_begin_def(serviceextinfo);
01146                 break;
01147 
01148         case XODTEMPLATE_MODULE:
01149                 xod_begin_def(module);
01150                 break;
01151 
01152         default:
01153                 return ERROR;
01154                 break;
01155                 }
01156 
01157         return result;
01158         }
01159 #undef xod_begin_def /* we don't need this anymore */
01160 
01161 
01162 /* adds a property to an object definition */
01163 int xodtemplate_add_object_property(char *input, int options){
01164         int result=OK;
01165         char *variable=NULL;
01166         char *value=NULL;
01167         char *temp_ptr=NULL;
01168         char *customvarname=NULL;
01169         char *customvarvalue=NULL;
01170         xodtemplate_timeperiod *temp_timeperiod=NULL;
01171         xodtemplate_command *temp_command=NULL;
01172         xodtemplate_contactgroup *temp_contactgroup=NULL;
01173         xodtemplate_hostgroup *temp_hostgroup=NULL;
01174         xodtemplate_servicegroup *temp_servicegroup=NULL;
01175         xodtemplate_servicedependency *temp_servicedependency=NULL;
01176         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
01177         xodtemplate_contact *temp_contact=NULL;
01178         xodtemplate_host *temp_host=NULL;
01179         xodtemplate_service *temp_service=NULL;
01180         xodtemplate_hostdependency *temp_hostdependency=NULL;
01181         xodtemplate_hostescalation *temp_hostescalation=NULL;
01182         xodtemplate_hostextinfo *temp_hostextinfo=NULL;
01183         xodtemplate_serviceextinfo *temp_serviceextinfo=NULL;
01184         xodtemplate_module *temp_module=NULL;
01185         register int x=0;
01186         register int y=0;
01187         int force_skiplists=FALSE;
01188 
01189 
01190         /* should some object definitions be added to skiplists immediately? */
01191 #ifdef NSCORE
01192         if(use_precached_objects==TRUE)
01193                 force_skiplists=TRUE;
01194 #else
01195         force_skiplists=TRUE;
01196 #endif
01197 
01198         /* check to see if we should process this type of object */
01199         switch(xodtemplate_current_object_type){
01200         case XODTEMPLATE_TIMEPERIOD:
01201                 if(!(options & READ_TIMEPERIODS))
01202                         return OK;
01203                 break;
01204         case XODTEMPLATE_COMMAND:
01205                 if(!(options & READ_COMMANDS))
01206                         return OK;
01207                 break;
01208         case XODTEMPLATE_CONTACT:
01209                 if(!(options & READ_CONTACTS))
01210                         return OK;
01211                 break;
01212         case XODTEMPLATE_CONTACTGROUP:
01213                 if(!(options & READ_CONTACTGROUPS))
01214                         return OK;
01215                 break;
01216         case XODTEMPLATE_HOST:
01217                 if(!(options & READ_HOSTS))
01218                         return OK;
01219                 break;
01220         case XODTEMPLATE_HOSTGROUP:
01221                 if(!(options & READ_HOSTGROUPS))
01222                         return OK;
01223                 break;
01224         case XODTEMPLATE_SERVICEGROUP:
01225                 if(!(options & READ_SERVICEGROUPS))
01226                         return OK;
01227                 break;
01228         case XODTEMPLATE_SERVICE:
01229                 if(!(options & READ_SERVICES))
01230                         return OK;
01231                 break;
01232         case XODTEMPLATE_SERVICEDEPENDENCY:
01233                 if(!(options & READ_SERVICEDEPENDENCIES))
01234                         return OK;
01235                 break;
01236         case XODTEMPLATE_SERVICEESCALATION:
01237                 if(!(options & READ_SERVICEESCALATIONS))
01238                         return OK;
01239                 break;
01240         case XODTEMPLATE_HOSTDEPENDENCY:
01241                 if(!(options & READ_HOSTDEPENDENCIES))
01242                         return OK;
01243                 break;
01244         case XODTEMPLATE_HOSTESCALATION:
01245                 if(!(options & READ_HOSTESCALATIONS))
01246                         return OK;
01247                 break;
01248         case XODTEMPLATE_HOSTEXTINFO:
01249                 if(!(options & READ_HOSTEXTINFO))
01250                         return OK;
01251                 break;
01252         case XODTEMPLATE_SERVICEEXTINFO:
01253                 if(!(options & READ_SERVICEEXTINFO))
01254                         return OK;
01255                 break;
01256         case XODTEMPLATE_MODULE:
01257                 if(!(options & READ_MODULES))
01258                         return OK;
01259                 break;
01260         default:
01261                 return ERROR;
01262                 break;
01263                 }
01264 
01265         /* get variable name */
01266         if((variable=(char *)strdup(input))==NULL)
01267                 return ERROR;
01268         /* trim at first whitespace occurance */
01269         for(x=0,y=0;variable[x]!='\x0';x++){
01270                 if(variable[x]==' ' || variable[x]=='\t')
01271                         break;
01272                 y++;
01273                 }
01274         variable[y]='\x0';
01275                         
01276         /* get variable value */
01277         if((value=(char *)strdup(input+x))==NULL){
01278                 my_free(variable);
01279                 return ERROR;
01280                 }
01281         strip(value);
01282 
01283 
01284         switch(xodtemplate_current_object_type){
01285 
01286         case XODTEMPLATE_TIMEPERIOD:
01287                 
01288                 temp_timeperiod=(xodtemplate_timeperiod *)xodtemplate_current_object;
01289 
01290                 if(!strcmp(variable,"use")){
01291                         if((temp_timeperiod->template=(char *)strdup(value))==NULL)
01292                                 result=ERROR;
01293                         }
01294                 else if(!strcmp(variable,"name")){
01295 
01296                         if((temp_timeperiod->name=(char *)strdup(value))==NULL)
01297                                 result=ERROR;
01298 
01299                         if(result==OK){
01300                                 /* add timeperiod to template skiplist for fast searches */
01301                                 result=skiplist_insert(xobject_template_skiplists[X_TIMEPERIOD_SKIPLIST],(void *)temp_timeperiod);
01302                                 switch(result){
01303                                 case SKIPLIST_ERROR_DUPLICATE:
01304                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for timeperiod '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_timeperiod->_config_file),temp_timeperiod->_start_line);
01305                                         result=ERROR;
01306                                         break;
01307                                 case SKIPLIST_OK:
01308                                         result=OK;
01309                                         break;
01310                                 default:
01311                                         result=ERROR;
01312                                         break;
01313                                         }
01314                                 }
01315                         }
01316                 else if(!strcmp(variable,"timeperiod_name")){
01317                         if((temp_timeperiod->timeperiod_name=(char *)strdup(value))==NULL)
01318                                 result=ERROR;
01319 
01320                         if(result==OK){
01321                                 /* add timeperiod to template skiplist for fast searches */
01322                                 result=skiplist_insert(xobject_skiplists[X_TIMEPERIOD_SKIPLIST],(void *)temp_timeperiod);
01323                                 switch(result){
01324                                 case SKIPLIST_ERROR_DUPLICATE:
01325                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for timeperiod '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_timeperiod->_config_file),temp_timeperiod->_start_line);
01326                                         result=ERROR;
01327                                         break;
01328                                 case SKIPLIST_OK:
01329                                         result=OK;
01330                                         break;
01331                                 default:
01332                                         result=ERROR;
01333                                         break;
01334                                         }
01335                                 }
01336                         }
01337                 else if(!strcmp(variable,"alias")){
01338                         if((temp_timeperiod->alias=(char *)strdup(value))==NULL)
01339                                 result=ERROR;
01340                         }
01341                 else if(!strcmp(variable,"exclude")){
01342                         if((temp_timeperiod->exclusions=(char *)strdup(value))==NULL)
01343                                 result=ERROR;
01344                         }
01345                 else if(!strcmp(variable,"register"))
01346                         temp_timeperiod->register_object=(atoi(value)>0)?TRUE:FALSE;
01347                 else if(xodtemplate_parse_timeperiod_directive(temp_timeperiod,variable,value)==OK)
01348                         result=OK;
01349                 else{
01350                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid timeperiod object directive '%s'.\n",variable);
01351                         return ERROR;
01352                         }
01353                 break;
01354 
01355 
01356 
01357         case XODTEMPLATE_COMMAND:
01358 
01359                 temp_command=(xodtemplate_command *)xodtemplate_current_object;
01360 
01361                 if(!strcmp(variable,"use")){
01362                         if((temp_command->template=(char *)strdup(value))==NULL)
01363                                 result=ERROR;
01364                         }
01365                 else if(!strcmp(variable,"name")){
01366 
01367                         if((temp_command->name=(char *)strdup(value))==NULL)
01368                                 result=ERROR;
01369 
01370                         if(result==OK){
01371                                 /* add command to template skiplist for fast searches */
01372                                 result=skiplist_insert(xobject_template_skiplists[X_COMMAND_SKIPLIST],(void *)temp_command);
01373                                 switch(result){
01374                                 case SKIPLIST_ERROR_DUPLICATE:
01375                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for command '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_command->_config_file),temp_command->_start_line);
01376                                         result=ERROR;
01377                                         break;
01378                                 case SKIPLIST_OK:
01379                                         result=OK;
01380                                         break;
01381                                 default:
01382                                         result=ERROR;
01383                                         break;
01384                                         }
01385                                 }
01386                         }
01387                 else if(!strcmp(variable,"command_name")){
01388                         if((temp_command->command_name=(char *)strdup(value))==NULL)
01389                                 result=ERROR;
01390 
01391                         if(result==OK){
01392                                 /* add command to template skiplist for fast searches */
01393                                 result=skiplist_insert(xobject_skiplists[X_COMMAND_SKIPLIST],(void *)temp_command);
01394                                 switch(result){
01395                                 case SKIPLIST_ERROR_DUPLICATE:
01396                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for command '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_command->_config_file),temp_command->_start_line);
01397                                         result=ERROR;
01398                                         break;
01399                                 case SKIPLIST_OK:
01400                                         result=OK;
01401                                         break;
01402                                 default:
01403                                         result=ERROR;
01404                                         break;
01405                                         }
01406                                 }
01407                         }
01408                 else if(!strcmp(variable,"command_line")){
01409                         if((temp_command->command_line=(char *)strdup(value))==NULL)
01410                                 result=ERROR;
01411                         }
01412                 else if(!strcmp(variable,"register"))
01413                         temp_command->register_object=(atoi(value)>0)?TRUE:FALSE;
01414                 else{
01415                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid command object directive '%s'.\n",variable);
01416                         return ERROR;
01417                         }
01418 
01419                 break;
01420 
01421         case XODTEMPLATE_CONTACTGROUP:
01422 
01423                 temp_contactgroup=(xodtemplate_contactgroup *)xodtemplate_current_object;
01424 
01425                 if(!strcmp(variable,"use")){
01426                         if((temp_contactgroup->template=(char *)strdup(value))==NULL)
01427                                 result=ERROR;
01428                         }
01429                 else if(!strcmp(variable,"name")){
01430 
01431                         if((temp_contactgroup->name=(char *)strdup(value))==NULL)
01432                                 result=ERROR;
01433 
01434                         if(result==OK){
01435                                 /* add contactgroup to template skiplist for fast searches */
01436                                 result=skiplist_insert(xobject_template_skiplists[X_CONTACTGROUP_SKIPLIST],(void *)temp_contactgroup);
01437                                 switch(result){
01438                                 case SKIPLIST_ERROR_DUPLICATE:
01439                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for contactgroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_contactgroup->_config_file),temp_contactgroup->_start_line);
01440                                         result=ERROR;
01441                                         break;
01442                                 case SKIPLIST_OK:
01443                                         result=OK;
01444                                         break;
01445                                 default:
01446                                         result=ERROR;
01447                                         break;
01448                                         }
01449                                 }
01450                         }
01451                 else if(!strcmp(variable,"contactgroup_name")){
01452                         if((temp_contactgroup->contactgroup_name=(char *)strdup(value))==NULL)
01453                                 result=ERROR;
01454 
01455                         if(result==OK){
01456                                 /* add contactgroup to template skiplist for fast searches */
01457                                 result=skiplist_insert(xobject_skiplists[X_CONTACTGROUP_SKIPLIST],(void *)temp_contactgroup);
01458                                 switch(result){
01459                                 case SKIPLIST_ERROR_DUPLICATE:
01460                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for contactgroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_contactgroup->_config_file),temp_contactgroup->_start_line);
01461                                         result=ERROR;
01462                                         break;
01463                                 case SKIPLIST_OK:
01464                                         result=OK;
01465                                         break;
01466                                 default:
01467                                         result=ERROR;
01468                                         break;
01469                                         }
01470                                 }
01471                         }
01472                 else if(!strcmp(variable,"alias")){
01473                         if((temp_contactgroup->alias=(char *)strdup(value))==NULL)
01474                                 result=ERROR;
01475                         }
01476                 else if(!strcmp(variable,"members")){
01477                         if(strcmp(value,XODTEMPLATE_NULL)){
01478                                 if(temp_contactgroup->members==NULL)
01479                                         temp_contactgroup->members=(char *)strdup(value);
01480                                 else{
01481                                         temp_contactgroup->members=(char *)realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(value)+2);
01482                                         if(temp_contactgroup->members!=NULL){
01483                                                 strcat(temp_contactgroup->members,",");
01484                                                 strcat(temp_contactgroup->members,value);
01485                                                 }
01486                                         } 
01487                                 if(temp_contactgroup->members==NULL)
01488                                         result=ERROR;
01489                                 }
01490                         temp_contactgroup->have_members=TRUE;
01491                         }
01492                 else if(!strcmp(variable,"contactgroup_members")){
01493                         if(strcmp(value,XODTEMPLATE_NULL)){
01494                                 if(temp_contactgroup->contactgroup_members==NULL)
01495                                         temp_contactgroup->contactgroup_members=(char *)strdup(value);
01496                                 else{
01497                                         temp_contactgroup->contactgroup_members=(char *)realloc(temp_contactgroup->contactgroup_members,strlen(temp_contactgroup->contactgroup_members)+strlen(value)+2);
01498                                         if(temp_contactgroup->contactgroup_members!=NULL){
01499                                                 strcat(temp_contactgroup->contactgroup_members,",");
01500                                                 strcat(temp_contactgroup->contactgroup_members,value);
01501                                                 }
01502                                         }
01503                                 if(temp_contactgroup->contactgroup_members==NULL)
01504                                         result=ERROR;
01505                                 }
01506                         temp_contactgroup->have_contactgroup_members=TRUE;
01507                         }
01508                 else if(!strcmp(variable,"register"))
01509                         temp_contactgroup->register_object=(atoi(value)>0)?TRUE:FALSE;
01510                 else{
01511                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid contactgroup object directive '%s'.\n",variable);
01512                         return ERROR;
01513                         }
01514 
01515                 break;
01516 
01517         case XODTEMPLATE_HOSTGROUP:
01518 
01519                 temp_hostgroup=(xodtemplate_hostgroup *)xodtemplate_current_object;
01520 
01521                 if(!strcmp(variable,"use")){
01522                         if((temp_hostgroup->template=(char *)strdup(value))==NULL)
01523                                 result=ERROR;
01524                         }
01525                 else if(!strcmp(variable,"name")){
01526 
01527                         if((temp_hostgroup->name=(char *)strdup(value))==NULL)
01528                                 result=ERROR;
01529 
01530                         if(result==OK){
01531                                 /* add hostgroup to template skiplist for fast searches */
01532                                 result=skiplist_insert(xobject_template_skiplists[X_HOSTGROUP_SKIPLIST],(void *)temp_hostgroup);
01533                                 switch(result){
01534                                 case SKIPLIST_ERROR_DUPLICATE:
01535                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for hostgroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_hostgroup->_config_file),temp_hostgroup->_start_line);
01536                                         result=ERROR;
01537                                         break;
01538                                 case SKIPLIST_OK:
01539                                         result=OK;
01540                                         break;
01541                                 default:
01542                                         result=ERROR;
01543                                         break;
01544                                         }
01545                                 }
01546                         }
01547                 else if(!strcmp(variable,"hostgroup_name")){
01548                         if((temp_hostgroup->hostgroup_name=(char *)strdup(value))==NULL)
01549                                 result=ERROR;
01550 
01551                         if(result==OK){
01552                                 /* add hostgroup to template skiplist for fast searches */
01553                                 result=skiplist_insert(xobject_skiplists[X_HOSTGROUP_SKIPLIST],(void *)temp_hostgroup);
01554                                 switch(result){
01555                                 case SKIPLIST_ERROR_DUPLICATE:
01556                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for hostgroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_hostgroup->_config_file),temp_hostgroup->_start_line);
01557                                         result=ERROR;
01558                                         break;
01559                                 case SKIPLIST_OK:
01560                                         result=OK;
01561                                         break;
01562                                 default:
01563                                         result=ERROR;
01564                                         break;
01565                                         }
01566                                 }
01567                         }
01568                 else if(!strcmp(variable,"alias")){
01569                         if((temp_hostgroup->alias=(char *)strdup(value))==NULL)
01570                                 result=ERROR;
01571                         }
01572                 else if(!strcmp(variable,"members")){
01573                         if(strcmp(value,XODTEMPLATE_NULL)){
01574                                 if(temp_hostgroup->members==NULL)
01575                                         temp_hostgroup->members=(char *)strdup(value);
01576                                 else{
01577                                         temp_hostgroup->members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(value)+2);
01578                                         if(temp_hostgroup->members!=NULL){
01579                                                 strcat(temp_hostgroup->members,",");
01580                                                 strcat(temp_hostgroup->members,value);
01581                                                 }
01582                                         } 
01583                                 if(temp_hostgroup->members==NULL)
01584                                         result=ERROR;
01585                                 }
01586                         temp_hostgroup->have_members=TRUE;
01587                         }
01588                 else if(!strcmp(variable,"hostgroup_members")){
01589                         if(strcmp(value,XODTEMPLATE_NULL)){
01590                                 if(temp_hostgroup->hostgroup_members==NULL)
01591                                         temp_hostgroup->hostgroup_members=(char *)strdup(value);
01592                                 else{
01593                                         temp_hostgroup->hostgroup_members=(char *)realloc(temp_hostgroup->hostgroup_members,strlen(temp_hostgroup->hostgroup_members)+strlen(value)+2);
01594                                         if(temp_hostgroup->hostgroup_members!=NULL){
01595                                                 strcat(temp_hostgroup->hostgroup_members,",");
01596                                                 strcat(temp_hostgroup->hostgroup_members,value);
01597                                                 }
01598                                         }
01599                                 if(temp_hostgroup->hostgroup_members==NULL)
01600                                         result=ERROR;
01601                                 }
01602                         temp_hostgroup->have_hostgroup_members=TRUE;
01603                         }
01604                 else if(!strcmp(variable,"notes")){
01605                         if(strcmp(value,XODTEMPLATE_NULL)){
01606                                 if((temp_hostgroup->notes=(char *)strdup(value))==NULL)
01607                                         result=ERROR;
01608                                 }
01609                         temp_hostgroup->have_notes=TRUE;
01610                         }
01611                 else if(!strcmp(variable,"notes_url")){
01612                         if(strcmp(value,XODTEMPLATE_NULL)){
01613                                 if((temp_hostgroup->notes_url=(char *)strdup(value))==NULL)
01614                                         result=ERROR;
01615                                 }
01616                         temp_hostgroup->have_notes_url=TRUE;
01617                         }
01618                 else if(!strcmp(variable,"action_url")){
01619                         if(strcmp(value,XODTEMPLATE_NULL)){
01620                                 if((temp_hostgroup->action_url=(char *)strdup(value))==NULL)
01621                                         result=ERROR;
01622                                 }
01623                         temp_hostgroup->have_action_url=TRUE;
01624                         }
01625                 else if(!strcmp(variable,"register"))
01626                         temp_hostgroup->register_object=(atoi(value)>0)?TRUE:FALSE;
01627                 else{
01628                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid hostgroup object directive '%s'.\n",variable);
01629                         return ERROR;
01630                         }
01631 
01632                 break;
01633 
01634         
01635         case XODTEMPLATE_SERVICEGROUP:
01636 
01637                 temp_servicegroup=(xodtemplate_servicegroup *)xodtemplate_current_object;
01638 
01639                 if(!strcmp(variable,"use")){
01640                         if((temp_servicegroup->template=(char *)strdup(value))==NULL)
01641                                 result=ERROR;
01642                         }
01643                 else if(!strcmp(variable,"name")){
01644 
01645                         if((temp_servicegroup->name=(char *)strdup(value))==NULL)
01646                                 result=ERROR;
01647 
01648                         if(result==OK){
01649                                 /* add servicegroup to template skiplist for fast searches */
01650                                 result=skiplist_insert(xobject_template_skiplists[X_SERVICEGROUP_SKIPLIST],(void *)temp_servicegroup);
01651                                 switch(result){
01652                                 case SKIPLIST_ERROR_DUPLICATE:
01653                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for servicegroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
01654                                         result=ERROR;
01655                                         break;
01656                                 case SKIPLIST_OK:
01657                                         result=OK;
01658                                         break;
01659                                 default:
01660                                         result=ERROR;
01661                                         break;
01662                                         }
01663                                 }
01664                         }
01665                 else if(!strcmp(variable,"servicegroup_name")){
01666                         if((temp_servicegroup->servicegroup_name=(char *)strdup(value))==NULL)
01667                                 result=ERROR;
01668 
01669                         if(result==OK){
01670                                 /* add servicegroup to template skiplist for fast searches */
01671                                 result=skiplist_insert(xobject_skiplists[X_SERVICEGROUP_SKIPLIST],(void *)temp_servicegroup);
01672                                 switch(result){
01673                                 case SKIPLIST_ERROR_DUPLICATE:
01674                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for servicegroup '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
01675                                         result=ERROR;
01676                                         break;
01677                                 case SKIPLIST_OK:
01678                                         result=OK;
01679                                         break;
01680                                 default:
01681                                         result=ERROR;
01682                                         break;
01683                                         }
01684                                 }
01685                         }
01686                 else if(!strcmp(variable,"alias")){
01687                         if((temp_servicegroup->alias=(char *)strdup(value))==NULL)
01688                                 result=ERROR;
01689                         }
01690                 else if(!strcmp(variable,"members")){
01691                         if(strcmp(value,XODTEMPLATE_NULL)){
01692                                 if(temp_servicegroup->members==NULL)
01693                                         temp_servicegroup->members=(char *)strdup(value);
01694                                 else{
01695                                         temp_servicegroup->members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(value)+2);
01696                                         if(temp_servicegroup->members!=NULL){
01697                                                 strcat(temp_servicegroup->members,",");
01698                                                 strcat(temp_servicegroup->members,value);
01699                                                 }
01700                                         }
01701                                 if(temp_servicegroup->members==NULL)
01702                                         result=ERROR;
01703                                 }
01704                         temp_servicegroup->have_members=TRUE;
01705                         }
01706                 else if(!strcmp(variable,"servicegroup_members")){
01707                         if(strcmp(value,XODTEMPLATE_NULL)){
01708                                 if(temp_servicegroup->servicegroup_members==NULL)
01709                                         temp_servicegroup->servicegroup_members=(char *)strdup(value);
01710                                 else{
01711                                         temp_servicegroup->servicegroup_members=(char *)realloc(temp_servicegroup->servicegroup_members,strlen(temp_servicegroup->servicegroup_members)+strlen(value)+2);
01712                                         if(temp_servicegroup->servicegroup_members!=NULL){
01713                                                 strcat(temp_servicegroup->servicegroup_members,",");
01714                                                 strcat(temp_servicegroup->servicegroup_members,value);
01715                                                 }
01716                                         }
01717                                 if(temp_servicegroup->servicegroup_members==NULL)
01718                                         result=ERROR;
01719                                 }
01720                         temp_servicegroup->have_servicegroup_members=TRUE;
01721                         }
01722                 else if(!strcmp(variable,"notes")){
01723                         if(strcmp(value,XODTEMPLATE_NULL)){
01724                                 if((temp_servicegroup->notes=(char *)strdup(value))==NULL)
01725                                         result=ERROR;
01726                                 }
01727                         temp_servicegroup->have_notes=TRUE;
01728                         }
01729                 else if(!strcmp(variable,"notes_url")){
01730                         if(strcmp(value,XODTEMPLATE_NULL)){
01731                                 if((temp_servicegroup->notes_url=(char *)strdup(value))==NULL)
01732                                         result=ERROR;
01733                                 }
01734                         temp_servicegroup->have_notes_url=TRUE;
01735                         }
01736                 else if(!strcmp(variable,"action_url")){
01737                         if(strcmp(value,XODTEMPLATE_NULL)){
01738                                 if((temp_servicegroup->action_url=(char *)strdup(value))==NULL)
01739                                         result=ERROR;
01740                                 }
01741                         temp_servicegroup->have_action_url=TRUE;
01742                         }
01743                 else if(!strcmp(variable,"register"))
01744                         temp_servicegroup->register_object=(atoi(value)>0)?TRUE:FALSE;
01745                 else{
01746                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid servicegroup object directive '%s'.\n",variable);
01747                         return ERROR;
01748                         }
01749 
01750                 break;
01751 
01752         
01753         case XODTEMPLATE_SERVICEDEPENDENCY:
01754 
01755                 temp_servicedependency=(xodtemplate_servicedependency *)xodtemplate_current_object;
01756 
01757                 if(!strcmp(variable,"use")){
01758                         if((temp_servicedependency->template=(char *)strdup(value))==NULL)
01759                                 result=ERROR;
01760                         }
01761                 else if(!strcmp(variable,"name")){
01762 
01763                         if((temp_servicedependency->name=(char *)strdup(value))==NULL)
01764                                 result=ERROR;
01765 
01766                         if(result==OK){
01767                                 /* add dependency to template skiplist for fast searches */
01768                                 result=skiplist_insert(xobject_template_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],(void *)temp_servicedependency);
01769                                 switch(result){
01770                                 case SKIPLIST_ERROR_DUPLICATE:
01771                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service dependency '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
01772                                         result=ERROR;
01773                                         break;
01774                                 case SKIPLIST_OK:
01775                                         result=OK;
01776                                         break;
01777                                 default:
01778                                         result=ERROR;
01779                                         break;
01780                                         }
01781                                 }
01782                         }
01783                 else if(!strcmp(variable,"servicegroup") || !strcmp(variable,"servicegroups") || !strcmp(variable,"servicegroup_name")){
01784                         if(strcmp(value,XODTEMPLATE_NULL)){
01785                                 if((temp_servicedependency->servicegroup_name=(char *)strdup(value))==NULL)
01786                                         result=ERROR;
01787                                 }
01788                         temp_servicedependency->have_servicegroup_name=TRUE;
01789                         }
01790                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
01791                         if(strcmp(value,XODTEMPLATE_NULL)){
01792                                 if((temp_servicedependency->hostgroup_name=(char *)strdup(value))==NULL)
01793                                         result=ERROR;
01794                                 }
01795                         temp_servicedependency->have_hostgroup_name=TRUE;
01796                         }
01797                 else if(!strcmp(variable,"host") || !strcmp(variable,"host_name") || !strcmp(variable,"master_host") || !strcmp(variable,"master_host_name")){
01798                         if(strcmp(value,XODTEMPLATE_NULL)){
01799                                 if((temp_servicedependency->host_name=(char *)strdup(value))==NULL)
01800                                         result=ERROR;
01801                                 }
01802                         temp_servicedependency->have_host_name=TRUE;
01803                         }
01804                 else if(!strcmp(variable,"description") || !strcmp(variable,"service_description") || !strcmp(variable,"master_description") || !strcmp(variable,"master_service_description")){
01805                         if(strcmp(value,XODTEMPLATE_NULL)){
01806                                 if((temp_servicedependency->service_description=(char *)strdup(value))==NULL)
01807                                         result=ERROR;
01808                                 }
01809                         temp_servicedependency->have_service_description=TRUE;
01810                         }
01811                 else if(!strcmp(variable,"dependent_servicegroup") || !strcmp(variable,"dependent_servicegroups") || !strcmp(variable,"dependent_servicegroup_name")){
01812                         if(strcmp(value,XODTEMPLATE_NULL)){
01813                                 if((temp_servicedependency->dependent_servicegroup_name=(char *)strdup(value))==NULL)
01814                                         result=ERROR;
01815                                 }
01816                         temp_servicedependency->have_dependent_servicegroup_name=TRUE;
01817                         }
01818                 else if(!strcmp(variable,"dependent_hostgroup") || !strcmp(variable,"dependent_hostgroups") || !strcmp(variable,"dependent_hostgroup_name")){
01819                         if(strcmp(value,XODTEMPLATE_NULL)){
01820                                 if((temp_servicedependency->dependent_hostgroup_name=(char *)strdup(value))==NULL)
01821                                         result=ERROR;
01822                                 }
01823                         temp_servicedependency->have_dependent_hostgroup_name=TRUE;
01824                         }
01825                 else if(!strcmp(variable,"dependent_host") || !strcmp(variable,"dependent_host_name")){
01826                         if(strcmp(value,XODTEMPLATE_NULL)){
01827                                 if((temp_servicedependency->dependent_host_name=(char *)strdup(value))==NULL)
01828                                         result=ERROR;
01829                                 }
01830                         temp_servicedependency->have_dependent_host_name=TRUE;
01831 
01832                         /* NOTE: dependencies are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
01833                         if(result==OK && force_skiplists==TRUE && temp_servicedependency->dependent_host_name!=NULL && temp_servicedependency->dependent_service_description!=NULL){
01834                                 /* add servicedependency to template skiplist for fast searches */
01835                                 result=skiplist_insert(xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],(void *)temp_servicedependency);
01836                                 switch(result){
01837                                 case SKIPLIST_OK:
01838                                         result=OK;
01839                                         break;
01840                                 default:
01841                                         result=ERROR;
01842                                         break;
01843                                         }
01844                                 }
01845                         }
01846                 else if(!strcmp(variable,"dependent_description") || !strcmp(variable,"dependent_service_description")){
01847                         if(strcmp(value,XODTEMPLATE_NULL)){
01848                                 if((temp_servicedependency->dependent_service_description=(char *)strdup(value))==NULL)
01849                                         result=ERROR;
01850                                 }
01851                         temp_servicedependency->have_dependent_service_description=TRUE;
01852 
01853                         /* NOTE: dependencies are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
01854                         if(result==OK && force_skiplists==TRUE && temp_servicedependency->dependent_host_name!=NULL && temp_servicedependency->dependent_service_description!=NULL){
01855                                 /* add servicedependency to template skiplist for fast searches */
01856                                 result=skiplist_insert(xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],(void *)temp_servicedependency);
01857                                 switch(result){
01858                                 case SKIPLIST_OK:
01859                                         result=OK;
01860                                         break;
01861                                 default:
01862                                         result=ERROR;
01863                                         break;
01864                                         }
01865                                 }
01866                         }
01867                 else if(!strcmp(variable,"dependency_period")){
01868                         if(strcmp(value,XODTEMPLATE_NULL)){
01869                                 if((temp_servicedependency->dependency_period=(char *)strdup(value))==NULL)
01870                                         result=ERROR;
01871                                 }
01872                         temp_servicedependency->have_dependency_period=TRUE;
01873                         }
01874                 else if(!strcmp(variable,"inherits_parent")){
01875                         temp_servicedependency->inherits_parent=(atoi(value)>0)?TRUE:FALSE;
01876                         temp_servicedependency->have_inherits_parent=TRUE;
01877                         }
01878                 else if(!strcmp(variable,"execution_failure_options") || !strcmp(variable,"execution_failure_criteria")){
01879                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
01880                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"ok"))
01881                                         temp_servicedependency->fail_execute_on_ok=TRUE;
01882                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
01883                                         temp_servicedependency->fail_execute_on_unknown=TRUE;
01884                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
01885                                         temp_servicedependency->fail_execute_on_warning=TRUE;
01886                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
01887                                         temp_servicedependency->fail_execute_on_critical=TRUE;
01888                                 else if(!strcmp(temp_ptr,"p") || !strcmp(temp_ptr,"pending"))
01889                                         temp_servicedependency->fail_execute_on_pending=TRUE;
01890                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
01891                                         temp_servicedependency->fail_execute_on_ok=FALSE;
01892                                         temp_servicedependency->fail_execute_on_unknown=FALSE;
01893                                         temp_servicedependency->fail_execute_on_warning=FALSE;
01894                                         temp_servicedependency->fail_execute_on_critical=FALSE;
01895                                         }
01896                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
01897                                         temp_servicedependency->fail_execute_on_ok=TRUE;
01898                                         temp_servicedependency->fail_execute_on_unknown=TRUE;
01899                                         temp_servicedependency->fail_execute_on_warning=TRUE;
01900                                         temp_servicedependency->fail_execute_on_critical=TRUE;
01901                                         }
01902                                 else{
01903                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid execution dependency option '%s' in servicedependency definition.\n",temp_ptr);
01904                                         return ERROR;
01905                                         }
01906                                 }
01907                         temp_servicedependency->have_execution_dependency_options=TRUE;
01908                         }
01909                 else if(!strcmp(variable,"notification_failure_options") || !strcmp(variable,"notification_failure_criteria")){
01910                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
01911                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"ok"))
01912                                         temp_servicedependency->fail_notify_on_ok=TRUE;
01913                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
01914                                         temp_servicedependency->fail_notify_on_unknown=TRUE;
01915                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
01916                                         temp_servicedependency->fail_notify_on_warning=TRUE;
01917                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
01918                                         temp_servicedependency->fail_notify_on_critical=TRUE;
01919                                 else if(!strcmp(temp_ptr,"p") || !strcmp(temp_ptr,"pending"))
01920                                         temp_servicedependency->fail_notify_on_pending=TRUE;
01921                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
01922                                         temp_servicedependency->fail_notify_on_ok=FALSE;
01923                                         temp_servicedependency->fail_notify_on_unknown=FALSE;
01924                                         temp_servicedependency->fail_notify_on_warning=FALSE;
01925                                         temp_servicedependency->fail_notify_on_critical=FALSE;
01926                                         temp_servicedependency->fail_notify_on_pending=FALSE;
01927                                         }
01928                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
01929                                         temp_servicedependency->fail_notify_on_ok=TRUE;
01930                                         temp_servicedependency->fail_notify_on_unknown=TRUE;
01931                                         temp_servicedependency->fail_notify_on_warning=TRUE;
01932                                         temp_servicedependency->fail_notify_on_critical=TRUE;
01933                                         temp_servicedependency->fail_notify_on_pending=TRUE;
01934                                         }
01935                                 else{
01936                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification dependency option '%s' in servicedependency definition.\n",temp_ptr);
01937                                         return ERROR;
01938                                         }
01939                                 }
01940                         temp_servicedependency->have_notification_dependency_options=TRUE;
01941                         }
01942                 else if(!strcmp(variable,"register"))
01943                         temp_servicedependency->register_object=(atoi(value)>0)?TRUE:FALSE;
01944                 else{
01945                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid servicedependency object directive '%s'.\n",variable);
01946                         return ERROR;
01947                         }
01948 
01949                 break;
01950 
01951         
01952         case XODTEMPLATE_SERVICEESCALATION:
01953 
01954                 temp_serviceescalation=(xodtemplate_serviceescalation *)xodtemplate_current_object;
01955 
01956                 if(!strcmp(variable,"use")){
01957                         if((temp_serviceescalation->template=(char *)strdup(value))==NULL)
01958                                 result=ERROR;
01959                         }
01960                 else if(!strcmp(variable,"name")){
01961 
01962                         if((temp_serviceescalation->name=(char *)strdup(value))==NULL)
01963                                 result=ERROR;
01964 
01965                         if(result==OK){
01966                                 /* add escalation to template skiplist for fast searches */
01967                                 result=skiplist_insert(xobject_template_skiplists[X_SERVICEESCALATION_SKIPLIST],(void *)temp_serviceescalation);
01968                                 switch(result){
01969                                 case SKIPLIST_ERROR_DUPLICATE:
01970                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service escalation '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_serviceescalation->_config_file),temp_serviceescalation->_start_line);
01971                                         result=ERROR;
01972                                         break;
01973                                 case SKIPLIST_OK:
01974                                         result=OK;
01975                                         break;
01976                                 default:
01977                                         result=ERROR;
01978                                         break;
01979                                         }
01980                                 }
01981                         }
01982                 else if(!strcmp(variable,"host") || !strcmp(variable,"host_name")){
01983 
01984                         if(strcmp(value,XODTEMPLATE_NULL)){
01985                                 if((temp_serviceescalation->host_name=(char *)strdup(value))==NULL)
01986                                         result=ERROR;
01987                                 }
01988                         temp_serviceescalation->have_host_name=TRUE;
01989 
01990                         /* NOTE: escalations are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
01991                         if(result==OK && force_skiplists==TRUE  && temp_serviceescalation->host_name!=NULL && temp_serviceescalation->service_description!=NULL){
01992                                 /* add serviceescalation to template skiplist for fast searches */
01993                                 result=skiplist_insert(xobject_skiplists[X_SERVICEESCALATION_SKIPLIST],(void *)temp_serviceescalation);
01994                                 switch(result){
01995                                 case SKIPLIST_OK:
01996                                         result=OK;
01997                                         break;
01998                                 default:
01999                                         result=ERROR;
02000                                         break;
02001                                         }
02002                                 }
02003                         }
02004                 else if(!strcmp(variable,"description") || !strcmp(variable,"service_description")){
02005                         if(strcmp(value,XODTEMPLATE_NULL)){
02006                                 if((temp_serviceescalation->service_description=(char *)strdup(value))==NULL)
02007                                         result=ERROR;
02008                                 }
02009                         temp_serviceescalation->have_service_description=TRUE;
02010 
02011                         /* NOTE: escalations are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
02012                         if(result==OK && force_skiplists==TRUE  && temp_serviceescalation->host_name!=NULL && temp_serviceescalation->service_description!=NULL){
02013                                 /* add serviceescalation to template skiplist for fast searches */
02014                                 result=skiplist_insert(xobject_skiplists[X_SERVICEESCALATION_SKIPLIST],(void *)temp_serviceescalation);
02015                                 switch(result){
02016                                 case SKIPLIST_OK:
02017                                         result=OK;
02018                                         break;
02019                                 default:
02020                                         result=ERROR;
02021                                         break;
02022                                         }
02023                                 }
02024                         }
02025                 else if(!strcmp(variable,"servicegroup") || !strcmp(variable,"servicegroups") || !strcmp(variable,"servicegroup_name")){
02026                         if(strcmp(value,XODTEMPLATE_NULL)){
02027                                 if((temp_serviceescalation->servicegroup_name=(char *)strdup(value))==NULL)
02028                                         result=ERROR;
02029                                 }
02030                         temp_serviceescalation->have_servicegroup_name=TRUE;
02031                         }
02032                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
02033                         if(strcmp(value,XODTEMPLATE_NULL)){
02034                                 if((temp_serviceescalation->hostgroup_name=(char *)strdup(value))==NULL)
02035                                         result=ERROR;
02036                                 }
02037                         temp_serviceescalation->have_hostgroup_name=TRUE;
02038                         }
02039                 else if(!strcmp(variable,"contact_groups")){
02040                         if(strcmp(value,XODTEMPLATE_NULL)){
02041                                 if((temp_serviceescalation->contact_groups=(char *)strdup(value))==NULL)
02042                                         result=ERROR;
02043                                 }
02044                         temp_serviceescalation->have_contact_groups=TRUE;
02045                         }
02046                 else if(!strcmp(variable,"contacts")){
02047                         if(strcmp(value,XODTEMPLATE_NULL)){
02048                                 if((temp_serviceescalation->contacts=(char *)strdup(value))==NULL)
02049                                         result=ERROR;
02050                                 }
02051                         temp_serviceescalation->have_contacts=TRUE;
02052                         }
02053                 else if(!strcmp(variable,"escalation_period")){
02054                         if(strcmp(value,XODTEMPLATE_NULL)){
02055                                 if((temp_serviceescalation->escalation_period=(char *)strdup(value))==NULL)
02056                                         result=ERROR;
02057                                 }
02058                         temp_serviceescalation->have_escalation_period=TRUE;
02059                         }
02060                 else if(!strcmp(variable,"first_notification")){
02061                         temp_serviceescalation->first_notification=atoi(value);
02062                         temp_serviceescalation->have_first_notification=TRUE;
02063                         }
02064                 else if(!strcmp(variable,"last_notification")){
02065                         temp_serviceescalation->last_notification=atoi(value);
02066                         temp_serviceescalation->have_last_notification=TRUE;
02067                         }
02068 #ifdef USE_ST_BASED_ESCAL_RANGES
02069                 else if(!strcmp(variable,"first_warning_notification")){
02070                         temp_serviceescalation->first_warning_notification=atoi(value);
02071                         temp_serviceescalation->have_first_warning_notification=TRUE;
02072                         }
02073                 else if(!strcmp(variable,"last_warning_notification")){
02074                         temp_serviceescalation->last_warning_notification=atoi(value);
02075                         temp_serviceescalation->have_last_warning_notification=TRUE;
02076                         }
02077                 else if(!strcmp(variable,"first_critical_notification")){
02078                         temp_serviceescalation->first_critical_notification=atoi(value);
02079                         temp_serviceescalation->have_first_critical_notification=TRUE;
02080                         }
02081                 else if(!strcmp(variable,"last_critical_notification")){
02082                         temp_serviceescalation->last_critical_notification=atoi(value);
02083                         temp_serviceescalation->have_last_critical_notification=TRUE;
02084                         }
02085                 else if(!strcmp(variable,"first_unknown_notification")){
02086                         temp_serviceescalation->first_unknown_notification=atoi(value);
02087                         temp_serviceescalation->have_first_unknown_notification=TRUE;
02088                         }
02089                 else if(!strcmp(variable,"last_unknown_notification")){
02090                         temp_serviceescalation->last_unknown_notification=atoi(value);
02091                         temp_serviceescalation->have_last_unknown_notification=TRUE;
02092                         }
02093 #endif
02094                 else if(!strcmp(variable,"notification_interval")){
02095                         temp_serviceescalation->notification_interval=strtod(value,NULL);
02096                         temp_serviceescalation->have_notification_interval=TRUE;
02097                         }
02098                 else if(!strcmp(variable,"escalation_options")){
02099                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02100                                 if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
02101                                         temp_serviceescalation->escalate_on_warning=TRUE;
02102                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
02103                                         temp_serviceescalation->escalate_on_unknown=TRUE;
02104                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
02105                                         temp_serviceescalation->escalate_on_critical=TRUE;
02106                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
02107                                         temp_serviceescalation->escalate_on_recovery=TRUE;
02108                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02109                                         temp_serviceescalation->escalate_on_warning=FALSE;
02110                                         temp_serviceescalation->escalate_on_unknown=FALSE;
02111                                         temp_serviceescalation->escalate_on_critical=FALSE;
02112                                         temp_serviceescalation->escalate_on_recovery=FALSE;
02113                                         }
02114                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02115                                         temp_serviceescalation->escalate_on_warning=TRUE;
02116                                         temp_serviceescalation->escalate_on_unknown=TRUE;
02117                                         temp_serviceescalation->escalate_on_critical=TRUE;
02118                                         temp_serviceescalation->escalate_on_recovery=TRUE;
02119                                         }
02120                                 else{
02121                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid escalation option '%s' in serviceescalation definition.\n",temp_ptr);
02122                                         return ERROR;
02123                                         }
02124                                 }
02125                         temp_serviceescalation->have_escalation_options=TRUE;
02126                         }
02127                 else if(!strcmp(variable,"escalation_condition")){
02128                         /* create new escalation_condition (head of the condition list) */
02129                         xodtemplate_escalation_condition *temp_condition=(xodtemplate_escalation_condition *)malloc(sizeof(xodtemplate_escalation_condition));
02130                         if (xodtemplate_create_escalation_condition(value, temp_condition)==OK) {
02131                                 temp_serviceescalation->condition=temp_condition;
02132                         }
02133                         else {
02134                                         my_free(temp_condition);
02135                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not create escalation condition for serviceescalation .\n");
02136                                         return ERROR;
02137                         }       
02138                 }
02139                 else if(!strcmp(variable,"register"))
02140                         temp_serviceescalation->register_object=(atoi(value)>0)?TRUE:FALSE;
02141                 else{
02142                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid serviceescalation object directive '%s'.\n",variable);
02143                         return ERROR;
02144                         }
02145 
02146                 break;
02147         
02148 
02149         case XODTEMPLATE_CONTACT:
02150 
02151                 temp_contact=(xodtemplate_contact *)xodtemplate_current_object;
02152 
02153                 if(!strcmp(variable,"use")){
02154                         if((temp_contact->template=(char *)strdup(value))==NULL)
02155                                 result=ERROR;
02156                         }
02157                 else if(!strcmp(variable,"name")){
02158 
02159                         if((temp_contact->name=(char *)strdup(value))==NULL)
02160                                 result=ERROR;
02161 
02162                         if(result==OK){
02163                                 /* add contact to template skiplist for fast searches */
02164                                 result=skiplist_insert(xobject_template_skiplists[X_CONTACT_SKIPLIST],(void *)temp_contact);
02165                                 switch(result){
02166                                 case SKIPLIST_ERROR_DUPLICATE:
02167                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for contact '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_contact->_config_file),temp_contact->_start_line);
02168                                         result=ERROR;
02169                                         break;
02170                                 case SKIPLIST_OK:
02171                                         result=OK;
02172                                         break;
02173                                 default:
02174                                         result=ERROR;
02175                                         break;
02176                                         }
02177                                 }
02178                         }
02179                 else if(!strcmp(variable,"contact_name")){
02180                         if((temp_contact->contact_name=(char *)strdup(value))==NULL)
02181                                 result=ERROR;
02182 
02183                         if(result==OK){
02184                                 /* add contact to template skiplist for fast searches */
02185                                 result=skiplist_insert(xobject_skiplists[X_CONTACT_SKIPLIST],(void *)temp_contact);
02186                                 switch(result){
02187                                 case SKIPLIST_ERROR_DUPLICATE:
02188                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for contact '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_contact->_config_file),temp_contact->_start_line);
02189                                         result=ERROR;
02190                                         break;
02191                                 case SKIPLIST_OK:
02192                                         result=OK;
02193                                         break;
02194                                 default:
02195                                         result=ERROR;
02196                                         break;
02197                                         }
02198                                 }
02199                         }
02200                 else if(!strcmp(variable,"alias")){
02201                         if((temp_contact->alias=(char *)strdup(value))==NULL)
02202                                 result=ERROR;
02203                         }
02204                 else if(!strcmp(variable,"contact_groups") || !strcmp(variable,"contactgroups")){
02205                         if(strcmp(value,XODTEMPLATE_NULL)){
02206                                 if((temp_contact->contact_groups=(char *)strdup(value))==NULL)
02207                                         result=ERROR;
02208                                 }
02209                         temp_contact->have_contact_groups=TRUE;
02210                         }
02211                 else if(!strcmp(variable,"email")){
02212                         if(strcmp(value,XODTEMPLATE_NULL)){
02213                                 if((temp_contact->email=(char *)strdup(value))==NULL)
02214                                         result=ERROR;
02215                                 }
02216                         temp_contact->have_email=TRUE;
02217                         }
02218                 else if(!strcmp(variable,"pager")){
02219                         if(strcmp(value,XODTEMPLATE_NULL)){
02220                                 if((temp_contact->pager=(char *)strdup(value))==NULL)
02221                                         result=ERROR;
02222                                 }
02223                         temp_contact->have_pager=TRUE;
02224                         }
02225                 else if(strstr(variable,"address")==variable){
02226                         x=atoi(variable+7);
02227                         if(x<1 || x>MAX_XODTEMPLATE_CONTACT_ADDRESSES)
02228                                 result=ERROR;
02229                         else if(strcmp(value,XODTEMPLATE_NULL)){
02230                                 if((temp_contact->address[x-1]=(char *)strdup(value))==NULL)
02231                                         result=ERROR;
02232                                 }
02233                         if(result==OK)
02234                                 temp_contact->have_address[x-1]=TRUE;
02235                         }
02236                 else if(!strcmp(variable,"host_notification_period")){
02237                         if(strcmp(value,XODTEMPLATE_NULL)){
02238                                 if((temp_contact->host_notification_period=(char *)strdup(value))==NULL)
02239                                         result=ERROR;
02240                                 }
02241                         temp_contact->have_host_notification_period=TRUE;
02242                         }
02243                 else if(!strcmp(variable,"host_notification_commands")){
02244                         if(strcmp(value,XODTEMPLATE_NULL)){
02245                                 if((temp_contact->host_notification_commands=(char *)strdup(value))==NULL)
02246                                         result=ERROR;
02247                                 }
02248                         temp_contact->have_host_notification_commands=TRUE;
02249                         }
02250                 else if(!strcmp(variable,"service_notification_period")){
02251                         if(strcmp(value,XODTEMPLATE_NULL)){
02252                                 if((temp_contact->service_notification_period=(char *)strdup(value))==NULL)
02253                                         result=ERROR;
02254                                 }
02255                         temp_contact->have_service_notification_period=TRUE;
02256                         }
02257                 else if(!strcmp(variable,"service_notification_commands")){
02258                         if(strcmp(value,XODTEMPLATE_NULL)){
02259                                 if((temp_contact->service_notification_commands=(char *)strdup(value))==NULL)
02260                                         result=ERROR;
02261                                 }
02262                         temp_contact->have_service_notification_commands=TRUE;
02263                         }
02264                 else if(!strcmp(variable,"host_notification_options")){
02265                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02266                                 if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
02267                                         temp_contact->notify_on_host_down=TRUE;
02268                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
02269                                         temp_contact->notify_on_host_unreachable=TRUE;
02270                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
02271                                         temp_contact->notify_on_host_recovery=TRUE;
02272                                 else if(!strcmp(temp_ptr,"f") || !strcmp(temp_ptr,"flapping"))
02273                                         temp_contact->notify_on_host_flapping=TRUE;
02274                                 else if(!strcmp(temp_ptr,"s") || !strcmp(temp_ptr,"downtime"))
02275                                         temp_contact->notify_on_host_downtime=TRUE;
02276                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02277                                         temp_contact->notify_on_host_down=FALSE;
02278                                         temp_contact->notify_on_host_unreachable=FALSE;
02279                                         temp_contact->notify_on_host_recovery=FALSE;
02280                                         temp_contact->notify_on_host_flapping=FALSE;
02281                                         temp_contact->notify_on_host_downtime=FALSE;
02282                                         }
02283                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02284                                         temp_contact->notify_on_host_down=TRUE;
02285                                         temp_contact->notify_on_host_unreachable=TRUE;
02286                                         temp_contact->notify_on_host_recovery=TRUE;
02287                                         temp_contact->notify_on_host_flapping=TRUE;
02288                                         temp_contact->notify_on_host_downtime=TRUE;
02289                                         }
02290                                 else{
02291                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid host notification option '%s' in contact definition.\n",temp_ptr);
02292                                         return ERROR;
02293                                         }
02294                                 }
02295                         temp_contact->have_host_notification_options=TRUE;
02296                         }
02297                 else if(!strcmp(variable,"service_notification_options")){
02298                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02299                                 if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
02300                                         temp_contact->notify_on_service_unknown=TRUE;
02301                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
02302                                         temp_contact->notify_on_service_warning=TRUE;
02303                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
02304                                         temp_contact->notify_on_service_critical=TRUE;
02305                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
02306                                         temp_contact->notify_on_service_recovery=TRUE;
02307                                 else if(!strcmp(temp_ptr,"f") || !strcmp(temp_ptr,"flapping"))
02308                                         temp_contact->notify_on_service_flapping=TRUE;
02309                                 else if(!strcmp(temp_ptr,"s") || !strcmp(temp_ptr,"downtime"))
02310                                         temp_contact->notify_on_service_downtime=TRUE;
02311                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02312                                         temp_contact->notify_on_service_unknown=FALSE;
02313                                         temp_contact->notify_on_service_warning=FALSE;
02314                                         temp_contact->notify_on_service_critical=FALSE;
02315                                         temp_contact->notify_on_service_recovery=FALSE;
02316                                         temp_contact->notify_on_service_flapping=FALSE;
02317                                         temp_contact->notify_on_service_downtime=FALSE;
02318                                         }
02319                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02320                                         temp_contact->notify_on_service_unknown=TRUE;
02321                                         temp_contact->notify_on_service_warning=TRUE;
02322                                         temp_contact->notify_on_service_critical=TRUE;
02323                                         temp_contact->notify_on_service_recovery=TRUE;
02324                                         temp_contact->notify_on_service_flapping=TRUE;
02325                                         temp_contact->notify_on_service_downtime=TRUE;
02326                                         }
02327                                 else{
02328                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid service notification option '%s' in contact definition.\n",temp_ptr);
02329                                         return ERROR;
02330                                         }
02331                                 }
02332                         temp_contact->have_service_notification_options=TRUE;
02333                         }
02334                 else if(!strcmp(variable,"host_notifications_enabled")){
02335                         temp_contact->host_notifications_enabled=(atoi(value)>0)?TRUE:FALSE;
02336                         temp_contact->have_host_notifications_enabled=TRUE;
02337                         }
02338                 else if(!strcmp(variable,"service_notifications_enabled")){
02339                         temp_contact->service_notifications_enabled=(atoi(value)>0)?TRUE:FALSE;
02340                         temp_contact->have_service_notifications_enabled=TRUE;
02341                         }
02342                 else if(!strcmp(variable,"can_submit_commands")){
02343                         temp_contact->can_submit_commands=(atoi(value)>0)?TRUE:FALSE;
02344                         temp_contact->have_can_submit_commands=TRUE;
02345                         }
02346                 else if(!strcmp(variable,"retain_status_information")){
02347                         temp_contact->retain_status_information=(atoi(value)>0)?TRUE:FALSE;
02348                         temp_contact->have_retain_status_information=TRUE;
02349                         }
02350                 else if(!strcmp(variable,"retain_nonstatus_information")){
02351                         temp_contact->retain_nonstatus_information=(atoi(value)>0)?TRUE:FALSE;
02352                         temp_contact->have_retain_nonstatus_information=TRUE;
02353                         }
02354                 else if(!strcmp(variable,"register"))
02355                         temp_contact->register_object=(atoi(value)>0)?TRUE:FALSE;
02356                 else if(variable[0]=='_'){
02357 
02358                         /* get the variable name */
02359                         customvarname=(char *)strdup(variable+1);
02360 
02361                         /* make sure we have a variable name */
02362                         if(customvarname==NULL || !strcmp(customvarname,"")){
02363                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Null custom variable name.\n");
02364                                 my_free(customvarname);
02365                                 return ERROR;
02366                                 }
02367 
02368                         /* get the variable value */
02369                         if(strcmp(value,XODTEMPLATE_NULL))
02370                                 customvarvalue=(char *)strdup(value);
02371                         else
02372                                 customvarvalue=NULL;
02373 
02374                         /* add the custom variable */
02375                         if(xodtemplate_add_custom_variable_to_contact(temp_contact,customvarname,customvarvalue)==NULL){
02376                                 my_free(customvarname);
02377                                 my_free(customvarvalue);
02378                                 return ERROR;
02379                                 }
02380 
02381                         /* free memory */
02382                         my_free(customvarname);
02383                         my_free(customvarvalue);
02384                         }
02385                 else{
02386                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid contact object directive '%s'.\n",variable);
02387                         return ERROR;
02388                         }
02389 
02390                 break;
02391 
02392 
02393         case XODTEMPLATE_HOST:
02394 
02395                 temp_host=(xodtemplate_host *)xodtemplate_current_object;
02396 
02397                 if(!strcmp(variable,"use")){
02398                         if((temp_host->template=(char *)strdup(value))==NULL)
02399                                 result=ERROR;
02400                         }
02401                 else if(!strcmp(variable,"name")){
02402 
02403                         if((temp_host->name=(char *)strdup(value))==NULL)
02404                                 result=ERROR;
02405 
02406                         if(result==OK){
02407                                 /* add host to template skiplist for fast searches */
02408                                 result=skiplist_insert(xobject_template_skiplists[X_HOST_SKIPLIST],(void *)temp_host);
02409                                 switch(result){
02410                                 case SKIPLIST_ERROR_DUPLICATE:
02411                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for host '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_host->_config_file),temp_host->_start_line);
02412                                         result=ERROR;
02413                                         break;
02414                                 case SKIPLIST_OK:
02415                                         result=OK;
02416                                         break;
02417                                 default:
02418                                         result=ERROR;
02419                                         break;
02420                                         }
02421                                 }
02422                         }
02423                 else if(!strcmp(variable,"host_name")){
02424                         if((temp_host->host_name=(char *)strdup(value))==NULL)
02425                                 result=ERROR;
02426 
02427                         if(result==OK){
02428                                 /* add host to template skiplist for fast searches */
02429                                 result=skiplist_insert(xobject_skiplists[X_HOST_SKIPLIST],(void *)temp_host);
02430                                 switch(result){
02431                                 case SKIPLIST_ERROR_DUPLICATE:
02432                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for host '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_host->_config_file),temp_host->_start_line);
02433                                         result=ERROR;
02434                                         break;
02435                                 case SKIPLIST_OK:
02436                                         result=OK;
02437                                         break;
02438                                 default:
02439                                         result=ERROR;
02440                                         break;
02441                                         }
02442                                 }
02443                         }
02444                 else if(!strcmp(variable,"display_name")){
02445                         if(strcmp(value,XODTEMPLATE_NULL)){
02446                                 if((temp_host->display_name=(char *)strdup(value))==NULL)
02447                                         result=ERROR;
02448                                 }
02449                         temp_host->have_display_name=TRUE;
02450                         }
02451                 else if(!strcmp(variable,"alias")){
02452                         if((temp_host->alias=(char *)strdup(value))==NULL)
02453                                 result=ERROR;
02454                         }
02455                 else if(!strcmp(variable,"address")){
02456                         if((temp_host->address=(char *)strdup(value))==NULL)
02457                                 result=ERROR;
02458                         }
02459                 else if(!strcmp(variable,"address6")){
02460                         if((temp_host->address6=(char *)strdup(value))==NULL)
02461                                 result=ERROR;
02462                         }
02463                 else if(!strcmp(variable,"parents")){
02464                         if(strcmp(value,XODTEMPLATE_NULL)){
02465                                 if((temp_host->parents=(char *)strdup(value))==NULL)
02466                                         result=ERROR;
02467                                 }
02468                         temp_host->have_parents=TRUE;
02469                         }
02470                 else if(!strcmp(variable,"host_groups") || !strcmp(variable,"hostgroups")){
02471                         if(strcmp(value,XODTEMPLATE_NULL)){
02472                                 if((temp_host->host_groups=(char *)strdup(value))==NULL)
02473                                         result=ERROR;
02474                                 }
02475                         temp_host->have_host_groups=TRUE;
02476                         }
02477                 else if(!strcmp(variable,"contact_groups")){
02478                         if(strcmp(value,XODTEMPLATE_NULL)){
02479                                 if((temp_host->contact_groups=(char *)strdup(value))==NULL)
02480                                         result=ERROR;
02481                                 }
02482                         temp_host->have_contact_groups=TRUE;
02483                         }
02484                 else if(!strcmp(variable,"contacts")){
02485                         if(strcmp(value,XODTEMPLATE_NULL)){
02486                                 if((temp_host->contacts=(char *)strdup(value))==NULL)
02487                                         result=ERROR;
02488                                 }
02489                         temp_host->have_contacts=TRUE;
02490                         }
02491                 else if(!strcmp(variable,"notification_period")){
02492                         if(strcmp(value,XODTEMPLATE_NULL)){
02493                                 if((temp_host->notification_period=(char *)strdup(value))==NULL)
02494                                         result=ERROR;
02495                                 }
02496                         temp_host->have_notification_period=TRUE;
02497                         }
02498                 else if(!strcmp(variable,"check_command")){
02499                         if(strcmp(value,XODTEMPLATE_NULL)){
02500                                 if((temp_host->check_command=(char *)strdup(value))==NULL)
02501                                         result=ERROR;
02502                                 }
02503                         temp_host->have_check_command=TRUE;
02504                         }
02505                 else if(!strcmp(variable,"check_period")){
02506                         if(strcmp(value,XODTEMPLATE_NULL)){
02507                                 if((temp_host->check_period=(char *)strdup(value))==NULL)
02508                                         result=ERROR;
02509                                 }
02510                         temp_host->have_check_period=TRUE;
02511                         }
02512                 else if(!strcmp(variable,"event_handler")){
02513                         if(strcmp(value,XODTEMPLATE_NULL)){
02514                                 if((temp_host->event_handler=(char *)strdup(value))==NULL)
02515                                         result=ERROR;
02516                                 }
02517                         temp_host->have_event_handler=TRUE;
02518                         }
02519                 else if(!strcmp(variable,"failure_prediction_options")){
02520                         if(strcmp(value,XODTEMPLATE_NULL)){
02521                                 if((temp_host->failure_prediction_options=(char *)strdup(value))==NULL)
02522                                         result=ERROR;
02523                                 }
02524                         temp_host->have_failure_prediction_options=TRUE;
02525                         }
02526                 else if(!strcmp(variable,"notes")){
02527                         if(strcmp(value,XODTEMPLATE_NULL)){
02528                                 if((temp_host->notes=(char *)strdup(value))==NULL)
02529                                         result=ERROR;
02530                                 }
02531                         temp_host->have_notes=TRUE;
02532                         }
02533                 else if(!strcmp(variable,"notes_url")){
02534                         if(strcmp(value,XODTEMPLATE_NULL)){
02535                                 if((temp_host->notes_url=(char *)strdup(value))==NULL)
02536                                         result=ERROR;
02537                                 }
02538                         temp_host->have_notes_url=TRUE;
02539                         }
02540                 else if(!strcmp(variable,"action_url")){
02541                         if(strcmp(value,XODTEMPLATE_NULL)){
02542                                 if((temp_host->action_url=(char *)strdup(value))==NULL)
02543                                         result=ERROR;
02544                                 }
02545                         temp_host->have_action_url=TRUE;
02546                         }
02547                 else if(!strcmp(variable,"icon_image")){
02548                         if(strcmp(value,XODTEMPLATE_NULL)){
02549                                 if((temp_host->icon_image=(char *)strdup(value))==NULL)
02550                                         result=ERROR;
02551                                 }
02552                         temp_host->have_icon_image=TRUE;
02553                         }
02554                 else if(!strcmp(variable,"icon_image_alt")){
02555                         if(strcmp(value,XODTEMPLATE_NULL)){
02556                                 if((temp_host->icon_image_alt=(char *)strdup(value))==NULL)
02557                                         result=ERROR;
02558                                 }
02559                         temp_host->have_icon_image_alt=TRUE;
02560                         }
02561                 else if(!strcmp(variable,"vrml_image")){
02562                         if(strcmp(value,XODTEMPLATE_NULL)){
02563                                 if((temp_host->vrml_image=(char *)strdup(value))==NULL)
02564                                         result=ERROR;
02565                                 }
02566                         temp_host->have_vrml_image=TRUE;
02567                         }
02568                 else if(!strcmp(variable,"gd2_image")|| !strcmp(variable,"statusmap_image")){
02569                         if(strcmp(value,XODTEMPLATE_NULL)){
02570                                 if((temp_host->statusmap_image=(char *)strdup(value))==NULL)
02571                                         result=ERROR;
02572                                 }
02573                         temp_host->have_statusmap_image=TRUE;
02574                         }
02575                 else if(!strcmp(variable,"initial_state")){
02576                         if(!strcmp(value,"o") || !strcmp(value,"up"))
02577                                 temp_host->initial_state=0; /* HOST_UP */
02578                         else if(!strcmp(value,"d") || !strcmp(value,"down"))
02579                                 temp_host->initial_state=1; /* HOST_DOWN */
02580                         else if(!strcmp(value,"u") || !strcmp(value,"unreachable"))
02581                                 temp_host->initial_state=2; /* HOST_UNREACHABLE */
02582                         else{
02583                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid initial state '%s' in host definition.\n",value);
02584                                 result=ERROR;
02585                                 }
02586                         temp_host->have_initial_state=TRUE;
02587                         }
02588                 else if(!strcmp(variable,"check_interval") || !strcmp(variable,"normal_check_interval")){
02589                         temp_host->check_interval=strtod(value,NULL);
02590                         temp_host->have_check_interval=TRUE;
02591                         }
02592                 else if(!strcmp(variable,"retry_interval") || !strcmp(variable,"retry_check_interval")){
02593                         temp_host->retry_interval=strtod(value,NULL);
02594                         temp_host->have_retry_interval=TRUE;
02595                         }
02596                 else if(!strcmp(variable,"max_check_attempts")){
02597                         temp_host->max_check_attempts=atoi(value);
02598                         temp_host->have_max_check_attempts=TRUE;
02599                         }
02600                 else if(!strcmp(variable,"checks_enabled") || !strcmp(variable,"active_checks_enabled")){
02601                         temp_host->active_checks_enabled=(atoi(value)>0)?TRUE:FALSE;
02602                         temp_host->have_active_checks_enabled=TRUE;
02603                         }
02604                 else if(!strcmp(variable,"passive_checks_enabled")){
02605                         temp_host->passive_checks_enabled=(atoi(value)>0)?TRUE:FALSE;
02606                         temp_host->have_passive_checks_enabled=TRUE;
02607                         }
02608                 else if(!strcmp(variable,"event_handler_enabled")){
02609                         temp_host->event_handler_enabled=(atoi(value)>0)?TRUE:FALSE;
02610                         temp_host->have_event_handler_enabled=TRUE;
02611                         }
02612                 else if(!strcmp(variable,"check_freshness")){
02613                         temp_host->check_freshness=(atoi(value)>0)?TRUE:FALSE;
02614                         temp_host->have_check_freshness=TRUE;
02615                         }
02616                 else if(!strcmp(variable,"freshness_threshold")){
02617                         temp_host->freshness_threshold=atoi(value);
02618                         temp_host->have_freshness_threshold=TRUE;
02619                         }
02620                 else if(!strcmp(variable,"low_flap_threshold")){
02621                         temp_host->low_flap_threshold=strtod(value,NULL);
02622                         temp_host->have_low_flap_threshold=TRUE;
02623                         }
02624                 else if(!strcmp(variable,"high_flap_threshold")){
02625                         temp_host->high_flap_threshold=strtod(value,NULL);
02626                         temp_host->have_high_flap_threshold=TRUE;
02627                         }
02628                 else if(!strcmp(variable,"flap_detection_enabled")){
02629                         temp_host->flap_detection_enabled=(atoi(value)>0)?TRUE:FALSE;
02630                         temp_host->have_flap_detection_enabled=TRUE;
02631                         }
02632                 else if(!strcmp(variable,"flap_detection_options")){
02633 
02634                         /* user is specifying something, so discard defaults... */
02635                         temp_host->flap_detection_on_up=FALSE;
02636                         temp_host->flap_detection_on_down=FALSE;
02637                         temp_host->flap_detection_on_unreachable=FALSE;
02638 
02639                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02640                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"up"))
02641                                         temp_host->flap_detection_on_up=TRUE;
02642                                 else if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
02643                                         temp_host->flap_detection_on_down=TRUE;
02644                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
02645                                         temp_host->flap_detection_on_unreachable=TRUE;
02646                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02647                                         temp_host->flap_detection_on_up=FALSE;
02648                                         temp_host->flap_detection_on_down=FALSE;
02649                                         temp_host->flap_detection_on_unreachable=FALSE;
02650                                         }
02651                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02652                                         temp_host->flap_detection_on_up=TRUE;
02653                                         temp_host->flap_detection_on_down=TRUE;
02654                                         temp_host->flap_detection_on_unreachable=TRUE;
02655                                         }
02656                                 else{
02657                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid flap detection option '%s' in host definition.\n",temp_ptr);
02658                                         result=ERROR;
02659                                         }
02660                                 }
02661                         temp_host->have_flap_detection_options=TRUE;
02662                         }
02663                 else if(!strcmp(variable,"notification_options")){
02664                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02665                                 if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
02666                                         temp_host->notify_on_down=TRUE;
02667                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
02668                                         temp_host->notify_on_unreachable=TRUE;
02669                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
02670                                         temp_host->notify_on_recovery=TRUE;
02671                                 else if(!strcmp(temp_ptr,"f") || !strcmp(temp_ptr,"flapping"))
02672                                         temp_host->notify_on_flapping=TRUE;
02673                                 else if(!strcmp(temp_ptr,"s") || !strcmp(temp_ptr,"downtime"))
02674                                         temp_host->notify_on_downtime=TRUE;
02675                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02676                                         temp_host->notify_on_down=FALSE;
02677                                         temp_host->notify_on_unreachable=FALSE;
02678                                         temp_host->notify_on_recovery=FALSE;
02679                                         temp_host->notify_on_flapping=FALSE;
02680                                         temp_host->notify_on_downtime=FALSE;
02681                                         }
02682                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02683                                         temp_host->notify_on_down=TRUE;
02684                                         temp_host->notify_on_unreachable=TRUE;
02685                                         temp_host->notify_on_recovery=TRUE;
02686                                         temp_host->notify_on_flapping=TRUE;
02687                                         temp_host->notify_on_downtime=TRUE;
02688                                         }
02689                                 else{
02690                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification option '%s' in host definition.\n",temp_ptr);
02691                                         result=ERROR;
02692                                         }
02693                                 }
02694                         temp_host->have_notification_options=TRUE;
02695                         }
02696                 else if(!strcmp(variable,"notifications_enabled")){
02697                         temp_host->notifications_enabled=(atoi(value)>0)?TRUE:FALSE;
02698                         temp_host->have_notifications_enabled=TRUE;
02699                         }
02700                 else if(!strcmp(variable,"notification_interval")){
02701                         temp_host->notification_interval=strtod(value,NULL);
02702                         temp_host->have_notification_interval=TRUE;
02703                         }
02704                 else if(!strcmp(variable,"first_notification_delay")){
02705                         temp_host->first_notification_delay=strtod(value,NULL);
02706                         temp_host->have_first_notification_delay=TRUE;
02707                         }
02708                 else if(!strcmp(variable,"stalking_options")){
02709                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
02710                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"up"))
02711                                         temp_host->stalk_on_up=TRUE;
02712                                 else if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
02713                                         temp_host->stalk_on_down=TRUE;
02714                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
02715                                         temp_host->stalk_on_unreachable=TRUE;
02716                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
02717                                         temp_host->stalk_on_up=FALSE;
02718                                         temp_host->stalk_on_down=FALSE;
02719                                         temp_host->stalk_on_unreachable=FALSE;
02720                                         }
02721                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
02722                                         temp_host->stalk_on_up=TRUE;
02723                                         temp_host->stalk_on_down=TRUE;
02724                                         temp_host->stalk_on_unreachable=TRUE;
02725                                         }
02726                                 else{
02727                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid stalking option '%s' in host definition.\n",temp_ptr);
02728                                         result=ERROR;
02729                                         }
02730                                 }
02731                         temp_host->have_stalking_options=TRUE;
02732                         }
02733                 else if(!strcmp(variable,"process_perf_data")){
02734                         temp_host->process_perf_data=(atoi(value)>0)?TRUE:FALSE;
02735                         temp_host->have_process_perf_data=TRUE;
02736                         }
02737                 else if(!strcmp(variable,"failure_prediction_enabled")){
02738                         temp_host->failure_prediction_enabled=(atoi(value)>0)?TRUE:FALSE;
02739                         temp_host->have_failure_prediction_enabled=TRUE;
02740                         }
02741                 else if(!strcmp(variable,"2d_coords")){
02742                         if((temp_ptr=strtok(value,", "))==NULL){
02743                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 2d_coords value '%s' in host definition.\n",temp_ptr);
02744                                 return ERROR;
02745                                 }
02746                         temp_host->x_2d=atoi(temp_ptr);
02747                         if((temp_ptr=strtok(NULL,", "))==NULL){
02748                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 2d_coords value '%s' in host definition.\n",temp_ptr);
02749                                 return ERROR;
02750                                 }
02751                         temp_host->y_2d=atoi(temp_ptr);
02752                         temp_host->have_2d_coords=TRUE;
02753                         }
02754                 else if(!strcmp(variable,"3d_coords")){
02755                         if((temp_ptr=strtok(value,", "))==NULL){
02756                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in host definition.\n",temp_ptr);
02757                                 return ERROR;
02758                                 }
02759                         temp_host->x_3d=strtod(temp_ptr,NULL);
02760                         if((temp_ptr=strtok(NULL,", "))==NULL){
02761                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in host definition.\n",temp_ptr);
02762                                 return ERROR;
02763                                 }
02764                         temp_host->y_3d=strtod(temp_ptr,NULL);
02765                         if((temp_ptr=strtok(NULL,", "))==NULL){
02766                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in host definition.\n",temp_ptr);
02767                                 return ERROR;
02768                                 }
02769                         temp_host->z_3d=strtod(temp_ptr,NULL);
02770                         temp_host->have_3d_coords=TRUE;
02771                         }
02772                 else if(!strcmp(variable,"obsess_over_host")){
02773                         temp_host->obsess_over_host=(atoi(value)>0)?TRUE:FALSE;
02774                         temp_host->have_obsess_over_host=TRUE;
02775                         }
02776                 else if(!strcmp(variable,"retain_status_information")){
02777                         temp_host->retain_status_information=(atoi(value)>0)?TRUE:FALSE;
02778                         temp_host->have_retain_status_information=TRUE;
02779                         }
02780                 else if(!strcmp(variable,"retain_nonstatus_information")){
02781                         temp_host->retain_nonstatus_information=(atoi(value)>0)?TRUE:FALSE;
02782                         temp_host->have_retain_nonstatus_information=TRUE;
02783                         }
02784                 else if(!strcmp(variable,"register"))
02785                         temp_host->register_object=(atoi(value)>0)?TRUE:FALSE;
02786                 else if(variable[0]=='_'){
02787 
02788                         /* get the variable name */
02789                         customvarname=(char *)strdup(variable+1);
02790 
02791                         /* make sure we have a variable name */
02792                         if(customvarname==NULL || !strcmp(customvarname,"")){
02793                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Null custom variable name.\n");
02794                                 my_free(customvarname);
02795                                 return ERROR;
02796                                 }
02797 
02798                         /* get the variable value */
02799                         customvarvalue=NULL;
02800                         if(strcmp(value,XODTEMPLATE_NULL))
02801                                 customvarvalue=(char *)strdup(value);
02802 
02803                         /* add the custom variable */
02804                         if(xodtemplate_add_custom_variable_to_host(temp_host,customvarname,customvarvalue)==NULL){
02805                                 my_free(customvarname);
02806                                 my_free(customvarvalue);
02807                                 return ERROR;
02808                                 }
02809 
02810                         /* free memory */
02811                         my_free(customvarname);
02812                         my_free(customvarvalue);
02813                         }
02814                 else{
02815                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid host object directive '%s'.\n",variable);
02816                         return ERROR;
02817                         }
02818 
02819                 break;
02820 
02821         case XODTEMPLATE_SERVICE:
02822 
02823                 temp_service=(xodtemplate_service *)xodtemplate_current_object;
02824 
02825                 if(!strcmp(variable,"use")){
02826                         if((temp_service->template=(char *)strdup(value))==NULL)
02827                                 result=ERROR;
02828                         }
02829                 else if(!strcmp(variable,"name")){
02830 
02831                         if((temp_service->name=(char *)strdup(value))==NULL)
02832                                 result=ERROR;
02833 
02834                         if(result==OK){
02835                                 /* add service to template skiplist for fast searches */
02836                                 result=skiplist_insert(xobject_template_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
02837                                 switch(result){
02838                                 case SKIPLIST_ERROR_DUPLICATE:
02839                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
02840                                         result=ERROR;
02841                                         break;
02842                                 case SKIPLIST_OK:
02843                                         result=OK;
02844                                         break;
02845                                 default:
02846                                         result=ERROR;
02847                                         break;
02848                                         }
02849                                 }
02850                         }
02851                 else if(!strcmp(variable,"host") || !strcmp(variable,"hosts") || !strcmp(variable,"host_name")){
02852                         if(strcmp(value,XODTEMPLATE_NULL)){
02853                                 if((temp_service->host_name=(char *)strdup(value))==NULL)
02854                                         result=ERROR;
02855                                 }
02856                         temp_service->have_host_name=TRUE;
02857 
02858                         /* NOTE: services are added to the skiplist in xodtemplate_duplicate_services(), except if daemon is using precached config */
02859                         if(result==OK && force_skiplists==TRUE  && temp_service->host_name!=NULL && temp_service->service_description!=NULL){
02860                                 /* add service to template skiplist for fast searches */
02861                                 result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
02862                                 switch(result){
02863                                 case SKIPLIST_ERROR_DUPLICATE:
02864                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
02865                                         result=ERROR;
02866                                         break;
02867                                 case SKIPLIST_OK:
02868                                         result=OK;
02869                                         break;
02870                                 default:
02871                                         result=ERROR;
02872                                         break;
02873                                         }
02874                                 }
02875                         }
02876                 else if(!strcmp(variable,"service_description") || !strcmp(variable,"description")){
02877                         if(strcmp(value,XODTEMPLATE_NULL)){
02878                                 if((temp_service->service_description=(char *)strdup(value))==NULL)
02879                                         result=ERROR;
02880                                 }
02881                         temp_service->have_service_description=TRUE;
02882 
02883                         /* NOTE: services are added to the skiplist in xodtemplate_duplicate_services(), except if daemon is using precached config */
02884                         if(result==OK && force_skiplists==TRUE  && temp_service->host_name!=NULL && temp_service->service_description!=NULL){
02885                                 /* add service to template skiplist for fast searches */
02886                                 result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
02887                                 switch(result){
02888                                 case SKIPLIST_ERROR_DUPLICATE:
02889                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
02890                                         result=ERROR;
02891                                         break;
02892                                 case SKIPLIST_OK:
02893                                         result=OK;
02894                                         break;
02895                                 default:
02896                                         result=ERROR;
02897                                         break;
02898                                         }
02899                                 }
02900                         }
02901                 else if(!strcmp(variable,"display_name")){
02902                         if(strcmp(value,XODTEMPLATE_NULL)){
02903                                 if((temp_service->display_name=(char *)strdup(value))==NULL)
02904                                         result=ERROR;
02905                                 }
02906                         temp_service->have_display_name=TRUE;
02907                         }
02908                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
02909                         if(strcmp(value,XODTEMPLATE_NULL)){
02910                                 if((temp_service->hostgroup_name=(char *)strdup(value))==NULL)
02911                                         result=ERROR;
02912                                 }
02913                         temp_service->have_hostgroup_name=TRUE;
02914                         }
02915                 else if(!strcmp(variable,"service_groups") || !strcmp(variable,"servicegroups")){
02916                         if(strcmp(value,XODTEMPLATE_NULL)){
02917                                 if((temp_service->service_groups=(char *)strdup(value))==NULL)
02918                                         result=ERROR;
02919                                 }
02920                         temp_service->have_service_groups=TRUE;
02921                         }
02922                 else if(!strcmp(variable,"check_command")){
02923                         if(strcmp(value,XODTEMPLATE_NULL)){
02924                                 if(value[0] == '!') {
02925                                         temp_service->have_important_check_command=TRUE;
02926                                         temp_ptr=value+1;
02927                                         }
02928                                 else
02929                                         temp_ptr=value;
02930                                 if((temp_service->check_command=(char *)strdup(temp_ptr))==NULL)
02931                                         result=ERROR;
02932                                 }
02933                         temp_service->have_check_command=TRUE;
02934                         }
02935                 else if(!strcmp(variable,"check_period")){
02936                         if(strcmp(value,XODTEMPLATE_NULL)){
02937                                 if((temp_service->check_period=(char *)strdup(value))==NULL)
02938                                         result=ERROR;
02939                                 }
02940                         temp_service->have_check_period=TRUE;
02941                         }
02942                 else if(!strcmp(variable,"event_handler")){
02943                         if(strcmp(value,XODTEMPLATE_NULL)){
02944                                 if((temp_service->event_handler=(char *)strdup(value))==NULL)
02945                                         result=ERROR;
02946                                 }
02947                         temp_service->have_event_handler=TRUE;
02948                         }
02949                 else if(!strcmp(variable,"notification_period")){
02950                         if(strcmp(value,XODTEMPLATE_NULL)){
02951                                 if((temp_service->notification_period=(char *)strdup(value))==NULL)
02952                                         result=ERROR;
02953                                 }
02954                         temp_service->have_notification_period=TRUE;
02955                         }
02956                 else if(!strcmp(variable,"contact_groups")){
02957                         if(strcmp(value,XODTEMPLATE_NULL)){
02958                                 if((temp_service->contact_groups=(char *)strdup(value))==NULL)
02959                                         result=ERROR;
02960                                 }
02961                         temp_service->have_contact_groups=TRUE;
02962                         }
02963                 else if(!strcmp(variable,"contacts")){
02964                         if(strcmp(value,XODTEMPLATE_NULL)){
02965                                 if((temp_service->contacts=(char *)strdup(value))==NULL)
02966                                         result=ERROR;
02967                                 }
02968                         temp_service->have_contacts=TRUE;
02969                         }
02970                 else if(!strcmp(variable,"failure_prediction_options")){
02971                         if(strcmp(value,XODTEMPLATE_NULL)){
02972                                 if((temp_service->failure_prediction_options=(char *)strdup(value))==NULL)
02973                                         result=ERROR;
02974                                 }
02975                         temp_service->have_failure_prediction_options=TRUE;
02976                         }
02977                 else if(!strcmp(variable,"notes")){
02978                         if(strcmp(value,XODTEMPLATE_NULL)){
02979                                 if((temp_service->notes=(char *)strdup(value))==NULL)
02980                                         result=ERROR;
02981                                 }
02982                         temp_service->have_notes=TRUE;
02983                         }
02984                 else if(!strcmp(variable,"notes_url")){
02985                         if(strcmp(value,XODTEMPLATE_NULL)){
02986                                 if((temp_service->notes_url=(char *)strdup(value))==NULL)
02987                                         result=ERROR;
02988                                 }
02989                         temp_service->have_notes_url=TRUE;
02990                         }
02991                 else if(!strcmp(variable,"action_url")){
02992                         if(strcmp(value,XODTEMPLATE_NULL)){
02993                                 if((temp_service->action_url=(char *)strdup(value))==NULL)
02994                                         result=ERROR;
02995                                 }
02996                         temp_service->have_action_url=TRUE;
02997                         }
02998                 else if(!strcmp(variable,"icon_image")){
02999                         if(strcmp(value,XODTEMPLATE_NULL)){
03000                                 if((temp_service->icon_image=(char *)strdup(value))==NULL)
03001                                         result=ERROR;
03002                                 }
03003                         temp_service->have_icon_image=TRUE;
03004                         }
03005                 else if(!strcmp(variable,"icon_image_alt")){
03006                         if(strcmp(value,XODTEMPLATE_NULL)){
03007                                 if((temp_service->icon_image_alt=(char *)strdup(value))==NULL)
03008                                         result=ERROR;
03009                                 }
03010                         temp_service->have_icon_image_alt=TRUE;
03011                         }
03012                 else if(!strcmp(variable,"initial_state")){
03013                         if(!strcmp(value,"o") || !strcmp(value,"ok"))
03014                                 temp_service->initial_state=STATE_OK;
03015                         else if(!strcmp(value,"w") || !strcmp(value,"warning"))
03016                                 temp_service->initial_state=STATE_WARNING;
03017                         else if(!strcmp(value,"u") || !strcmp(value,"unknown"))
03018                                 temp_service->initial_state=STATE_UNKNOWN;
03019                         else if(!strcmp(value,"c") || !strcmp(value,"critical"))
03020                                 temp_service->initial_state=STATE_CRITICAL;
03021                         else{
03022                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid initial state '%s' in service definition.\n",value);
03023                                 result=ERROR;
03024                                 }
03025                         temp_service->have_initial_state=TRUE;
03026                         }
03027                 else if(!strcmp(variable,"max_check_attempts")){
03028                         temp_service->max_check_attempts=atoi(value);
03029                         temp_service->have_max_check_attempts=TRUE;
03030                         }
03031                 else if(!strcmp(variable,"check_interval") || !strcmp(variable,"normal_check_interval")){
03032                         temp_service->check_interval=strtod(value,NULL);
03033                         temp_service->have_check_interval=TRUE;
03034                         }
03035                 else if(!strcmp(variable,"retry_interval") || !strcmp(variable,"retry_check_interval")){
03036                         temp_service->retry_interval=strtod(value,NULL);
03037                         temp_service->have_retry_interval=TRUE;
03038                         }
03039                 else if(!strcmp(variable,"active_checks_enabled")){
03040                         temp_service->active_checks_enabled=(atoi(value)>0)?TRUE:FALSE;
03041                         temp_service->have_active_checks_enabled=TRUE;
03042                         }
03043                 else if(!strcmp(variable,"passive_checks_enabled")){
03044                         temp_service->passive_checks_enabled=(atoi(value)>0)?TRUE:FALSE;
03045                         temp_service->have_passive_checks_enabled=TRUE;
03046                         }
03047                 else if(!strcmp(variable,"parallelize_check")){
03048                         temp_service->parallelize_check=atoi(value);
03049                         temp_service->have_parallelize_check=TRUE;
03050                         }
03051                 else if(!strcmp(variable,"is_volatile")){
03052                         temp_service->is_volatile=(atoi(value)>0)?((atoi(value)==2)?VOLATILE_WITH_RENOTIFICATION_INTERVAL:TRUE):FALSE;
03053                         temp_service->have_is_volatile=TRUE;
03054                         }
03055                 else if(!strcmp(variable,"obsess_over_service")){
03056                         temp_service->obsess_over_service=(atoi(value)>0)?TRUE:FALSE;
03057                         temp_service->have_obsess_over_service=TRUE;
03058                         }
03059                 else if(!strcmp(variable,"event_handler_enabled")){
03060                         temp_service->event_handler_enabled=(atoi(value)>0)?TRUE:FALSE;
03061                         temp_service->have_event_handler_enabled=TRUE;
03062                         }
03063                 else if(!strcmp(variable,"check_freshness")){
03064                         temp_service->check_freshness=(atoi(value)>0)?TRUE:FALSE;
03065                         temp_service->have_check_freshness=TRUE;
03066                         }
03067                 else if(!strcmp(variable,"freshness_threshold")){
03068                         temp_service->freshness_threshold=atoi(value);
03069                         temp_service->have_freshness_threshold=TRUE;
03070                         }
03071                 else if(!strcmp(variable,"low_flap_threshold")){
03072                         temp_service->low_flap_threshold=strtod(value,NULL);
03073                         temp_service->have_low_flap_threshold=TRUE;
03074                         }
03075                 else if(!strcmp(variable,"high_flap_threshold")){
03076                         temp_service->high_flap_threshold=strtod(value,NULL);
03077                         temp_service->have_high_flap_threshold=TRUE;
03078                         }
03079                 else if(!strcmp(variable,"flap_detection_enabled")){
03080                         temp_service->flap_detection_enabled=(atoi(value)>0)?TRUE:FALSE;
03081                         temp_service->have_flap_detection_enabled=TRUE;
03082                         }       
03083                 else if(!strcmp(variable,"flap_detection_options")){
03084 
03085                         /* user is specifying something, so discard defaults... */
03086                         temp_service->flap_detection_on_ok=FALSE;
03087                         temp_service->flap_detection_on_warning=FALSE;
03088                         temp_service->flap_detection_on_unknown=FALSE;
03089                         temp_service->flap_detection_on_critical=FALSE;
03090 
03091                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03092                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"ok"))
03093                                         temp_service->flap_detection_on_ok=TRUE;
03094                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
03095                                         temp_service->flap_detection_on_warning=TRUE;
03096                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
03097                                         temp_service->flap_detection_on_unknown=TRUE;
03098                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
03099                                         temp_service->flap_detection_on_critical=TRUE;
03100                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03101                                         temp_service->flap_detection_on_ok=FALSE;
03102                                         temp_service->flap_detection_on_warning=FALSE;
03103                                         temp_service->flap_detection_on_unknown=FALSE;
03104                                         temp_service->flap_detection_on_critical=FALSE;
03105                                         }
03106                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03107                                         temp_service->flap_detection_on_ok=TRUE;
03108                                         temp_service->flap_detection_on_warning=TRUE;
03109                                         temp_service->flap_detection_on_unknown=TRUE;
03110                                         temp_service->flap_detection_on_critical=TRUE;
03111                                         }
03112                                 else{
03113                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid flap detection option '%s' in service definition.\n",temp_ptr);
03114                                         return ERROR;
03115                                         }
03116                                 }
03117                         temp_service->have_flap_detection_options=TRUE;
03118                         }
03119                 else if(!strcmp(variable,"notification_options")){
03120                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03121                                 if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
03122                                         temp_service->notify_on_unknown=TRUE;
03123                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
03124                                         temp_service->notify_on_warning=TRUE;
03125                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
03126                                         temp_service->notify_on_critical=TRUE;
03127                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
03128                                         temp_service->notify_on_recovery=TRUE;
03129                                 else if(!strcmp(temp_ptr,"f") || !strcmp(temp_ptr,"flapping"))
03130                                         temp_service->notify_on_flapping=TRUE;
03131                                 else if(!strcmp(temp_ptr,"s") || !strcmp(temp_ptr,"downtime"))
03132                                         temp_service->notify_on_downtime=TRUE;
03133                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03134                                         temp_service->notify_on_unknown=FALSE;
03135                                         temp_service->notify_on_warning=FALSE;
03136                                         temp_service->notify_on_critical=FALSE;
03137                                         temp_service->notify_on_recovery=FALSE;
03138                                         temp_service->notify_on_flapping=FALSE;
03139                                         temp_service->notify_on_downtime=FALSE;
03140                                         }
03141                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03142                                         temp_service->notify_on_unknown=TRUE;
03143                                         temp_service->notify_on_warning=TRUE;
03144                                         temp_service->notify_on_critical=TRUE;
03145                                         temp_service->notify_on_recovery=TRUE;
03146                                         temp_service->notify_on_flapping=TRUE;
03147                                         temp_service->notify_on_downtime=TRUE;
03148                                         }
03149                                 else{
03150                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification option '%s' in service definition.\n",temp_ptr);
03151                                         return ERROR;
03152                                         }
03153                                 }
03154                         temp_service->have_notification_options=TRUE;
03155                         }
03156                 else if(!strcmp(variable,"notifications_enabled")){
03157                         temp_service->notifications_enabled=(atoi(value)>0)?TRUE:FALSE;
03158                         temp_service->have_notifications_enabled=TRUE;
03159                         }
03160                 else if(!strcmp(variable,"notification_interval")){
03161                         temp_service->notification_interval=strtod(value,NULL);
03162                         temp_service->have_notification_interval=TRUE;
03163                         }
03164                 else if(!strcmp(variable,"first_notification_delay")){
03165                         temp_service->first_notification_delay=strtod(value,NULL);
03166                         temp_service->have_first_notification_delay=TRUE;
03167                         }
03168                 else if(!strcmp(variable,"stalking_options")){
03169                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03170                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"ok"))
03171                                         temp_service->stalk_on_ok=TRUE;
03172                                 else if(!strcmp(temp_ptr,"w") || !strcmp(temp_ptr,"warning"))
03173                                         temp_service->stalk_on_warning=TRUE;
03174                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unknown"))
03175                                         temp_service->stalk_on_unknown=TRUE;
03176                                 else if(!strcmp(temp_ptr,"c") || !strcmp(temp_ptr,"critical"))
03177                                         temp_service->stalk_on_critical=TRUE;
03178                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03179                                         temp_service->stalk_on_ok=FALSE;
03180                                         temp_service->stalk_on_warning=FALSE;
03181                                         temp_service->stalk_on_unknown=FALSE;
03182                                         temp_service->stalk_on_critical=FALSE;
03183                                         }
03184                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03185                                         temp_service->stalk_on_ok=TRUE;
03186                                         temp_service->stalk_on_warning=TRUE;
03187                                         temp_service->stalk_on_unknown=TRUE;
03188                                         temp_service->stalk_on_critical=TRUE;
03189                                         }
03190                                 else{
03191                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid stalking option '%s' in service definition.\n",temp_ptr);
03192                                         return ERROR;
03193                                         }
03194                                 }
03195                         temp_service->have_stalking_options=TRUE;
03196                         }
03197                 else if(!strcmp(variable,"process_perf_data")){
03198                         temp_service->process_perf_data=(atoi(value)>0)?TRUE:FALSE;
03199                         temp_service->have_process_perf_data=TRUE;
03200                         }
03201                 else if(!strcmp(variable,"failure_prediction_enabled")){
03202                         temp_service->failure_prediction_enabled=(atoi(value)>0)?TRUE:FALSE;
03203                         temp_service->have_failure_prediction_enabled=TRUE;
03204                         }
03205                 else if(!strcmp(variable,"retain_status_information")){
03206                         temp_service->retain_status_information=(atoi(value)>0)?TRUE:FALSE;
03207                         temp_service->have_retain_status_information=TRUE;
03208                         }
03209                 else if(!strcmp(variable,"retain_nonstatus_information")){
03210                         temp_service->retain_nonstatus_information=(atoi(value)>0)?TRUE:FALSE;
03211                         temp_service->have_retain_nonstatus_information=TRUE;
03212                         }
03213                 else if(!strcmp(variable,"register"))
03214                         temp_service->register_object=(atoi(value)>0)?TRUE:FALSE;
03215                 else if(variable[0]=='_'){
03216 
03217                         /* get the variable name */
03218                         customvarname=(char *)strdup(variable+1);
03219 
03220                         /* make sure we have a variable name */
03221                         if(customvarname==NULL || !strcmp(customvarname,"")){
03222                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Null custom variable name.\n");
03223                                 my_free(customvarname);
03224                                 return ERROR;
03225                                 }
03226 
03227                         /* get the variable value */
03228                         if(strcmp(value,XODTEMPLATE_NULL))
03229                                 customvarvalue=(char *)strdup(value);
03230                         else
03231                                 customvarvalue=NULL;
03232 
03233                         /* add the custom variable */
03234                         if(xodtemplate_add_custom_variable_to_service(temp_service,customvarname,customvarvalue)==NULL){
03235                                 my_free(customvarname);
03236                                 my_free(customvarvalue);
03237                                 return ERROR;
03238                                 }
03239 
03240                         /* free memory */
03241                         my_free(customvarname);
03242                         my_free(customvarvalue);
03243                         }
03244                 else{
03245                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid service object directive '%s'.\n",variable);
03246                         return ERROR;
03247                         }
03248 
03249                 break;
03250 
03251         case XODTEMPLATE_HOSTDEPENDENCY:
03252 
03253                 temp_hostdependency=(xodtemplate_hostdependency *)xodtemplate_current_object;
03254 
03255                 if(!strcmp(variable,"use")){
03256                         if((temp_hostdependency->template=(char *)strdup(value))==NULL)
03257                                 result=ERROR;
03258                         }
03259                 else if(!strcmp(variable,"name")){
03260 
03261                         if((temp_hostdependency->name=(char *)strdup(value))==NULL)
03262                                 result=ERROR;
03263 
03264                         if(result==OK){
03265                                 /* add dependency to template skiplist for fast searches */
03266                                 result=skiplist_insert(xobject_template_skiplists[X_HOSTDEPENDENCY_SKIPLIST],(void *)temp_hostdependency);
03267                                 switch(result){
03268                                 case SKIPLIST_ERROR_DUPLICATE:
03269                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for host dependency '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_hostdependency->_config_file),temp_hostdependency->_start_line);
03270                                         result=ERROR;
03271                                         break;
03272                                 case SKIPLIST_OK:
03273                                         result=OK;
03274                                         break;
03275                                 default:
03276                                         result=ERROR;
03277                                         break;
03278                                         }
03279                                 }
03280                         }
03281                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
03282                         if(strcmp(value,XODTEMPLATE_NULL)){
03283                                 if((temp_hostdependency->hostgroup_name=(char *)strdup(value))==NULL)
03284                                         result=ERROR;
03285                                 }
03286                         temp_hostdependency->have_hostgroup_name=TRUE;
03287                         }
03288                 else if(!strcmp(variable,"host") || !strcmp(variable,"host_name") || !strcmp(variable,"master_host") || !strcmp(variable,"master_host_name")){
03289                         if(strcmp(value,XODTEMPLATE_NULL)){
03290                                 if((temp_hostdependency->host_name=(char *)strdup(value))==NULL)
03291                                         result=ERROR;
03292                                 }
03293                         temp_hostdependency->have_host_name=TRUE;
03294                         }
03295                 else if(!strcmp(variable,"dependent_hostgroup") || !strcmp(variable,"dependent_hostgroups") || !strcmp(variable,"dependent_hostgroup_name")){
03296                         if(strcmp(value,XODTEMPLATE_NULL)){
03297                                 if((temp_hostdependency->dependent_hostgroup_name=(char *)strdup(value))==NULL)
03298                                         result=ERROR;
03299                                 }
03300                         temp_hostdependency->have_dependent_hostgroup_name=TRUE;
03301                         }
03302                 else if(!strcmp(variable,"dependent_host") || !strcmp(variable,"dependent_host_name")){
03303                         if(strcmp(value,XODTEMPLATE_NULL)){
03304                                 if((temp_hostdependency->dependent_host_name=(char *)strdup(value))==NULL)
03305                                         result=ERROR;
03306                                 }
03307                         temp_hostdependency->have_dependent_host_name=TRUE;
03308 
03309                         /* NOTE: dependencies are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
03310                         if(result==OK && force_skiplists==TRUE){
03311                                 /* add hostdependency to template skiplist for fast searches */
03312                                 result=skiplist_insert(xobject_skiplists[X_HOSTDEPENDENCY_SKIPLIST],(void *)temp_hostdependency);
03313                                 switch(result){
03314                                 case SKIPLIST_OK:
03315                                         result=OK;
03316                                         break;
03317                                 default:
03318                                         result=ERROR;
03319                                         break;
03320                                         }
03321                                 }
03322                         }
03323                 else if(!strcmp(variable,"dependency_period")){
03324                         if(strcmp(value,XODTEMPLATE_NULL)){
03325                                 if((temp_hostdependency->dependency_period=(char *)strdup(value))==NULL)
03326                                         result=ERROR;
03327                                 }
03328                         temp_hostdependency->have_dependency_period=TRUE;
03329                         }
03330                 else if(!strcmp(variable,"inherits_parent")){
03331                         temp_hostdependency->inherits_parent=(atoi(value)>0)?TRUE:FALSE;
03332                         temp_hostdependency->have_inherits_parent=TRUE;
03333                         }
03334                 else if(!strcmp(variable,"notification_failure_options") || !strcmp(variable,"notification_failure_criteria")){
03335                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03336                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"up"))
03337                                         temp_hostdependency->fail_notify_on_up=TRUE;
03338                                 else if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
03339                                         temp_hostdependency->fail_notify_on_down=TRUE;
03340                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
03341                                         temp_hostdependency->fail_notify_on_unreachable=TRUE;
03342                                 else if(!strcmp(temp_ptr,"p") || !strcmp(temp_ptr,"pending"))
03343                                         temp_hostdependency->fail_notify_on_pending=TRUE;
03344                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03345                                         temp_hostdependency->fail_notify_on_up=FALSE;
03346                                         temp_hostdependency->fail_notify_on_down=FALSE;
03347                                         temp_hostdependency->fail_notify_on_unreachable=FALSE;
03348                                         temp_hostdependency->fail_notify_on_pending=FALSE;
03349                                         }
03350                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03351                                         temp_hostdependency->fail_notify_on_up=TRUE;
03352                                         temp_hostdependency->fail_notify_on_down=TRUE;
03353                                         temp_hostdependency->fail_notify_on_unreachable=TRUE;
03354                                         temp_hostdependency->fail_notify_on_pending=TRUE;
03355                                         }
03356                                 else{
03357                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification dependency option '%s' in hostdependency definition.\n",temp_ptr);
03358                                         return ERROR;
03359                                         }
03360                                 }
03361                         temp_hostdependency->have_notification_dependency_options=TRUE;
03362                         }
03363                 else if(!strcmp(variable,"execution_failure_options") || !strcmp(variable,"execution_failure_criteria")){
03364                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03365                                 if(!strcmp(temp_ptr,"o") || !strcmp(temp_ptr,"up"))
03366                                         temp_hostdependency->fail_execute_on_up=TRUE;
03367                                 else if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
03368                                         temp_hostdependency->fail_execute_on_down=TRUE;
03369                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
03370                                         temp_hostdependency->fail_execute_on_unreachable=TRUE;
03371                                 else if(!strcmp(temp_ptr,"p") || !strcmp(temp_ptr,"pending"))
03372                                         temp_hostdependency->fail_execute_on_pending=TRUE;
03373                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03374                                         temp_hostdependency->fail_execute_on_up=FALSE;
03375                                         temp_hostdependency->fail_execute_on_down=FALSE;
03376                                         temp_hostdependency->fail_execute_on_unreachable=FALSE;
03377                                         temp_hostdependency->fail_execute_on_pending=FALSE;
03378                                         }
03379                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03380                                         temp_hostdependency->fail_execute_on_up=TRUE;
03381                                         temp_hostdependency->fail_execute_on_down=TRUE;
03382                                         temp_hostdependency->fail_execute_on_unreachable=TRUE;
03383                                         temp_hostdependency->fail_execute_on_pending=TRUE;
03384                                         }
03385                                 else{
03386                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid execution dependency option '%s' in hostdependency definition.\n",temp_ptr);
03387                                         return ERROR;
03388                                         }
03389                                 }
03390                         temp_hostdependency->have_execution_dependency_options=TRUE;
03391                         }
03392                 else if(!strcmp(variable,"register"))
03393                         temp_hostdependency->register_object=(atoi(value)>0)?TRUE:FALSE;
03394                 else{
03395                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid hostdependency object directive '%s'.\n",variable);
03396                         return ERROR;
03397                         }
03398 
03399                 break;
03400 
03401         
03402         case XODTEMPLATE_HOSTESCALATION:
03403 
03404                 temp_hostescalation=(xodtemplate_hostescalation *)xodtemplate_current_object;
03405 
03406                 if(!strcmp(variable,"use")){
03407                         if((temp_hostescalation->template=(char *)strdup(value))==NULL)
03408                                 result=ERROR;
03409                         }
03410                 else if(!strcmp(variable,"name")){
03411 
03412                         if((temp_hostescalation->name=(char *)strdup(value))==NULL)
03413                                 result=ERROR;
03414 
03415                         if(result==OK){
03416                                 /* add escalation to template skiplist for fast searches */
03417                                 result=skiplist_insert(xobject_template_skiplists[X_HOSTESCALATION_SKIPLIST],(void *)temp_hostescalation);
03418                                 switch(result){
03419                                 case SKIPLIST_ERROR_DUPLICATE:
03420                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for host escalation '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_hostescalation->_config_file),temp_hostescalation->_start_line);
03421                                         result=ERROR;
03422                                         break;
03423                                 case SKIPLIST_OK:
03424                                         result=OK;
03425                                         break;
03426                                 default:
03427                                         result=ERROR;
03428                                         break;
03429                                         }
03430                                 }
03431                         }
03432                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
03433                         if(strcmp(value,XODTEMPLATE_NULL)){
03434                                 if((temp_hostescalation->hostgroup_name=(char *)strdup(value))==NULL)
03435                                         result=ERROR;
03436                                 }
03437                         temp_hostescalation->have_hostgroup_name=TRUE;
03438                         }
03439                 else if(!strcmp(variable,"host") || !strcmp(variable,"host_name")){
03440                         if(strcmp(value,XODTEMPLATE_NULL)){
03441                                 if((temp_hostescalation->host_name=(char *)strdup(value))==NULL)
03442                                         result=ERROR;
03443                                 }
03444                         temp_hostescalation->have_host_name=TRUE;
03445 
03446                         /* NOTE: escalations are added to the skiplist in xodtemplate_duplicate_objects(), except if daemon is using precached config */
03447                         if(result==OK && force_skiplists==TRUE){
03448                                 /* add hostescalation to template skiplist for fast searches */
03449                                 result=skiplist_insert(xobject_skiplists[X_HOSTESCALATION_SKIPLIST],(void *)temp_hostescalation);
03450                                 switch(result){
03451                                 case SKIPLIST_OK:
03452                                         result=OK;
03453                                         break;
03454                                 default:
03455                                         result=ERROR;
03456                                         break;
03457                                         }
03458                                 }
03459                         }
03460                 else if(!strcmp(variable,"contact_groups")){
03461                         if(strcmp(value,XODTEMPLATE_NULL)){
03462                                 if((temp_hostescalation->contact_groups=(char *)strdup(value))==NULL)
03463                                         result=ERROR;
03464                                 }
03465                         temp_hostescalation->have_contact_groups=TRUE;
03466                         }
03467                 else if(!strcmp(variable,"contacts")){
03468                         if(strcmp(value,XODTEMPLATE_NULL)){
03469                                 if((temp_hostescalation->contacts=(char *)strdup(value))==NULL)
03470                                         result=ERROR;
03471                                 }
03472                         temp_hostescalation->have_contacts=TRUE;
03473                         }
03474                 else if(!strcmp(variable,"escalation_period")){
03475                         if(strcmp(value,XODTEMPLATE_NULL)){
03476                                 if((temp_hostescalation->escalation_period=(char *)strdup(value))==NULL)
03477                                         result=ERROR;
03478                                 }
03479                         temp_hostescalation->have_escalation_period=TRUE;
03480                         }
03481                 else if(!strcmp(variable,"first_notification")){
03482                         temp_hostescalation->first_notification=atoi(value);
03483                         temp_hostescalation->have_first_notification=TRUE;
03484                         }
03485                 else if(!strcmp(variable,"last_notification")){
03486                         temp_hostescalation->last_notification=atoi(value);
03487                         temp_hostescalation->have_last_notification=TRUE;
03488                         }
03489 #ifdef USE_ST_BASED_ESCAL_RANGES
03490                 else if(!strcmp(variable,"first_down_notification")){
03491                         temp_hostescalation->first_down_notification=atoi(value);
03492                         temp_hostescalation->have_first_down_notification=TRUE;
03493                         }
03494                 else if(!strcmp(variable,"last_down_notification")){
03495                         temp_hostescalation->last_down_notification=atoi(value);
03496                         temp_hostescalation->have_last_down_notification=TRUE;
03497                         }
03498                 else if(!strcmp(variable,"first_unreachable_notification")){
03499                         temp_hostescalation->first_unreachable_notification=atoi(value);
03500                         temp_hostescalation->have_first_unreachable_notification=TRUE;
03501                         }
03502                 else if(!strcmp(variable,"last_unreachable_notification")){
03503                         temp_hostescalation->last_unreachable_notification=atoi(value);
03504                         temp_hostescalation->have_last_unreachable_notification=TRUE;
03505                         }
03506 #endif
03507                 else if(!strcmp(variable,"notification_interval")){
03508                         temp_hostescalation->notification_interval=strtod(value,NULL);
03509                         temp_hostescalation->have_notification_interval=TRUE;
03510                         }
03511                 else if(!strcmp(variable,"escalation_options")){
03512                         for(temp_ptr=strtok(value,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
03513                                 if(!strcmp(temp_ptr,"d") || !strcmp(temp_ptr,"down"))
03514                                         temp_hostescalation->escalate_on_down=TRUE;
03515                                 else if(!strcmp(temp_ptr,"u") || !strcmp(temp_ptr,"unreachable"))
03516                                         temp_hostescalation->escalate_on_unreachable=TRUE;
03517                                 else if(!strcmp(temp_ptr,"r") || !strcmp(temp_ptr,"recovery"))
03518                                         temp_hostescalation->escalate_on_recovery=TRUE;
03519                                 else if(!strcmp(temp_ptr,"n") || !strcmp(temp_ptr,"none")){
03520                                         temp_hostescalation->escalate_on_down=FALSE;
03521                                         temp_hostescalation->escalate_on_unreachable=FALSE;
03522                                         temp_hostescalation->escalate_on_recovery=FALSE;
03523                                         }
03524                                 else if(!strcmp(temp_ptr,"a") || !strcmp(temp_ptr,"all")){
03525                                         temp_hostescalation->escalate_on_down=TRUE;
03526                                         temp_hostescalation->escalate_on_unreachable=TRUE;
03527                                         temp_hostescalation->escalate_on_recovery=TRUE;
03528                                         }
03529                                 else{
03530                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid escalation option '%s' in hostescalation definition.\n",temp_ptr);
03531                                         return ERROR;
03532                                         }
03533                                 }
03534                         temp_hostescalation->have_escalation_options=TRUE;
03535                         }
03536                 else if(!strcmp(variable,"escalation_condition")){
03537                         xodtemplate_escalation_condition *temp_condition=(xodtemplate_escalation_condition *)malloc(sizeof(xodtemplate_escalation_condition));
03538                         if (xodtemplate_create_escalation_condition(value, temp_condition)==OK) {
03539                                 temp_hostescalation->condition=temp_condition;
03540                         }
03541                         else {
03542                                 my_free(temp_condition);
03543                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not create escalation condition for hostescalation .\n");
03544                                 return ERROR;
03545                         }
03546                 }
03547                 else if(!strcmp(variable,"register"))
03548                         temp_hostescalation->register_object=(atoi(value)>0)?TRUE:FALSE;
03549                 else{
03550                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid hostescalation object directive '%s'.\n",variable);
03551                         return ERROR;
03552                         }
03553 
03554                 break;
03555         
03556         case XODTEMPLATE_HOSTEXTINFO:
03557                 
03558                 temp_hostextinfo=xodtemplate_hostextinfo_list;
03559 
03560                 if(!strcmp(variable,"use")){
03561                         if((temp_hostextinfo->template=(char *)strdup(value))==NULL)
03562                                 result=ERROR;
03563                         }
03564                 else if(!strcmp(variable,"name")){
03565 
03566                         if((temp_hostextinfo->name=(char *)strdup(value))==NULL)
03567                                 result=ERROR;
03568 
03569                         if(result==OK){
03570                                 /* add to template skiplist for fast searches */
03571                                 result=skiplist_insert(xobject_template_skiplists[X_HOSTEXTINFO_SKIPLIST],(void *)temp_hostextinfo);
03572                                 switch(result){
03573                                 case SKIPLIST_ERROR_DUPLICATE:
03574                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for extended host info '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_hostextinfo->_config_file),temp_hostextinfo->_start_line);
03575                                         result=ERROR;
03576                                         break;
03577                                 case SKIPLIST_OK:
03578                                         result=OK;
03579                                         break;
03580                                 default:
03581                                         result=ERROR;
03582                                         break;
03583                                         }
03584                                 }
03585                         }
03586                 else if(!strcmp(variable,"host_name")){
03587                         if(strcmp(value,XODTEMPLATE_NULL)){
03588                                 if((temp_hostextinfo->host_name=(char *)strdup(value))==NULL)
03589                                         result=ERROR;
03590                                 }
03591                         temp_hostextinfo->have_host_name=TRUE;
03592                         }
03593                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroup_name")){
03594                         if(strcmp(value,XODTEMPLATE_NULL)){
03595                                 if((temp_hostextinfo->hostgroup_name=(char *)strdup(value))==NULL)
03596                                         result=ERROR;
03597                                 }
03598                         temp_hostextinfo->have_hostgroup_name=TRUE;
03599                         }
03600                 else if(!strcmp(variable,"notes")){
03601                         if(strcmp(value,XODTEMPLATE_NULL)){
03602                                 if((temp_hostextinfo->notes=(char *)strdup(value))==NULL)
03603                                         result=ERROR;
03604                                 }
03605                         temp_hostextinfo->have_notes=TRUE;
03606                         }
03607                 else if(!strcmp(variable,"notes_url")){
03608                         if(strcmp(value,XODTEMPLATE_NULL)){
03609                                 if((temp_hostextinfo->notes_url=(char *)strdup(value))==NULL)
03610                                         result=ERROR;
03611                                 }
03612                         temp_hostextinfo->have_notes_url=TRUE;
03613                         }
03614                 else if(!strcmp(variable,"action_url")){
03615                         if(strcmp(value,XODTEMPLATE_NULL)){
03616                                 if((temp_hostextinfo->action_url=(char *)strdup(value))==NULL)
03617                                         result=ERROR;
03618                                 }
03619                         temp_hostextinfo->have_action_url=TRUE;
03620                         }
03621                 else if(!strcmp(variable,"icon_image")){
03622                         if(strcmp(value,XODTEMPLATE_NULL)){
03623                                 if((temp_hostextinfo->icon_image=(char *)strdup(value))==NULL)
03624                                         result=ERROR;
03625                                 }
03626                         temp_hostextinfo->have_icon_image=TRUE;
03627                         }
03628                 else if(!strcmp(variable,"icon_image_alt")){
03629                         if(strcmp(value,XODTEMPLATE_NULL)){
03630                                 if((temp_hostextinfo->icon_image_alt=(char *)strdup(value))==NULL)
03631                                         result=ERROR;
03632                                 }
03633                         temp_hostextinfo->have_icon_image_alt=TRUE;
03634                         }
03635                 else if(!strcmp(variable,"vrml_image")){
03636                         if(strcmp(value,XODTEMPLATE_NULL)){
03637                                 if((temp_hostextinfo->vrml_image=(char *)strdup(value))==NULL)
03638                                         result=ERROR;
03639                                 }
03640                         temp_hostextinfo->have_vrml_image=TRUE;
03641                         }
03642                 else if(!strcmp(variable,"gd2_image")|| !strcmp(variable,"statusmap_image")){
03643                         if(strcmp(value,XODTEMPLATE_NULL)){
03644                                 if((temp_hostextinfo->statusmap_image=(char *)strdup(value))==NULL)
03645                                         result=ERROR;
03646                                 }
03647                         temp_hostextinfo->have_statusmap_image=TRUE;
03648                         }
03649                 else if(!strcmp(variable,"2d_coords")){
03650                         temp_ptr=strtok(value,", ");
03651                         if(temp_ptr==NULL){
03652                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 2d_coords value '%s' in extended host info definition.\n",temp_ptr);
03653                                 return ERROR;
03654                                 }
03655                         temp_hostextinfo->x_2d=atoi(temp_ptr);
03656                         temp_ptr=strtok(NULL,", ");
03657                         if(temp_ptr==NULL){
03658                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 2d_coords value '%s' in extended host info definition.\n",temp_ptr);
03659                                 return ERROR;
03660                                 }
03661                         temp_hostextinfo->y_2d=atoi(temp_ptr);
03662                         temp_hostextinfo->have_2d_coords=TRUE;
03663                         }
03664                 else if(!strcmp(variable,"3d_coords")){
03665                         temp_ptr=strtok(value,", ");
03666                         if(temp_ptr==NULL){
03667                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in extended host info definition.\n",temp_ptr);
03668                                 return ERROR;
03669                                 }
03670                         temp_hostextinfo->x_3d=strtod(temp_ptr,NULL);
03671                         temp_ptr=strtok(NULL,", ");
03672                         if(temp_ptr==NULL){
03673                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in extended host info definition.\n",temp_ptr);
03674                                 return ERROR;
03675                                 }
03676                         temp_hostextinfo->y_3d=strtod(temp_ptr,NULL);
03677                         temp_ptr=strtok(NULL,", ");
03678                         if(temp_ptr==NULL){
03679                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid 3d_coords value '%s' in extended host info definition.\n",temp_ptr);
03680                                 return ERROR;
03681                                 }
03682                         temp_hostextinfo->z_3d=strtod(temp_ptr,NULL);
03683                         temp_hostextinfo->have_3d_coords=TRUE;
03684                         }
03685                 else if(!strcmp(variable,"register"))
03686                         temp_hostextinfo->register_object=(atoi(value)>0)?TRUE:FALSE;
03687                 else{
03688                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid hostextinfo object directive '%s'.\n",variable);
03689                         return ERROR;
03690                         }
03691 
03692                 break;
03693         
03694         case XODTEMPLATE_SERVICEEXTINFO:
03695                 
03696                 temp_serviceextinfo=xodtemplate_serviceextinfo_list;
03697 
03698                 if(!strcmp(variable,"use")){
03699                         if((temp_serviceextinfo->template=(char *)strdup(value))==NULL)
03700                                 result=ERROR;
03701                         }
03702                 else if(!strcmp(variable,"name")){
03703 
03704                         if((temp_serviceextinfo->name=(char *)strdup(value))==NULL)
03705                                 result=ERROR;
03706 
03707                         if(result==OK){
03708                                 /* add to template skiplist for fast searches */
03709                                 result=skiplist_insert(xobject_template_skiplists[X_SERVICEEXTINFO_SKIPLIST],(void *)temp_serviceextinfo);
03710                                 switch(result){
03711                                 case SKIPLIST_ERROR_DUPLICATE:
03712                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for extended service info '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_serviceextinfo->_config_file),temp_serviceextinfo->_start_line);
03713                                         result=ERROR;
03714                                         break;
03715                                 case SKIPLIST_OK:
03716                                         result=OK;
03717                                         break;
03718                                 default:
03719                                         result=ERROR;
03720                                         break;
03721                                         }
03722                                 }
03723                         }
03724                 else if(!strcmp(variable,"host_name")){
03725                         if(strcmp(value,XODTEMPLATE_NULL)){
03726                                 if((temp_serviceextinfo->host_name=(char *)strdup(value))==NULL)
03727                                         result=ERROR;
03728                                 }
03729                         temp_serviceextinfo->have_host_name=TRUE;
03730                         }
03731                 else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroup_name")){
03732                         if(strcmp(value,XODTEMPLATE_NULL)){
03733                                 if((temp_serviceextinfo->hostgroup_name=(char *)strdup(value))==NULL)
03734                                         result=ERROR;
03735                                 }
03736                         temp_serviceextinfo->have_hostgroup_name=TRUE;
03737                         }
03738                 else if(!strcmp(variable,"service_description")){
03739                         if(strcmp(value,XODTEMPLATE_NULL)){
03740                                 if((temp_serviceextinfo->service_description=(char *)strdup(value))==NULL)
03741                                         result=ERROR;
03742                                 }
03743                         temp_serviceextinfo->have_service_description=TRUE;
03744                         }
03745                 else if(!strcmp(variable,"notes")){
03746                         if(strcmp(value,XODTEMPLATE_NULL)){
03747                                 if((temp_serviceextinfo->notes=(char *)strdup(value))==NULL)
03748                                         result=ERROR;
03749                                 }
03750                         temp_serviceextinfo->have_notes=TRUE;
03751                         }
03752                 else if(!strcmp(variable,"notes_url")){
03753                         if(strcmp(value,XODTEMPLATE_NULL)){
03754                                 if((temp_serviceextinfo->notes_url=(char *)strdup(value))==NULL)
03755                                         result=ERROR;
03756                                 }
03757                         temp_serviceextinfo->have_notes_url=TRUE;
03758                         }
03759                 else if(!strcmp(variable,"action_url")){
03760                         if(strcmp(value,XODTEMPLATE_NULL)){
03761                                 if((temp_serviceextinfo->action_url=(char *)strdup(value))==NULL)
03762                                         result=ERROR;
03763                                 }
03764                         temp_serviceextinfo->have_action_url=TRUE;
03765                         }
03766                 else if(!strcmp(variable,"icon_image")){
03767                         if(strcmp(value,XODTEMPLATE_NULL)){
03768                                 if((temp_serviceextinfo->icon_image=(char *)strdup(value))==NULL)
03769                                         result=ERROR;
03770                                 }
03771                         temp_serviceextinfo->have_icon_image=TRUE;
03772                         }
03773                 else if(!strcmp(variable,"icon_image_alt")){
03774                         if(strcmp(value,XODTEMPLATE_NULL)){
03775                                 if((temp_serviceextinfo->icon_image_alt=(char *)strdup(value))==NULL)
03776                                         result=ERROR;
03777                                 }
03778                         temp_serviceextinfo->have_icon_image_alt=TRUE;
03779                         }
03780                 else if(!strcmp(variable,"register"))
03781                         temp_serviceextinfo->register_object=(atoi(value)>0)?TRUE:FALSE;
03782                 else{
03783                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid serviceextinfo object directive '%s'.\n",variable);
03784                         return ERROR;
03785                         }
03786 
03787                 break;
03788 
03789 
03790         case XODTEMPLATE_MODULE:
03791 
03792                 temp_module=(xodtemplate_module *)xodtemplate_current_object;
03793 
03794                 
03795                 if(!strcmp(variable,"use")){
03796                         if((temp_command->template=(char *)strdup(value))==NULL)
03797                                 result=ERROR;
03798                         }
03799                 else if(!strcmp(variable,"name")){
03800 
03801                         if((temp_module->name=(char *)strdup(value))==NULL)
03802                                 result=ERROR;
03803 
03804                         if(result==OK){
03805                                 /* add module to template skiplist for fast searches */
03806                                 result=skiplist_insert(xobject_template_skiplists[X_MODULE_SKIPLIST],(void *)temp_module);
03807                                 switch(result){
03808                                 case SKIPLIST_ERROR_DUPLICATE:
03809                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for module '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_module->_config_file),temp_module->_start_line);
03810                                         result=ERROR;
03811                                         break;
03812                                 case SKIPLIST_OK:
03813                                         result=OK;
03814                                         break;
03815                                 default:
03816                                         result=ERROR;
03817                                         break;
03818                                         }
03819                                 }
03820                         }
03821                 else if(!strcmp(variable,"module_name")){
03822                         if((temp_module->module_name=(char *)strdup(value))==NULL)
03823                                 result=ERROR;
03824 
03825                         if(result==OK){
03826                                 /* add module to template skiplist for fast searches */
03827                                 result=skiplist_insert(xobject_skiplists[X_MODULE_SKIPLIST],(void *)temp_module);
03828                                 switch(result){
03829                                 case SKIPLIST_ERROR_DUPLICATE:
03830                                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for module '%s' (config file '%s', starting on line %d)\n",value,xodtemplate_config_file_name(temp_module->_config_file),temp_module->_start_line);
03831                                         result=ERROR;
03832                                         break;
03833                                 case SKIPLIST_OK:
03834                                         result=OK;
03835                                         break;
03836                                 default:
03837                                         result=ERROR;
03838                                         break;
03839                                         }
03840                                 }
03841                         }
03842                 else if(!strcmp(variable,"module_type")){
03843                         if((temp_module->module_type=(char *)strdup(value))==NULL)
03844                                 result=ERROR;
03845                         }
03846                 else if(!strcmp(variable,"path")){
03847                         if((temp_module->path=(char *)strdup(value))==NULL)
03848                                 result=ERROR;
03849                         }
03850                 else if(!strcmp(variable,"args")){
03851                         if((temp_module->args=(char *)strdup(value))==NULL)
03852                                 result=ERROR;
03853                         }
03854                 else if(!strcmp(variable,"register"))
03855                         temp_module->register_object=(atoi(value)>0)?TRUE:FALSE;
03856                 else{
03857                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid module object directive '%s'.\n",variable);
03858                         return ERROR;
03859                         }
03860 
03861                 break;
03862 
03863 
03864         default:
03865                 return ERROR;
03866                 break;
03867                 }
03868 
03869         /* free memory */
03870         my_free(variable);
03871         my_free(value);
03872 
03873         return result;
03874         }
03875 
03876 
03877 
03878 /* completes an object definition */
03879 int xodtemplate_end_object_definition(int options){
03880         int result=OK;
03881 
03882 
03883         xodtemplate_current_object=NULL;
03884         xodtemplate_current_object_type=XODTEMPLATE_NONE;
03885 
03886         return result;
03887         }
03888 
03889 
03890 
03891 /* adds a custom variable to a host */
03892 xodtemplate_customvariablesmember *xodtemplate_add_custom_variable_to_host(xodtemplate_host *hst, char *varname, char *varvalue){
03893 
03894         return xodtemplate_add_custom_variable_to_object(&hst->custom_variables,varname,varvalue);
03895         }
03896 
03897 
03898 
03899 /* adds a custom variable to a service */
03900 xodtemplate_customvariablesmember *xodtemplate_add_custom_variable_to_service(xodtemplate_service *svc, char *varname, char *varvalue){
03901 
03902         return xodtemplate_add_custom_variable_to_object(&svc->custom_variables,varname,varvalue);
03903         }
03904 
03905 
03906 
03907 /* adds a custom variable to a contact */
03908 xodtemplate_customvariablesmember *xodtemplate_add_custom_variable_to_contact(xodtemplate_contact *cntct, char *varname, char *varvalue){
03909 
03910         return xodtemplate_add_custom_variable_to_object(&cntct->custom_variables,varname,varvalue);
03911         }
03912 
03913 
03914 
03915 /* adds a custom variable to an object */
03916 xodtemplate_customvariablesmember *xodtemplate_add_custom_variable_to_object(xodtemplate_customvariablesmember **object_ptr, char *varname, char *varvalue){
03917         xodtemplate_customvariablesmember *new_customvariablesmember=NULL;
03918         register int x=0;
03919 
03920         /* make sure we have the data we need */
03921         if(object_ptr==NULL)
03922                 return NULL;
03923 
03924         if(varname==NULL || !strcmp(varname,""))
03925                 return NULL;
03926 
03927         /* allocate memory for a new member */
03928         if((new_customvariablesmember=malloc(sizeof(xodtemplate_customvariablesmember)))==NULL)
03929                 return NULL;
03930         if((new_customvariablesmember->variable_name=(char *)strdup(varname))==NULL){
03931                 my_free(new_customvariablesmember);
03932                 return NULL;
03933                 }
03934         if(varvalue){
03935                 if((new_customvariablesmember->variable_value=(char *)strdup(varvalue))==NULL){
03936                         my_free(new_customvariablesmember->variable_name);
03937                         my_free(new_customvariablesmember);
03938                         return NULL;
03939                         }
03940                 }
03941         else
03942                 new_customvariablesmember->variable_value=NULL;
03943 
03944         /* convert varname to all uppercase (saves CPU time during macro functions) */
03945         for(x=0;new_customvariablesmember->variable_name[x]!='\x0';x++)
03946                 new_customvariablesmember->variable_name[x]=toupper(new_customvariablesmember->variable_name[x]);
03947         
03948         /* add the new member to the head of the member list */
03949         new_customvariablesmember->next=*object_ptr;
03950         *object_ptr=new_customvariablesmember;
03951 
03952         return new_customvariablesmember;
03953         }
03954 
03955 
03956 
03957 /* parses a timeperod directive... :-) */
03958 int xodtemplate_parse_timeperiod_directive(xodtemplate_timeperiod *tperiod, char *var, char *val){
03959         char *input=NULL;
03960         char temp_buffer[5][MAX_INPUT_BUFFER]={"","","","",""};
03961         int items=0;
03962         int result=OK;
03963 
03964         int syear=0;
03965         int smon=0;
03966         int smday=0;
03967         int swday=0;
03968         int swday_offset=0;
03969         int eyear=0;
03970         int emon=0;
03971         int emday=0;
03972         int ewday=0;
03973         int ewday_offset=0;
03974         int skip_interval=0;
03975 
03976         /* make sure we've got the reqs */
03977         if(tperiod==NULL || var==NULL || val==NULL)
03978                 return ERROR;
03979 
03980         /* we'll need the full (unsplit) input later */
03981         if((input=(char *)malloc(strlen(var)+strlen(val)+2))==NULL)
03982                 return ERROR;
03983         strcpy(input,var);
03984         strcat(input," ");
03985         strcat(input,val);
03986 
03987         if(0)
03988                 return OK;
03989 
03990         /* calendar dates */
03991         else if((items=sscanf(input,"%4d-%2d-%2d - %4d-%2d-%2d / %d %[0-9:, -]",&syear,&smon,&smday,&eyear,&emon,&emday,&skip_interval,temp_buffer[0]))==8){
03992                 /* add timerange exception */
03993                 if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_CALENDAR_DATE,syear,smon-1,smday,0,0,eyear,emon-1,emday,0,0,skip_interval,temp_buffer[0])==NULL)
03994                         result=ERROR;
03995                 }
03996 
03997         else if((items=sscanf(input,"%4d-%2d-%2d / %d %[0-9:, -]",&syear,&smon,&smday,&skip_interval,temp_buffer[0]))==5){
03998                 eyear=syear;
03999                 emon=smon;
04000                 emday=smday;
04001                 /* add timerange exception */
04002                 if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_CALENDAR_DATE,syear,smon-1,smday,0,0,eyear,emon-1,emday,0,0,skip_interval,temp_buffer[0])==NULL)
04003                         result=ERROR;
04004                 }
04005 
04006         else if((items=sscanf(input,"%4d-%2d-%2d - %4d-%2d-%2d %[0-9:, -]",&syear,&smon,&smday,&eyear,&emon,&emday,temp_buffer[0]))==7){
04007                 /* add timerange exception */
04008                 if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_CALENDAR_DATE,syear,smon-1,smday,0,0,eyear,emon-1,emday,0,0,0,temp_buffer[0])==NULL)
04009                         result=ERROR;
04010                 }
04011 
04012         else if((items=sscanf(input,"%4d-%2d-%2d %[0-9:, -]",&syear,&smon,&smday,temp_buffer[0]))==4){
04013                 eyear=syear;
04014                 emon=smon;
04015                 emday=smday;
04016                 /* add timerange exception */
04017                 if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_CALENDAR_DATE,syear,smon-1,smday,0,0,eyear,emon-1,emday,0,0,0,temp_buffer[0])==NULL)
04018                         result=ERROR;
04019                 }
04020 
04021         /* other types... */
04022         else if((items=sscanf(input,"%[a-z] %d %[a-z] - %[a-z] %d %[a-z] / %d %[0-9:, -]",temp_buffer[0],&swday_offset,temp_buffer[1],temp_buffer[2],&ewday_offset,temp_buffer[3],&skip_interval,temp_buffer[4]))==8){
04023                 /* wednesday 1 january - thursday 2 july / 3 */
04024                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK&& (result=xodtemplate_get_month_from_string(temp_buffer[1],&smon))==OK && (result=xodtemplate_get_weekday_from_string(temp_buffer[2],&ewday))==OK&& (result=xodtemplate_get_month_from_string(temp_buffer[3],&emon))==OK){
04025                         /* add timeperiod exception */
04026                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_WEEK_DAY,0,smon,0,swday,swday_offset,0,emon,0,ewday,ewday_offset,skip_interval,temp_buffer[4])==NULL)
04027                                 result=ERROR;
04028                         }
04029                 }
04030 
04031         else if((items=sscanf(input,"%[a-z] %d - %[a-z] %d / %d %[0-9:, -]",temp_buffer[0],&smday,temp_buffer[1],&emday,&skip_interval,temp_buffer[2]))==6){
04032                 /* february 1 - march 15 / 3 */
04033                 /* monday 2 - thursday 3 / 2 */
04034                 /* day 4 - day 6 / 2 */
04035                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK && (result=xodtemplate_get_weekday_from_string(temp_buffer[1],&ewday))==OK){
04036                         /* monday 2 - thursday 3 / 2 */
04037                         swday_offset=smday;
04038                         ewday_offset=emday;
04039                         /* add timeperiod exception */
04040                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_WEEK_DAY,0,0,0,swday,swday_offset,0,0,0,ewday,ewday_offset,skip_interval,temp_buffer[2])==NULL)
04041                                 result=ERROR;
04042                         }
04043                 else if((result=xodtemplate_get_month_from_string(temp_buffer[0],&smon))==OK && (result=xodtemplate_get_month_from_string(temp_buffer[1],&emon))==OK){
04044                         /* february 1 - march 15 / 3 */
04045                         /* add timeperiod exception */
04046                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DATE,0,smon,smday,0,0,0,emon,emday,0,0,skip_interval,temp_buffer[2])==NULL)
04047                                 result=ERROR;
04048                         }
04049                 else if(!strcmp(temp_buffer[0],"day")  && !strcmp(temp_buffer[1],"day")){
04050                         /* day 4 - 6 / 2 */
04051                         /* add timeperiod exception */
04052                         result=OK;
04053                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DAY,0,0,smday,0,0,0,0,emday,0,0,skip_interval,temp_buffer[2])==NULL)
04054                                 result=ERROR;
04055                         }
04056                 }
04057 
04058         else if((items=sscanf(input,"%[a-z] %d - %d / %d %[0-9:, -]",temp_buffer[0],&smday,&emday,&skip_interval,temp_buffer[1]))==5){
04059                 /* february 1 - 15 / 3 */
04060                 /* monday 2 - 3 / 2 */
04061                 /* day 1 - 25 / 4 */
04062                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK){
04063                         /* thursday 2 - 4 */
04064                         swday_offset=smday;
04065                         ewday=swday;
04066                         ewday_offset=emday;
04067                         /* add timeperiod exception */
04068                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_WEEK_DAY,0,0,0,swday,swday_offset,0,0,0,ewday,ewday_offset,skip_interval,temp_buffer[1])==NULL)
04069                                 result=ERROR;
04070                         }
04071                 else if((result=xodtemplate_get_month_from_string(temp_buffer[0],&smon))==OK){
04072                         /* february 3 - 5 */
04073                         emon=smon;
04074                         /* add timeperiod exception */
04075                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DATE,0,smon,smday,0,0,0,emon,emday,0,0,skip_interval,temp_buffer[1])==NULL)
04076                                 result=ERROR;
04077                         }
04078                 else if(!strcmp(temp_buffer[0],"day")){
04079                         /* day 1 - 4 */
04080                         /* add timeperiod exception */
04081                         result=OK;
04082                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DAY,0,0,smday,0,0,0,0,emday,0,0,skip_interval,temp_buffer[1])==NULL)
04083                                 result=ERROR;
04084                         }
04085                 }
04086 
04087         else if((items=sscanf(input,"%[a-z] %d %[a-z] - %[a-z] %d %[a-z] %[0-9:, -]",temp_buffer[0],&swday_offset,temp_buffer[1],temp_buffer[2],&ewday_offset,temp_buffer[3],temp_buffer[4]))==7){
04088                 /* wednesday 1 january - thursday 2 july */
04089                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK&& (result=xodtemplate_get_month_from_string(temp_buffer[1],&smon))==OK && (result=xodtemplate_get_weekday_from_string(temp_buffer[2],&ewday))==OK&& (result=xodtemplate_get_month_from_string(temp_buffer[3],&emon))==OK){
04090                         /* add timeperiod exception */
04091                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_WEEK_DAY,0,smon,0,swday,swday_offset,0,emon,0,ewday,ewday_offset,0,temp_buffer[4])==NULL)
04092                                 result=ERROR;
04093                         }
04094                 }
04095 
04096         else if((items=sscanf(input,"%[a-z] %d - %d %[0-9:, -]",temp_buffer[0],&smday,&emday,temp_buffer[1]))==4){
04097                 /* february 3 - 5 */
04098                 /* thursday 2 - 4 */
04099                 /* day 1 - 4 */
04100                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK){
04101                         /* thursday 2 - 4 */
04102                         swday_offset=smday;
04103                         ewday=swday;
04104                         ewday_offset=emday;
04105                         /* add timeperiod exception */
04106                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_WEEK_DAY,0,0,0,swday,swday_offset,0,0,0,ewday,ewday_offset,0,temp_buffer[1])==NULL)
04107                                 result=ERROR;
04108                         }
04109                 else if((result=xodtemplate_get_month_from_string(temp_buffer[0],&smon))==OK){
04110                         /* february 3 - 5 */
04111                         emon=smon;
04112                         /* add timeperiod exception */
04113                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DATE,0,smon,smday,0,0,0,emon,emday,0,0,0,temp_buffer[1])==NULL)
04114                                 result=ERROR;
04115                         }
04116                 else if(!strcmp(temp_buffer[0],"day")){
04117                         /* day 1 - 4 */
04118                         /* add timeperiod exception */
04119                         result=OK;
04120                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DAY,0,0,smday,0,0,0,0,emday,0,0,0,temp_buffer[1])==NULL)
04121                                 result=ERROR;
04122                         }
04123                 }
04124 
04125         else if((items=sscanf(input,"%[a-z] %d - %[a-z] %d %[0-9:, -]",temp_buffer[0],&smday,temp_buffer[1],&emday,temp_buffer[2]))==5){
04126                 /* february 1 - march 15 */
04127                 /* monday 2 - thursday 3 */
04128                 /* day 1 - day 5 */
04129                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK && (result=xodtemplate_get_weekday_from_string(temp_buffer[1],&ewday))==OK){
04130                         /* monday 2 - thursday 3 */
04131                         swday_offset=smday;
04132                         ewday_offset=emday;
04133                         /* add timeperiod exception */
04134                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_WEEK_DAY,0,0,0,swday,swday_offset,0,0,0,ewday,ewday_offset,0,temp_buffer[2])==NULL)
04135                                 result=ERROR;
04136                         }
04137                 else if((result=xodtemplate_get_month_from_string(temp_buffer[0],&smon))==OK && (result=xodtemplate_get_month_from_string(temp_buffer[1],&emon))==OK){
04138                         /* february 1 - march 15 */
04139                         /* add timeperiod exception */
04140                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DATE,0,smon,smday,0,0,0,emon,emday,0,0,0,temp_buffer[2])==NULL)
04141                                 result=ERROR;
04142                         }
04143                 else if(!strcmp(temp_buffer[0],"day")  && !strcmp(temp_buffer[1],"day")){
04144                         /* day 1 - day 5 */
04145                         /* add timeperiod exception */
04146                         result=OK;
04147                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DAY,0,0,smday,0,0,0,0,emday,0,0,0,temp_buffer[2])==NULL)
04148                                 result=ERROR;
04149                         }
04150                 }
04151         
04152         else if((items=sscanf(input,"%[a-z] %d%*[ \t]%[0-9:, -]",temp_buffer[0],&smday,temp_buffer[1]))==3){
04153                 /* february 3 */
04154                 /* thursday 2 */
04155                 /* day 1 */
04156                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK){
04157                         /* thursday 2 */
04158                         swday_offset=smday;
04159                         ewday=swday;
04160                         ewday_offset=swday_offset;
04161                         /* add timeperiod exception */
04162                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_WEEK_DAY,0,0,0,swday,swday_offset,0,0,0,ewday,ewday_offset,0,temp_buffer[1])==NULL)
04163                                 result=ERROR;
04164                         }
04165                 else if((result=xodtemplate_get_month_from_string(temp_buffer[0],&smon))==OK){
04166                         /* february 3 */
04167                         emon=smon;
04168                         emday=smday;
04169                         /* add timeperiod exception */
04170                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DATE,0,smon,smday,0,0,0,emon,emday,0,0,0,temp_buffer[1])==NULL)
04171                                 result=ERROR;
04172                         }
04173                 else if(!strcmp(temp_buffer[0],"day")){
04174                         /* day 1 */
04175                         emday=smday;
04176                         /* add timeperiod exception */
04177                         result=OK;
04178                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_DAY,0,0,smday,0,0,0,0,emday,0,0,0,temp_buffer[1])==NULL)
04179                                 result=ERROR;
04180                         }
04181                 }
04182 
04183         else if((items=sscanf(input,"%[a-z] %d %[a-z] %[0-9:, -]",temp_buffer[0],&swday_offset,temp_buffer[1],temp_buffer[2]))==4){
04184                 /* thursday 3 february */
04185                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK&& (result=xodtemplate_get_month_from_string(temp_buffer[1],&smon))==OK){
04186                         emon=smon;
04187                         ewday=swday;
04188                         ewday_offset=swday_offset;
04189                         /* add timeperiod exception */
04190                         if(xodtemplate_add_exception_to_timeperiod(tperiod,DATERANGE_MONTH_WEEK_DAY,0,smon,0,swday,swday_offset,0,emon,0,ewday,ewday_offset,0,temp_buffer[2])==NULL)
04191                                 result=ERROR;
04192                         }
04193                 }
04194         
04195         else if((items=sscanf(input,"%[a-z] %[0-9:, -]",temp_buffer[0],temp_buffer[1]))==2){
04196                 /* monday */
04197                 if((result=xodtemplate_get_weekday_from_string(temp_buffer[0],&swday))==OK){
04198                         /* add normal weekday timerange */
04199                         if((tperiod->timeranges[swday]=(char *)strdup(temp_buffer[1]))==NULL)
04200                                 result=ERROR;
04201                         }
04202                 }
04203 
04204         else
04205                 result=ERROR;
04206 
04207         /* free memory */
04208         my_free(input);
04209 
04210         if(result==ERROR){
04211 #ifdef NSCORE
04212                 printf("Error: Could not parse timeperiod directive '%s'!\n",input);
04213 #endif
04214                 return ERROR;
04215                 }
04216 
04217         return OK;
04218         }
04219 
04220 
04221 
04222 /* add a new exception to a timeperiod */
04223 xodtemplate_daterange *xodtemplate_add_exception_to_timeperiod(xodtemplate_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, char *timeranges){
04224         xodtemplate_daterange *new_daterange=NULL;
04225 
04226         /* make sure we have the data we need */
04227         if(period==NULL || timeranges==NULL)
04228                 return NULL;
04229 
04230         /* allocate memory for the date range range */
04231         if((new_daterange=malloc(sizeof(xodtemplate_daterange)))==NULL)
04232                 return NULL;
04233 
04234         new_daterange->next=NULL;
04235 
04236         new_daterange->type=type;
04237         new_daterange->syear=syear;
04238         new_daterange->smon=smon;
04239         new_daterange->smday=smday;
04240         new_daterange->swday=swday;
04241         new_daterange->swday_offset=swday_offset;
04242         new_daterange->eyear=eyear;
04243         new_daterange->emon=emon;
04244         new_daterange->emday=emday;
04245         new_daterange->ewday=ewday;
04246         new_daterange->ewday_offset=ewday_offset;
04247         new_daterange->skip_interval=skip_interval;
04248         new_daterange->timeranges=(char *)strdup(timeranges);
04249 
04250         /* add the new date range to the head of the range list for this exception type */
04251         new_daterange->next=period->exceptions[type];
04252         period->exceptions[type]=new_daterange;
04253 
04254         return new_daterange;
04255         }
04256 
04257 
04258 
04259 int xodtemplate_get_month_from_string(char *str, int *month){
04260         char *months[12]={"january","february","march","april","may","june","july","august","september","october","november","december"};
04261         int x=0;
04262 
04263         if(str==NULL || month==NULL)
04264                 return ERROR;
04265 
04266         for(x=0;x<12;x++){
04267                 if(!strcmp(str,months[x])){
04268                         *month=x;
04269                         return OK;
04270                         }
04271                 }
04272 
04273         return ERROR;
04274         }
04275 
04276 
04277 
04278 
04279 int xodtemplate_get_weekday_from_string(char *str, int *weekday){
04280         char *days[7]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
04281         int x=0;
04282 
04283         if(str==NULL || weekday==NULL)
04284                 return ERROR;
04285 
04286         for(x=0;x<7;x++){
04287                 if(!strcmp(str,days[x])){
04288                         *weekday=x;
04289                         return OK;
04290                         }
04291                 }
04292 
04293         return ERROR;
04294         }
04295 
04296 
04297 
04298 /******************************************************************/
04299 /***************** OBJECT DUPLICATION FUNCTIONS *******************/
04300 /******************************************************************/
04301 
04302 #ifdef NSCORE
04303 
04304 /* duplicates service definitions */
04305 int xodtemplate_duplicate_services(void){
04306         int result=OK;
04307         xodtemplate_service *temp_service=NULL;
04308         xodtemplate_memberlist *temp_memberlist=NULL;
04309         xodtemplate_memberlist *temp_rejectlist=NULL;
04310         xodtemplate_memberlist *this_memberlist=NULL;
04311         char *host_name=NULL;
04312         int first_item=FALSE;
04313 
04314 
04315         /****** DUPLICATE SERVICE DEFINITIONS WITH ONE OR MORE HOSTGROUP AND/OR HOST NAMES ******/
04316         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
04317 
04318                 /* skip service definitions without enough data */
04319                 if(temp_service->hostgroup_name==NULL && temp_service->host_name==NULL)
04320                         continue;
04321 
04322                 /* If hostgroup is not null and hostgroup has no members, check to see if */
04323                 /* allow_empty_hostgroup_assignment is set to 1 - if it is, continue without error  */
04324                 if(temp_service->hostgroup_name!=NULL){
04325                         if(xodtemplate_expand_hostgroups(&temp_memberlist,&temp_rejectlist,temp_service->hostgroup_name,temp_service->_config_file,temp_service->_start_line)==ERROR){
04326                                 return ERROR;
04327                                 }
04328                         else{
04329                                 xodtemplate_free_memberlist(&temp_rejectlist);
04330                                 if (temp_memberlist!=NULL){
04331                                         xodtemplate_free_memberlist(&temp_memberlist);
04332                                         }
04333                                 else{
04334                                         /* User is ok with hostgroup -> service mappings with no hosts */
04335                                         if(allow_empty_hostgroup_assignment==1){
04336                                                 continue;
04337                                                }
04338                                         }
04339                                 }
04340                         }
04341 
04342                 /* skip services that shouldn't be registered */
04343                 if(temp_service->register_object==FALSE)
04344                         continue;
04345 
04346                 /* get list of hosts */
04347                 temp_memberlist=xodtemplate_expand_hostgroups_and_hosts(temp_service->hostgroup_name,temp_service->host_name,temp_service->_config_file,temp_service->_start_line);
04348                 if(temp_memberlist==NULL){
04349                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand hostgroups and/or hosts specified in service (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04350                         return ERROR;
04351                         }
04352 
04353                 /* add a copy of the service for every host in the hostgroup/host name list */
04354                 first_item=TRUE;
04355                 for(this_memberlist=temp_memberlist;this_memberlist!=NULL;this_memberlist=this_memberlist->next){
04356 
04357                         /* if this is the first duplication, use the existing entry */
04358                         if(first_item==TRUE){
04359 
04360                                 my_free(temp_service->host_name);
04361                                 temp_service->host_name=(char *)strdup(this_memberlist->name1);
04362                                 if(temp_service->host_name==NULL){
04363                                         xodtemplate_free_memberlist(&temp_memberlist);
04364                                         return ERROR;
04365                                         }
04366 
04367                                 first_item=FALSE;
04368                                 continue;
04369                                 }
04370 
04371                         /* duplicate service definition */
04372                         result=xodtemplate_duplicate_service(temp_service,this_memberlist->name1);
04373 
04374                         /* exit on error */
04375                         if(result==ERROR){
04376                                 my_free(host_name);
04377                                 return ERROR;
04378                                 }
04379                         }
04380 
04381                 /* free memory we used for host list */
04382                 xodtemplate_free_memberlist(&temp_memberlist);
04383                 }
04384 
04385 
04386         /***************************************/
04387         /* SKIPLIST STUFF FOR FAST SORT/SEARCH */
04388         /***************************************/
04389 
04390         /* First loop for single host service definition*/
04391         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
04392 
04393                 /* skip services that shouldn't be registered */
04394                 if(temp_service->register_object==FALSE)
04395                         continue;
04396 
04397                 if(xodtemplate_is_service_is_from_hostgroup(temp_service)){
04398                         continue;
04399                 }
04400 
04401                 /* skip service definitions without enough data */
04402                 /* make host_name optional for services, only warn */
04403                 if(temp_service->host_name==NULL){
04404                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: No host_name found for service definition or used template (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04405                         result=ERROR;
04406                 }
04407 
04408                 if(temp_service->service_description==NULL){
04409                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: No service_description found for service definition or used template (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04410                         return ERROR;
04411                 }
04412 
04413                 result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
04414 
04415                 switch(result){
04416                 case SKIPLIST_ERROR_DUPLICATE:
04417                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' on host '%s' (config file '%s', starting on line %d)\n",temp_service->service_description,temp_service->host_name,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04418                         result=ERROR;
04419                         break;
04420                 case SKIPLIST_OK:
04421                         result=OK;
04422                         break;
04423                 default:
04424                         result=ERROR;
04425                         break;
04426                         }
04427                 }
04428 
04429 
04430         /* second loop for host group service definition*/
04431         /* add services to skiplist for fast searches */
04432         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
04433 
04434                 /* skip services that shouldn't be registered */
04435                 if(temp_service->register_object==FALSE)
04436                         continue;
04437 
04438                 if(!xodtemplate_is_service_is_from_hostgroup(temp_service)){
04439                         continue;
04440                 }
04441                 /*The flag X_SERVICE_IS_FROM_HOSTGROUP is set, unset it*/
04442                 xodtemplate_unset_service_is_from_hostgroup(temp_service);
04443 
04444                 /* skip service definitions without enough data */
04445                 if(temp_service->host_name==NULL){
04446                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: No host_name found for service definition or used template (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04447                         return ERROR;
04448                 }
04449 
04450                 if(temp_service->service_description==NULL){
04451                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: No service_description found for service definition or used template (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04452                         return ERROR;
04453                 }
04454 
04455                 result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
04456 
04457                 switch(result){
04458                 case SKIPLIST_ERROR_DUPLICATE:
04459                         logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' on host '%s' (config file '%s', starting on line %d)\n",temp_service->service_description,temp_service->host_name,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
04460                         result=ERROR;
04461                         break;
04462                 case SKIPLIST_OK:
04463                         result=OK;
04464                         break;
04465                 default:
04466                         result=ERROR;
04467                         break;
04468                         }
04469                 }
04470 
04471         return OK;
04472         }
04473 
04474 
04475 
04476 /* duplicates object definitions */
04477 int xodtemplate_duplicate_objects(void){
04478         int result=OK;
04479         xodtemplate_hostescalation *temp_hostescalation=NULL;
04480         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
04481         xodtemplate_hostdependency *temp_hostdependency=NULL;
04482         xodtemplate_servicedependency *temp_servicedependency=NULL;
04483         xodtemplate_hostextinfo *temp_hostextinfo=NULL;
04484         xodtemplate_serviceextinfo *temp_serviceextinfo=NULL;
04485 
04486         xodtemplate_memberlist *master_hostlist=NULL,*dependent_hostlist=NULL;
04487         xodtemplate_memberlist *master_servicelist=NULL,*dependent_servicelist=NULL;
04488         xodtemplate_memberlist *temp_masterhost=NULL,*temp_dependenthost=NULL;
04489         xodtemplate_memberlist *temp_masterservice=NULL,*temp_dependentservice=NULL;
04490 
04491         char *service_descriptions=NULL;
04492         int first_item=FALSE;
04493         int same_host_servicedependency=FALSE;
04494 
04495 
04496         /*************************************/
04497         /* SERVICES ARE DUPLICATED ELSEWHERE */
04498         /*************************************/
04499 
04500 
04501         /****** DUPLICATE HOST ESCALATION DEFINITIONS WITH ONE OR MORE HOSTGROUP AND/OR HOST NAMES ******/
04502         for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
04503 
04504                 /* skip host escalation definitions without enough data */
04505                 if(temp_hostescalation->hostgroup_name==NULL && temp_hostescalation->host_name==NULL)
04506                         continue;
04507 
04508                 /* get list of hosts */
04509                 master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_hostescalation->hostgroup_name,temp_hostescalation->host_name,temp_hostescalation->_config_file,temp_hostescalation->_start_line);
04510                 if(master_hostlist==NULL){
04511                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand hostgroups and/or hosts specified in host escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostescalation->_config_file),temp_hostescalation->_start_line);
04512                         return ERROR;
04513                         }
04514 
04515                 /* add a copy of the hostescalation for every host in the hostgroup/host name list */
04516                 first_item=TRUE;
04517                 for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
04518 
04519                         /* if this is the first duplication, use the existing entry */
04520                         if(first_item==TRUE){
04521 
04522                                 my_free(temp_hostescalation->host_name);
04523                                 temp_hostescalation->host_name=(char *)strdup(temp_masterhost->name1);
04524                                 if(temp_hostescalation->host_name==NULL){
04525                                         xodtemplate_free_memberlist(&master_hostlist);
04526                                         return ERROR;
04527                                         }
04528 
04529                                 first_item=FALSE;
04530                                 continue;
04531                                 }
04532 
04533                         /* duplicate hostescalation definition */
04534                         result=xodtemplate_duplicate_hostescalation(temp_hostescalation,temp_masterhost->name1);
04535 
04536                         /* exit on error */
04537                         if(result==ERROR){
04538                                 xodtemplate_free_memberlist(&master_hostlist);
04539                                 return ERROR;
04540                                 }
04541                         }
04542 
04543                 /* free memory we used for host list */
04544                 xodtemplate_free_memberlist(&master_hostlist);
04545                 }
04546 
04547         
04548         /****** DUPLICATE SERVICE ESCALATION DEFINITIONS WITH ONE OR MORE HOSTGROUP AND/OR HOST NAMES ******/
04549         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
04550 
04551                 /* skip service escalation definitions without enough data */
04552                 if(temp_serviceescalation->hostgroup_name==NULL && temp_serviceescalation->host_name==NULL)
04553                         continue;
04554 
04555                 /* get list of hosts */
04556                 master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_serviceescalation->hostgroup_name,temp_serviceescalation->host_name,temp_serviceescalation->_config_file,temp_serviceescalation->_start_line);
04557                 if(master_hostlist==NULL){
04558                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand hostgroups and/or hosts specified in service escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_serviceescalation->_config_file),temp_serviceescalation->_start_line);
04559                         return ERROR;
04560                         }
04561 
04562                 /* duplicate service escalation entries */
04563                 first_item=TRUE;
04564                 for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
04565 
04566                         /* if this is the first duplication,use the existing entry */
04567                         if(first_item==TRUE){
04568 
04569                                 my_free(temp_serviceescalation->host_name);
04570                                 temp_serviceescalation->host_name=(char *)strdup(temp_masterhost->name1);
04571                                 if(temp_serviceescalation->host_name==NULL){
04572                                         xodtemplate_free_memberlist(&master_hostlist);
04573                                         return ERROR;
04574                                         }
04575 
04576                                 first_item=FALSE;
04577                                 continue;
04578                                 }
04579 
04580                         /* duplicate service escalation definition */
04581                         result=xodtemplate_duplicate_serviceescalation(temp_serviceescalation,temp_masterhost->name1,temp_serviceescalation->service_description);
04582 
04583                         /* exit on error */
04584                         if(result==ERROR){
04585                                 xodtemplate_free_memberlist(&master_hostlist);
04586                                 return ERROR;
04587                                 }
04588                         }
04589 
04590                 /* free memory we used for host list */
04591                 xodtemplate_free_memberlist(&master_hostlist);
04592                 }
04593 
04594 
04595         /****** DUPLICATE SERVICE ESCALATION DEFINITIONS WITH MULTIPLE DESCRIPTIONS ******/
04596         /* THIS MUST BE DONE AFTER DUPLICATING FOR MULTIPLE HOST NAMES (SEE ABOVE) */
04597         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
04598 
04599                 /* skip serviceescalations without enough data */
04600                 if(temp_serviceescalation->service_description==NULL || temp_serviceescalation->host_name==NULL)
04601                         continue;
04602 
04603                 /* get list of services */
04604                 master_servicelist=xodtemplate_expand_servicegroups_and_services(NULL,temp_serviceescalation->host_name,temp_serviceescalation->service_description,temp_serviceescalation->_config_file,temp_serviceescalation->_start_line);
04605                 if(master_servicelist==NULL){
04606                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand services specified in service escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_serviceescalation->_config_file),temp_serviceescalation->_start_line);
04607                         return ERROR;
04608                         }
04609 
04610                 /* duplicate service escalation entries */
04611                 first_item=TRUE;
04612                 for(temp_masterservice=master_servicelist;temp_masterservice!=NULL;temp_masterservice=temp_masterservice->next){
04613 
04614                         /* if this is the first duplication, use the existing entry */
04615                         if(first_item==TRUE){
04616 
04617                                 my_free(temp_serviceescalation->service_description);
04618                                 temp_serviceescalation->service_description=(char *)strdup(temp_masterservice->name2);
04619                                 if(temp_serviceescalation->service_description==NULL){
04620                                         xodtemplate_free_memberlist(&master_servicelist);
04621                                         return ERROR;
04622                                         }
04623 
04624                                 first_item=FALSE;
04625                                 continue;
04626                                 }
04627 
04628                         /* duplicate service escalation definition */
04629                         result=xodtemplate_duplicate_serviceescalation(temp_serviceescalation,temp_serviceescalation->host_name,temp_masterservice->name2);
04630 
04631                         /* exit on error */
04632                         if(result==ERROR){
04633                                 xodtemplate_free_memberlist(&master_servicelist);
04634                                 return ERROR;
04635                                 }
04636                         }
04637 
04638                 /* free memory we used for service list */
04639                 xodtemplate_free_memberlist(&master_servicelist);
04640                 }
04641 
04642 
04643 
04644         /****** DUPLICATE SERVICE ESCALATION DEFINITIONS WITH SERVICEGROUPS ******/
04645         /* THIS MUST BE DONE AFTER DUPLICATING FOR MULTIPLE HOST NAMES (SEE ABOVE) */
04646         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
04647 
04648                 /* skip serviceescalations without enough data */
04649                 if(temp_serviceescalation->servicegroup_name==NULL)
04650                         continue;
04651 
04652                 /* get list of services */
04653                 master_servicelist=xodtemplate_expand_servicegroups_and_services(temp_serviceescalation->servicegroup_name,NULL,NULL,temp_serviceescalation->_config_file,temp_serviceescalation->_start_line);
04654                 if(master_servicelist==NULL){
04655                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand servicegroups specified in service escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_serviceescalation->_config_file),temp_serviceescalation->_start_line);
04656                         return ERROR;
04657                         }
04658 
04659                 /* duplicate service escalation entries */
04660                 first_item=TRUE;
04661                 for(temp_masterservice=master_servicelist;temp_masterservice!=NULL;temp_masterservice=temp_masterservice->next){
04662 
04663                         /* if this is the first duplication, use the existing entry if possible */
04664                         if(first_item==TRUE && temp_serviceescalation->host_name==NULL && temp_serviceescalation->service_description==NULL){
04665 
04666                                 my_free(temp_serviceescalation->host_name);
04667                                 temp_serviceescalation->host_name=(char *)strdup(temp_masterservice->name1);
04668 
04669                                 my_free(temp_serviceescalation->service_description);
04670                                 temp_serviceescalation->service_description=(char *)strdup(temp_masterservice->name2);
04671 
04672                                 if(temp_serviceescalation->host_name==NULL || temp_serviceescalation->service_description==NULL){
04673                                         xodtemplate_free_memberlist(&master_servicelist);
04674                                         return ERROR;
04675                                         }
04676 
04677                                 first_item=FALSE;
04678                                 continue;
04679                                 }
04680 
04681                         /* duplicate service escalation definition */
04682                         result=xodtemplate_duplicate_serviceescalation(temp_serviceescalation,temp_masterservice->name1,temp_masterservice->name2);
04683 
04684                         /* exit on error */
04685                         if(result==ERROR){
04686                                 xodtemplate_free_memberlist(&master_servicelist);
04687                                 return ERROR;
04688                                 }
04689                         }
04690 
04691                 /* free memory we used for service list */
04692                 xodtemplate_free_memberlist(&master_servicelist);
04693                 }
04694 
04695 
04696         /****** DUPLICATE HOST DEPENDENCY DEFINITIONS WITH MULTIPLE HOSTGROUP AND/OR HOST NAMES (MASTER AND DEPENDENT) ******/
04697         for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
04698                 
04699                 /* skip host dependencies without enough data */
04700                 if(temp_hostdependency->hostgroup_name==NULL && temp_hostdependency->dependent_hostgroup_name==NULL && temp_hostdependency->host_name==NULL && temp_hostdependency->dependent_host_name==NULL)
04701                         continue;
04702 
04703                 /* get list of master host names */
04704                 master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_hostdependency->hostgroup_name,temp_hostdependency->host_name,temp_hostdependency->_config_file,temp_hostdependency->_start_line);
04705                 if(master_hostlist==NULL){
04706                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand master hostgroups and/or hosts specified in host dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostdependency->_config_file),temp_hostdependency->_start_line);
04707                         return ERROR;
04708                         }
04709 
04710                 /* get list of dependent host names */
04711                 dependent_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_hostdependency->dependent_hostgroup_name,temp_hostdependency->dependent_host_name,temp_hostdependency->_config_file,temp_hostdependency->_start_line);
04712                 if(dependent_hostlist==NULL){
04713                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand dependent hostgroups and/or hosts specified in host dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostdependency->_config_file),temp_hostdependency->_start_line);
04714                         xodtemplate_free_memberlist(&master_hostlist);
04715                         return ERROR;
04716                         }
04717 
04718                 /* duplicate the dependency definitions */
04719                 first_item=TRUE;
04720                 for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
04721 
04722                         for(temp_dependenthost=dependent_hostlist;temp_dependenthost!=NULL;temp_dependenthost=temp_dependenthost->next){
04723 
04724                                 /* temp=master, this=dep */
04725 
04726                                 /* existing definition gets first names */
04727                                 if(first_item==TRUE){
04728                                         my_free(temp_hostdependency->host_name);
04729                                         my_free(temp_hostdependency->dependent_host_name);
04730                                         temp_hostdependency->host_name=(char *)strdup(temp_masterhost->name1);
04731                                         temp_hostdependency->dependent_host_name=(char *)strdup(temp_dependenthost->name1);
04732                                         first_item=FALSE;
04733                                         continue;
04734                                         }
04735                                 else
04736                                         result=xodtemplate_duplicate_hostdependency(temp_hostdependency,temp_masterhost->name1,temp_dependenthost->name1);
04737                                 /* exit on error */
04738                                 if(result==ERROR){
04739                                         xodtemplate_free_memberlist(&master_hostlist);
04740                                         xodtemplate_free_memberlist(&dependent_hostlist);
04741                                         return ERROR;
04742                                         }
04743                                 }
04744                         }
04745 
04746                 /* free memory used to store host lists */
04747                 xodtemplate_free_memberlist(&master_hostlist);
04748                 xodtemplate_free_memberlist(&dependent_hostlist);
04749                 }
04750 
04751 
04752 
04753         /****** PROCESS SERVICE DEPENDENCIES WITH MASTER SERVICEGROUPS *****/
04754         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
04755 
04756                 /* skip templates */
04757                 if(temp_servicedependency->register_object==0)
04758                         continue;
04759 
04760                 /* expand master servicegroups into a list of services */
04761                 if(temp_servicedependency->servicegroup_name){
04762 
04763                         master_servicelist=xodtemplate_expand_servicegroups_and_services(temp_servicedependency->servicegroup_name,NULL,NULL,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
04764                         if(master_servicelist==NULL){
04765                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand master servicegroups specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
04766                                 return ERROR;
04767                                 }
04768 
04769                         /* if dependency also has master host, hostgroup, and/or service, we must split that off to another definition */
04770                         if(temp_servicedependency->host_name!=NULL || temp_servicedependency->hostgroup_name!=NULL || temp_servicedependency->service_description!=NULL){
04771 
04772                                 /* duplicate everything except master servicegroup */
04773                                 xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,temp_servicedependency->hostgroup_name,NULL,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_service_description,temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_servicegroup_name);
04774 
04775                                 /* clear values in this definition */
04776                                 temp_servicedependency->have_host_name=FALSE;
04777                                 temp_servicedependency->have_service_description=FALSE;
04778                                 temp_servicedependency->have_hostgroup_name=FALSE;
04779                                 my_free(temp_servicedependency->host_name);
04780                                 my_free(temp_servicedependency->service_description);
04781                                 my_free(temp_servicedependency->hostgroup_name);
04782                                 }
04783 
04784                         /* duplicate service dependency entries */
04785                         first_item=TRUE;
04786                         for(temp_masterservice=master_servicelist;temp_masterservice!=NULL;temp_masterservice=temp_masterservice->next){
04787 
04788                                 /* just in case */
04789                                 if(temp_masterservice->name1==NULL || temp_masterservice->name2==NULL)
04790                                         continue;
04791 
04792                                 /* if this is the first duplication, use the existing entry */
04793                                 if(first_item==TRUE){
04794 
04795                                         my_free(temp_servicedependency->host_name);
04796                                         temp_servicedependency->host_name=(char *)strdup(temp_masterservice->name1);
04797 
04798                                         my_free(temp_servicedependency->service_description);
04799                                         temp_servicedependency->service_description=(char *)strdup(temp_masterservice->name2);
04800 
04801                                         /* clear the master servicegroup */
04802                                         temp_servicedependency->have_servicegroup_name=FALSE;
04803                                         my_free(temp_servicedependency->servicegroup_name);
04804                                 
04805                                         if(temp_servicedependency->host_name==NULL || temp_servicedependency->service_description==NULL){
04806                                                 xodtemplate_free_memberlist(&master_servicelist);
04807                                                 return ERROR;
04808                                                 }
04809 
04810                                         first_item=FALSE;
04811                                         continue;
04812                                         }
04813 
04814                                 /* duplicate service dependency definition */
04815                                 result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_masterservice->name1,temp_masterservice->name2,NULL,NULL,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_service_description,temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_servicegroup_name);
04816 
04817                                 /* exit on error */
04818                                 if(result==ERROR){
04819                                         xodtemplate_free_memberlist(&master_servicelist);
04820                                         return ERROR;
04821                                         }
04822                                 }
04823 
04824                         /* free memory we used for service list */
04825                         xodtemplate_free_memberlist(&master_servicelist);
04826                         }
04827                 }
04828 
04829 
04830         /****** PROCESS SERVICE DEPENDENCY MASTER HOSTS/HOSTGROUPS/SERVICES *****/
04831         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
04832 
04833                 /* skip templates */
04834                 if(temp_servicedependency->register_object==0)
04835                         continue;
04836 
04837                 /* expand master hosts/hostgroups into a list of host names */
04838                 if(temp_servicedependency->host_name!=NULL || temp_servicedependency->hostgroup_name!=NULL){
04839 
04840 #ifdef DEBUG_SERVICE_DEPENDENCIES
04841                         printf("1a) H: %s  HG: %s  SD: %s\n",temp_servicedependency->host_name,temp_servicedependency->hostgroup_name,temp_servicedependency->service_description);
04842 #endif
04843 
04844                         master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_servicedependency->hostgroup_name,temp_servicedependency->host_name,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
04845                         if(master_hostlist==NULL){
04846                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand master hostgroups and/or hosts specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
04847                                 return ERROR;
04848                                 }
04849 
04850                         /* save service descriptions for later */
04851                         if(temp_servicedependency->service_description)
04852                                 service_descriptions=(char *)strdup(temp_servicedependency->service_description);
04853 
04854                         /* for each host, expand master services */
04855                         first_item=TRUE;
04856                         for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
04857 
04858                                 master_servicelist=xodtemplate_expand_servicegroups_and_services(NULL,temp_masterhost->name1,service_descriptions,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
04859                                 if(master_servicelist==NULL){
04860                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand master services specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
04861                                         return ERROR;
04862                                         }
04863 
04864                                 /* duplicate service dependency entries */
04865                                 for(temp_masterservice=master_servicelist;temp_masterservice!=NULL;temp_masterservice=temp_masterservice->next){
04866                                         
04867                                         /* just in case */
04868                                         if(temp_masterservice->name1==NULL || temp_masterservice->name2==NULL)
04869                                                 continue;
04870 
04871                                         /* if this is the first duplication, use the existing entry */
04872                                         if(first_item==TRUE){
04873 
04874                                                 my_free(temp_servicedependency->host_name);
04875                                                 temp_servicedependency->host_name=(char *)strdup(temp_masterhost->name1);
04876 
04877                                                 my_free(temp_servicedependency->service_description);
04878                                                 temp_servicedependency->service_description=(char *)strdup(temp_masterservice->name2);
04879 
04880                                                 if(temp_servicedependency->host_name==NULL || temp_servicedependency->service_description==NULL){
04881                                                         xodtemplate_free_memberlist(&master_hostlist);
04882                                                         xodtemplate_free_memberlist(&master_servicelist);
04883                                                         return ERROR;
04884                                                         }
04885 
04886                                                 first_item=FALSE;
04887                                                 continue;
04888                                                 }
04889 
04890                                         /* duplicate service dependency definition */
04891                                         result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_masterhost->name1,temp_masterservice->name2,NULL,NULL,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_service_description,temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_servicegroup_name);
04892 
04893                                         /* exit on error */
04894                                         if(result==ERROR){
04895                                                 xodtemplate_free_memberlist(&master_hostlist);
04896                                                 xodtemplate_free_memberlist(&master_servicelist);
04897                                                 return ERROR;
04898                                                 }
04899                                         }
04900 
04901                                 /* free memory we used for service list */
04902                                 xodtemplate_free_memberlist(&master_servicelist);
04903                                 }
04904 
04905                         /* free service descriptions */
04906                         my_free(service_descriptions);
04907 
04908                         /* free memory we used for host list */
04909                         xodtemplate_free_memberlist(&master_hostlist);
04910                         }
04911                 }
04912 
04913 
04914 #ifdef DEBUG_SERVICE_DEPENDENCIES
04915         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
04916                 printf("1**) H: %s  HG: %s  SG: %s  SD: %s  DH: %s  DHG: %s  DSG: %s  DSD: %s\n",temp_servicedependency->host_name,temp_servicedependency->hostgroup_name,temp_servicedependency->servicegroup_name,temp_servicedependency->service_description,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_servicegroup_name,temp_servicedependency->dependent_service_description);
04917                 }
04918         printf("\n");
04919 #endif
04920 
04921 
04922         /****** PROCESS SERVICE DEPENDENCIES WITH DEPENDENT SERVICEGROUPS *****/
04923         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
04924 
04925                 /* skip templates */
04926                 if(temp_servicedependency->register_object==0)
04927                         continue;
04928 
04929                 /* expand dependent servicegroups into a list of services */
04930                 if(temp_servicedependency->dependent_servicegroup_name){
04931 
04932                         dependent_servicelist=xodtemplate_expand_servicegroups_and_services(temp_servicedependency->dependent_servicegroup_name,NULL,NULL,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
04933                         if(dependent_servicelist==NULL){
04934                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand dependent servicegroups specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
04935                                 return ERROR;
04936                                 }
04937 
04938                         /* if dependency also has dependent host, hostgroup, and/or service, we must split that off to another definition */
04939                         if(temp_servicedependency->dependent_host_name!=NULL || temp_servicedependency->dependent_hostgroup_name!=NULL || temp_servicedependency->dependent_service_description!=NULL){
04940 
04941                                 /* duplicate everything except dependent servicegroup */
04942                                 xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,temp_servicedependency->hostgroup_name,temp_servicedependency->servicegroup_name,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_service_description,temp_servicedependency->dependent_hostgroup_name,NULL);
04943 
04944                                 /* clear values in this definition */
04945                                 temp_servicedependency->have_dependent_host_name=FALSE;
04946                                 temp_servicedependency->have_dependent_service_description=FALSE;
04947                                 temp_servicedependency->have_dependent_hostgroup_name=FALSE;
04948                                 my_free(temp_servicedependency->dependent_host_name);
04949                                 my_free(temp_servicedependency->dependent_service_description);
04950                                 my_free(temp_servicedependency->dependent_hostgroup_name);
04951                                 }
04952 
04953                         /* Detected same host servicegroups dependencies */
04954                         same_host_servicedependency=FALSE;
04955                         if(temp_servicedependency->host_name==NULL && temp_servicedependency->hostgroup_name==NULL)
04956                                 same_host_servicedependency=TRUE;
04957 
04958                         /* duplicate service dependency entries */
04959                         first_item=TRUE;
04960                         for(temp_dependentservice=dependent_servicelist;temp_dependentservice!=NULL;temp_dependentservice=temp_dependentservice->next){
04961 
04962                                 /* just in case */
04963                                 if(temp_dependentservice->name1==NULL || temp_dependentservice->name2==NULL)
04964                                         continue;
04965 
04966                                 /* if this is the first duplication, use the existing entry */
04967                                 if(first_item==TRUE){
04968 
04969                                         my_free(temp_servicedependency->dependent_host_name);
04970                                         temp_servicedependency->dependent_host_name=(char *)strdup(temp_dependentservice->name1);
04971 
04972                                         my_free(temp_servicedependency->dependent_service_description);
04973                                         temp_servicedependency->dependent_service_description=(char *)strdup(temp_dependentservice->name2);
04974 
04975                                         /* Same host servicegroups dependencies: Use dependentservice host_name for master host_name */
04976                                         if(same_host_servicedependency==TRUE)
04977                                                 temp_servicedependency->host_name=(char*)strdup(temp_dependentservice->name1);
04978 
04979                                         /* clear the dependent servicegroup */
04980                                         temp_servicedependency->have_dependent_servicegroup_name=FALSE;
04981                                         my_free(temp_servicedependency->dependent_servicegroup_name);
04982 
04983                                         if(temp_servicedependency->dependent_host_name==NULL || temp_servicedependency->dependent_service_description==NULL){
04984                                                 xodtemplate_free_memberlist(&dependent_servicelist);
04985                                                 return ERROR;
04986                                                 }
04987 
04988                                         first_item=FALSE;
04989                                         continue;
04990                                         }
04991 
04992                                 /* duplicate service dependency definition */
04993                                 /* Same host servicegroups dependencies: Use dependentservice host_name for master host_name instead of undefined (not yet) master host_name */
04994                                 if(same_host_servicedependency==TRUE)
04995                                         result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_dependentservice->name1,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
04996                                 else
04997                                         result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
04998 
04999                                 /* exit on error */
05000                                 if(result==ERROR){
05001                                         xodtemplate_free_memberlist(&dependent_servicelist);
05002                                         return ERROR;
05003                                         }
05004                                 }
05005 
05006                         /* free memory we used for service list */
05007                         xodtemplate_free_memberlist(&dependent_servicelist);
05008                         }
05009                 }
05010 
05011 
05012 #ifdef DEBUG_SERVICE_DEPENDENCIES
05013         printf("\n");
05014         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
05015                 printf("2**) H: %s  HG: %s  SG: %s  SD: %s  DH: %s  DHG: %s  DSG: %s  DSD: %s\n",temp_servicedependency->host_name,temp_servicedependency->hostgroup_name,temp_servicedependency->servicegroup_name,temp_servicedependency->service_description,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_servicegroup_name,temp_servicedependency->dependent_service_description);
05016                 }
05017 #endif
05018 
05019 
05020         /****** PROCESS SERVICE DEPENDENCY DEPENDENT HOSTS/HOSTGROUPS/SERVICES *****/
05021         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
05022 
05023                 /* skip templates */
05024                 if(temp_servicedependency->register_object==0)
05025                         continue;
05026 
05027                 /* ADDED 02/04/2007 - special case for "same host" dependencies */
05028                 if(temp_servicedependency->dependent_host_name==NULL && temp_servicedependency->dependent_hostgroup_name==NULL){
05029                         if(temp_servicedependency->host_name)
05030                                 temp_servicedependency->dependent_host_name=(char *)strdup(temp_servicedependency->host_name);
05031                         }
05032 
05033                 /* expand dependent hosts/hostgroups into a list of host names */
05034                 if(temp_servicedependency->dependent_host_name!=NULL || temp_servicedependency->dependent_hostgroup_name!=NULL){
05035 
05036                         dependent_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_servicedependency->dependent_hostgroup_name,temp_servicedependency->dependent_host_name,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
05037                         if(dependent_hostlist==NULL){
05038                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand dependent hostgroups and/or hosts specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
05039                                 return ERROR;
05040                                 }
05041 
05042                         /* save service descriptions for later */
05043                         if(temp_servicedependency->dependent_service_description)
05044                                 service_descriptions=(char *)strdup(temp_servicedependency->dependent_service_description);
05045 
05046                         /* for each host, expand dependent services */
05047                         first_item=TRUE;
05048                         for(temp_dependenthost=dependent_hostlist;temp_dependenthost!=NULL;temp_dependenthost=temp_dependenthost->next){
05049 
05050                                 dependent_servicelist=xodtemplate_expand_servicegroups_and_services(NULL,temp_dependenthost->name1,service_descriptions,temp_servicedependency->_config_file,temp_servicedependency->_start_line);
05051                                 if(dependent_servicelist==NULL){
05052                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand dependent services specified in service dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicedependency->_config_file),temp_servicedependency->_start_line);
05053                                         return ERROR;
05054                                         }
05055 
05056                                 /* duplicate service dependency entries */
05057                                 for(temp_dependentservice=dependent_servicelist;temp_dependentservice!=NULL;temp_dependentservice=temp_dependentservice->next){
05058                                         
05059                                         /* just in case */
05060                                         if(temp_dependentservice->name1==NULL || temp_dependentservice->name2==NULL)
05061                                                 continue;
05062 
05063                                         /* if this is the first duplication, use the existing entry */
05064                                         if(first_item==TRUE){
05065 
05066                                                 my_free(temp_servicedependency->dependent_host_name);
05067                                                 temp_servicedependency->dependent_host_name=(char *)strdup(temp_dependentservice->name1);
05068 
05069                                                 my_free(temp_servicedependency->dependent_service_description);
05070                                                 temp_servicedependency->dependent_service_description=(char *)strdup(temp_dependentservice->name2);
05071 
05072                                                 if(temp_servicedependency->dependent_host_name==NULL || temp_servicedependency->dependent_service_description==NULL){
05073                                                         xodtemplate_free_memberlist(&dependent_servicelist);
05074                                                         xodtemplate_free_memberlist(&dependent_hostlist);
05075                                                         return ERROR;
05076                                                         }
05077 
05078                                                 first_item=FALSE;
05079                                                 continue;
05080                                                 }
05081 
05082                                         /* duplicate service dependency definition */
05083                                         result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
05084 
05085                                         /* exit on error */
05086                                         if(result==ERROR){
05087                                                 xodtemplate_free_memberlist(&dependent_servicelist);
05088                                                 xodtemplate_free_memberlist(&dependent_hostlist);
05089                                                 return ERROR;
05090                                                 }
05091                                         }
05092 
05093                                 /* free memory we used for service list */
05094                                 xodtemplate_free_memberlist(&dependent_servicelist);
05095                                 }
05096 
05097                         /* free service descriptions */
05098                         my_free(service_descriptions);
05099 
05100                         /* free memory we used for host list */
05101                         xodtemplate_free_memberlist(&dependent_hostlist);
05102                         }
05103                 }
05104 
05105 
05106 #ifdef DEBUG_SERVICE_DEPENDENCIES
05107         printf("\n");
05108         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
05109                 printf("3**)  MAS: %s/%s  DEP: %s/%s\n",temp_servicedependency->host_name,temp_servicedependency->service_description,temp_servicedependency->dependent_host_name,temp_servicedependency->dependent_service_description);
05110                 }
05111 #endif
05112 
05113 
05114         /****** DUPLICATE HOSTEXTINFO DEFINITIONS WITH ONE OR MORE HOSTGROUP AND/OR HOST NAMES ******/
05115         for(temp_hostextinfo=xodtemplate_hostextinfo_list;temp_hostextinfo!=NULL;temp_hostextinfo=temp_hostextinfo->next){
05116 
05117                 /* skip definitions without enough data */
05118                 if(temp_hostextinfo->hostgroup_name==NULL && temp_hostextinfo->host_name==NULL)
05119                         continue;
05120 
05121                 /* get list of hosts */
05122                 master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_hostextinfo->hostgroup_name,temp_hostextinfo->host_name,temp_hostextinfo->_config_file,temp_hostextinfo->_start_line);
05123                 if(master_hostlist==NULL){
05124                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand hostgroups and/or hosts specified in extended host info (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostextinfo->_config_file),temp_hostextinfo->_start_line);
05125                         return ERROR;
05126                         }
05127 
05128                 /* add a copy of the definition for every host in the hostgroup/host name list */
05129                 first_item=TRUE;
05130                 for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
05131 
05132                         /* if this is the first duplication, use the existing entry */
05133                         if(first_item==TRUE){
05134 
05135                                 my_free(temp_hostextinfo->host_name);
05136                                 temp_hostextinfo->host_name=(char *)strdup(temp_masterhost->name1);
05137                                 if(temp_hostextinfo->host_name==NULL){
05138                                         xodtemplate_free_memberlist(&master_hostlist);
05139                                         return ERROR;
05140                                         }
05141                                 first_item=FALSE;
05142                                 continue;
05143                                 }
05144 
05145                         /* duplicate hostextinfo definition */
05146                         result=xodtemplate_duplicate_hostextinfo(temp_hostextinfo,temp_masterhost->name1);
05147 
05148                         /* exit on error */
05149                         if(result==ERROR){
05150                                 xodtemplate_free_memberlist(&master_hostlist);
05151                                 return ERROR;
05152                                 }
05153                         }
05154 
05155                 /* free memory we used for host list */
05156                 xodtemplate_free_memberlist(&master_hostlist);
05157                 }
05158 
05159 
05160         /****** DUPLICATE SERVICEEXTINFO DEFINITIONS WITH ONE OR MORE HOSTGROUP AND/OR HOST NAMES ******/
05161         for(temp_serviceextinfo=xodtemplate_serviceextinfo_list;temp_serviceextinfo!=NULL;temp_serviceextinfo=temp_serviceextinfo->next){
05162 
05163                 /* skip definitions without enough data */
05164                 if(temp_serviceextinfo->hostgroup_name==NULL && temp_serviceextinfo->host_name==NULL)
05165                         continue;
05166 
05167                 /* get list of hosts */
05168                 master_hostlist=xodtemplate_expand_hostgroups_and_hosts(temp_serviceextinfo->hostgroup_name,temp_serviceextinfo->host_name,temp_serviceextinfo->_config_file,temp_serviceextinfo->_start_line);
05169                 if(master_hostlist==NULL){
05170                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand hostgroups and/or hosts specified in extended service info (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_serviceextinfo->_config_file),temp_serviceextinfo->_start_line);
05171                         return ERROR;
05172                         }
05173 
05174                 /* add a copy of the definition for every host in the hostgroup/host name list */
05175                 first_item=TRUE;
05176                 for(temp_masterhost=master_hostlist;temp_masterhost!=NULL;temp_masterhost=temp_masterhost->next){
05177 
05178                         /* existing definition gets first host name */
05179                         if(first_item==TRUE){
05180                                 my_free(temp_serviceextinfo->host_name);
05181                                 temp_serviceextinfo->host_name=(char *)strdup(temp_masterhost->name1);
05182                                 if(temp_serviceextinfo->host_name==NULL){
05183                                         xodtemplate_free_memberlist(&master_hostlist);
05184                                         return ERROR;
05185                                         }
05186                                 first_item=FALSE;
05187                                 continue;
05188                                 }
05189 
05190                         /* duplicate serviceextinfo definition */
05191                         result=xodtemplate_duplicate_serviceextinfo(temp_serviceextinfo,temp_masterhost->name1);
05192 
05193                         /* exit on error */
05194                         if(result==ERROR){
05195                                 xodtemplate_free_memberlist(&master_hostlist);
05196                                 return ERROR;
05197                                 }
05198                         }
05199 
05200                 /* free memory we used for host list */
05201                 xodtemplate_free_memberlist(&master_hostlist);
05202                 }
05203 
05204 
05205         /***************************************/
05206         /* SKIPLIST STUFF FOR FAST SORT/SEARCH */
05207         /***************************************/
05208 
05209         /* host escalations */
05210         for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
05211 
05212                 /* skip escalations that shouldn't be registered */
05213                 if(temp_hostescalation->register_object==FALSE)
05214                         continue;
05215 
05216                 /* skip escalation definitions without enough data */
05217                 if(temp_hostescalation->host_name==NULL)
05218                         continue;
05219 
05220                 result=skiplist_insert(xobject_skiplists[X_HOSTESCALATION_SKIPLIST],(void *)temp_hostescalation);
05221                 switch(result){
05222                 case SKIPLIST_OK:
05223                         result=OK;
05224                         break;
05225                 default:
05226                         result=ERROR;
05227                         break;
05228                         }
05229                 }
05230 
05231         /* service escalations */
05232         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
05233 
05234                 /* skip escalations that shouldn't be registered */
05235                 if(temp_serviceescalation->register_object==FALSE)
05236                         continue;
05237 
05238                 /* skip escalation definitions without enough data */
05239                 if(temp_serviceescalation->host_name==NULL || temp_serviceescalation->service_description==NULL)
05240                         continue;
05241 
05242                 result=skiplist_insert(xobject_skiplists[X_SERVICEESCALATION_SKIPLIST],(void *)temp_serviceescalation);
05243                 switch(result){
05244                 case SKIPLIST_OK:
05245                         result=OK;
05246                         break;
05247                 default:
05248                         result=ERROR;
05249                         break;
05250                         }
05251                 }
05252 
05253         /* host dependencies */
05254         for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
05255 
05256                 /* skip dependencys that shouldn't be registered */
05257                 if(temp_hostdependency->register_object==FALSE)
05258                         continue;
05259 
05260                 /* skip dependency definitions without enough data */
05261                 if(temp_hostdependency->host_name==NULL)
05262                         continue;
05263 
05264                 result=skiplist_insert(xobject_skiplists[X_HOSTDEPENDENCY_SKIPLIST],(void *)temp_hostdependency);
05265                 switch(result){
05266                 case SKIPLIST_OK:
05267                         result=OK;
05268                         break;
05269                 default:
05270                         result=ERROR;
05271                         break;
05272                         }
05273                 }
05274 
05275         /* service dependencies */
05276         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
05277 
05278                 /* skip dependencys that shouldn't be registered */
05279                 if(temp_servicedependency->register_object==FALSE)
05280                         continue;
05281 
05282                 /* skip dependency definitions without enough data */
05283                 if(temp_servicedependency->dependent_host_name==NULL || temp_servicedependency->dependent_service_description==NULL)
05284                         continue;
05285 
05286                 result=skiplist_insert(xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],(void *)temp_servicedependency);
05287                 switch(result){
05288                 case SKIPLIST_OK:
05289                         result=OK;
05290                         break;
05291                 default:
05292                         result=ERROR;
05293                         break;
05294                         }
05295                 }
05296 
05297         /* host extinfo */
05298         /* NOT NEEDED */
05299 
05300         /* service extinfo */
05301         /* NOT NEEDED */
05302 
05303         return OK;
05304         }
05305 
05306 
05307 
05308 /* duplicates a service definition (with a new host name) */
05309 int xodtemplate_duplicate_service(xodtemplate_service *temp_service, char *host_name){
05310         xodtemplate_service *new_service=NULL;
05311         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
05312         int error=FALSE;
05313 
05314 
05315         /* allocate memory for a new service definition */
05316         new_service=(xodtemplate_service *)malloc(sizeof(xodtemplate_service));
05317         if(new_service==NULL)
05318                 return ERROR;
05319 
05320         /* standard items */
05321         new_service->template=NULL;
05322         new_service->name=NULL;
05323         new_service->has_been_resolved=temp_service->has_been_resolved;
05324         new_service->register_object=temp_service->register_object;
05325         new_service->_config_file=temp_service->_config_file;
05326         new_service->_start_line=temp_service->_start_line;
05327         /*tag service apply on host group*/
05328         xodtemplate_set_service_is_from_hostgroup(new_service);
05329 
05330         /* string defaults */
05331         new_service->hostgroup_name=NULL;
05332         new_service->have_hostgroup_name=temp_service->have_hostgroup_name;
05333         new_service->host_name=NULL;
05334         new_service->have_host_name=temp_service->have_host_name;
05335         new_service->service_description=NULL;
05336         new_service->have_service_description=temp_service->have_service_description;
05337         new_service->display_name=NULL;
05338         new_service->have_display_name=temp_service->have_display_name;
05339         new_service->service_groups=NULL;
05340         new_service->have_service_groups=temp_service->have_service_groups;
05341         new_service->check_command=NULL;
05342         new_service->have_check_command=temp_service->have_check_command;
05343         new_service->check_period=NULL;
05344         new_service->have_check_period=temp_service->have_check_period;
05345         new_service->event_handler=NULL;
05346         new_service->have_event_handler=temp_service->have_event_handler;
05347         new_service->notification_period=NULL;
05348         new_service->have_notification_period=temp_service->have_notification_period;
05349         new_service->contact_groups=NULL;
05350         new_service->have_contact_groups=temp_service->have_contact_groups;
05351         new_service->contacts=NULL;
05352         new_service->have_contacts=temp_service->have_contacts;
05353         new_service->failure_prediction_options=NULL;
05354         new_service->have_failure_prediction_options=temp_service->have_failure_prediction_options;
05355         new_service->notes=NULL;
05356         new_service->have_notes=temp_service->have_notes;
05357         new_service->notes_url=NULL;
05358         new_service->have_notes_url=temp_service->have_notes_url;
05359         new_service->action_url=NULL;
05360         new_service->have_action_url=temp_service->have_action_url;
05361         new_service->icon_image=NULL;
05362         new_service->have_icon_image=temp_service->have_icon_image;
05363         new_service->icon_image_alt=NULL;
05364         new_service->have_icon_image_alt=temp_service->have_icon_image_alt;
05365         new_service->custom_variables=NULL;
05366 
05367         /* make sure hostgroup member in new service definition is NULL */
05368         new_service->hostgroup_name=NULL;
05369 
05370         /* allocate memory for and copy string members of service definition (host name provided, DO NOT duplicate hostgroup member!)*/
05371         if(temp_service->host_name!=NULL && (new_service->host_name=(char *)strdup(host_name))==NULL)
05372                 error=TRUE;
05373         if(temp_service->template!=NULL && (new_service->template=(char *)strdup(temp_service->template))==NULL)
05374                 error=TRUE;
05375         if(temp_service->name!=NULL && (new_service->name=(char *)strdup(temp_service->name))==NULL)
05376                 error=TRUE;
05377         if(temp_service->service_description!=NULL && (new_service->service_description=(char *)strdup(temp_service->service_description))==NULL)
05378                 error=TRUE;
05379         if(temp_service->display_name!=NULL && (new_service->display_name=(char *)strdup(temp_service->display_name))==NULL)
05380                 error=TRUE;
05381         if(temp_service->service_groups!=NULL && (new_service->service_groups=(char *)strdup(temp_service->service_groups))==NULL)
05382                 error=TRUE;
05383         if(temp_service->check_command!=NULL && (new_service->check_command=(char *)strdup(temp_service->check_command))==NULL)
05384                 error=TRUE;
05385         if(temp_service->check_period!=NULL && (new_service->check_period=(char *)strdup(temp_service->check_period))==NULL)
05386                 error=TRUE;
05387         if(temp_service->event_handler!=NULL && (new_service->event_handler=(char *)strdup(temp_service->event_handler))==NULL)
05388                 error=TRUE;
05389         if(temp_service->notification_period!=NULL && (new_service->notification_period=(char *)strdup(temp_service->notification_period))==NULL)
05390                 error=TRUE;
05391         if(temp_service->contact_groups!=NULL && (new_service->contact_groups=(char *)strdup(temp_service->contact_groups))==NULL)
05392                 error=TRUE;
05393         if(temp_service->contacts!=NULL && (new_service->contacts=(char *)strdup(temp_service->contacts))==NULL)
05394                 error=TRUE;
05395         if(temp_service->failure_prediction_options!=NULL && (new_service->failure_prediction_options=(char *)strdup(temp_service->failure_prediction_options))==NULL)
05396                 error=TRUE;
05397         if(temp_service->notes!=NULL && (new_service->notes=(char *)strdup(temp_service->notes))==NULL)
05398                 error=TRUE;
05399         if(temp_service->notes_url!=NULL && (new_service->notes_url=(char *)strdup(temp_service->notes_url))==NULL)
05400                 error=TRUE;
05401         if(temp_service->action_url!=NULL && (new_service->action_url=(char *)strdup(temp_service->action_url))==NULL)
05402                 error=TRUE;
05403         if(temp_service->icon_image!=NULL && (new_service->icon_image=(char *)strdup(temp_service->icon_image))==NULL)
05404                 error=TRUE;
05405         if(temp_service->icon_image_alt!=NULL && (new_service->icon_image_alt=(char *)strdup(temp_service->icon_image_alt))==NULL)
05406                 error=TRUE;
05407 
05408         if(error==TRUE){
05409                 my_free(new_service->host_name);
05410                 my_free(new_service->template);
05411                 my_free(new_service->name);
05412                 my_free(new_service->service_description);
05413                 my_free(new_service->display_name);
05414                 my_free(new_service->service_groups);
05415                 my_free(new_service->check_command);
05416                 my_free(new_service->check_period);
05417                 my_free(new_service->event_handler);
05418                 my_free(new_service->notification_period);
05419                 my_free(new_service->contact_groups);
05420                 my_free(new_service->contacts);
05421                 my_free(new_service->failure_prediction_options);
05422                 my_free(new_service->notes);
05423                 my_free(new_service->notes_url);
05424                 my_free(new_service->action_url);
05425                 my_free(new_service->icon_image);
05426                 my_free(new_service->icon_image_alt);
05427                 my_free(new_service);
05428                 return ERROR;
05429                 }
05430 
05431         /* duplicate custom variables */
05432         for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next)
05433                 xodtemplate_add_custom_variable_to_service(new_service,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value);
05434 
05435         /* duplicate non-string members */
05436         new_service->initial_state=temp_service->initial_state;
05437         new_service->max_check_attempts=temp_service->max_check_attempts;
05438         new_service->have_max_check_attempts=temp_service->have_max_check_attempts;
05439         new_service->check_interval=temp_service->check_interval;
05440         new_service->have_check_interval=temp_service->have_check_interval;
05441         new_service->retry_interval=temp_service->retry_interval;
05442         new_service->have_retry_interval=temp_service->have_retry_interval;
05443         new_service->active_checks_enabled=temp_service->active_checks_enabled;
05444         new_service->have_active_checks_enabled=temp_service->have_active_checks_enabled;
05445         new_service->passive_checks_enabled=temp_service->passive_checks_enabled;
05446         new_service->have_passive_checks_enabled=temp_service->have_passive_checks_enabled;
05447         new_service->parallelize_check=temp_service->parallelize_check;
05448         new_service->have_parallelize_check=temp_service->have_parallelize_check;
05449         new_service->is_volatile=temp_service->is_volatile;
05450         new_service->have_is_volatile=temp_service->have_is_volatile;
05451         new_service->obsess_over_service=temp_service->obsess_over_service;
05452         new_service->have_obsess_over_service=temp_service->have_obsess_over_service;
05453         new_service->event_handler_enabled=temp_service->event_handler_enabled;
05454         new_service->have_event_handler_enabled=temp_service->have_event_handler_enabled;
05455         new_service->check_freshness=temp_service->check_freshness;
05456         new_service->have_check_freshness=temp_service->have_check_freshness;
05457         new_service->freshness_threshold=temp_service->freshness_threshold;
05458         new_service->have_freshness_threshold=temp_service->have_freshness_threshold;
05459         new_service->flap_detection_enabled=temp_service->flap_detection_enabled;
05460         new_service->have_flap_detection_enabled=temp_service->have_flap_detection_enabled;
05461         new_service->low_flap_threshold=temp_service->low_flap_threshold;
05462         new_service->have_low_flap_threshold=temp_service->have_low_flap_threshold;
05463         new_service->high_flap_threshold=temp_service->high_flap_threshold;
05464         new_service->have_high_flap_threshold=temp_service->have_high_flap_threshold;
05465         new_service->flap_detection_on_ok=temp_service->flap_detection_on_ok;
05466         new_service->flap_detection_on_warning=temp_service->flap_detection_on_warning;
05467         new_service->flap_detection_on_unknown=temp_service->flap_detection_on_unknown;
05468         new_service->flap_detection_on_critical=temp_service->flap_detection_on_critical;
05469         new_service->have_flap_detection_options=temp_service->have_flap_detection_options;
05470         new_service->notify_on_unknown=temp_service->notify_on_unknown;
05471         new_service->notify_on_warning=temp_service->notify_on_warning;
05472         new_service->notify_on_critical=temp_service->notify_on_critical;
05473         new_service->notify_on_recovery=temp_service->notify_on_recovery;
05474         new_service->notify_on_flapping=temp_service->notify_on_flapping;
05475         new_service->notify_on_downtime=temp_service->notify_on_downtime;
05476         new_service->have_notification_options=temp_service->have_notification_options;
05477         new_service->notifications_enabled=temp_service->notifications_enabled;
05478         new_service->have_notifications_enabled=temp_service->have_notifications_enabled;
05479         new_service->notification_interval=temp_service->notification_interval;
05480         new_service->have_notification_interval=temp_service->have_notification_interval;
05481         new_service->first_notification_delay=temp_service->first_notification_delay;
05482         new_service->have_first_notification_delay=temp_service->have_first_notification_delay;
05483         new_service->stalk_on_ok=temp_service->stalk_on_ok;
05484         new_service->stalk_on_unknown=temp_service->stalk_on_unknown;
05485         new_service->stalk_on_warning=temp_service->stalk_on_warning;
05486         new_service->stalk_on_critical=temp_service->stalk_on_critical;
05487         new_service->have_stalking_options=temp_service->have_stalking_options;
05488         new_service->process_perf_data=temp_service->process_perf_data;
05489         new_service->have_process_perf_data=temp_service->have_process_perf_data;
05490         new_service->failure_prediction_enabled=temp_service->failure_prediction_enabled;
05491         new_service->have_failure_prediction_enabled=temp_service->have_failure_prediction_enabled;
05492         new_service->retain_status_information=temp_service->retain_status_information;
05493         new_service->have_retain_status_information=temp_service->have_retain_status_information;
05494         new_service->retain_nonstatus_information=temp_service->retain_nonstatus_information;
05495         new_service->have_retain_nonstatus_information=temp_service->have_retain_nonstatus_information;
05496 
05497         /* add new service to head of list in memory */
05498         new_service->next=xodtemplate_service_list;
05499         xodtemplate_service_list=new_service;
05500 
05501         return OK;
05502         }
05503 
05504 
05505 
05506 
05507 /* duplicates a host escalation definition (with a new host name) */
05508 int xodtemplate_duplicate_hostescalation(xodtemplate_hostescalation *temp_hostescalation, char *host_name){
05509         xodtemplate_hostescalation *new_hostescalation=NULL;
05510         xodtemplate_escalation_condition *temp_escalationcondition=NULL;
05511         xodtemplate_escalation_condition *new_escalationcondition=NULL;
05512         xodtemplate_escalation_condition *new_escalationcondition_tail=NULL;
05513         int error=FALSE;
05514 
05515 
05516         /* allocate memory for a new host escalation definition */
05517         new_hostescalation=(xodtemplate_hostescalation *)malloc(sizeof(xodtemplate_hostescalation));
05518         if(new_hostescalation==NULL)
05519                 return ERROR;
05520 
05521         /* standard items */
05522         new_hostescalation->template=NULL;
05523         new_hostescalation->name=NULL;
05524         new_hostescalation->has_been_resolved=temp_hostescalation->has_been_resolved;
05525         new_hostescalation->register_object=temp_hostescalation->register_object;
05526         new_hostescalation->_config_file=temp_hostescalation->_config_file;
05527         new_hostescalation->_start_line=temp_hostescalation->_start_line;
05528 
05529         /* string defaults */
05530         new_hostescalation->hostgroup_name=NULL;
05531         new_hostescalation->have_hostgroup_name=temp_hostescalation->have_hostgroup_name;
05532         new_hostescalation->host_name=NULL;
05533         new_hostescalation->have_host_name=(host_name)?TRUE:FALSE;
05534         new_hostescalation->contact_groups=NULL;
05535         new_hostescalation->have_contact_groups=temp_hostescalation->have_contact_groups;
05536         new_hostescalation->contacts=NULL;
05537         new_hostescalation->have_contacts=temp_hostescalation->have_contacts;
05538         new_hostescalation->escalation_period=NULL;
05539         new_hostescalation->have_escalation_period=temp_hostescalation->have_escalation_period;
05540 
05541         /* allocate memory for and copy string members of hostescalation definition */
05542         if(host_name!=NULL && (new_hostescalation->host_name=(char *)strdup(host_name))==NULL)
05543                 error=TRUE;
05544 
05545         if(temp_hostescalation->template!=NULL && (new_hostescalation->template=(char *)strdup(temp_hostescalation->template))==NULL)
05546                 error=TRUE;
05547         if(temp_hostescalation->name!=NULL && (new_hostescalation->name=(char *)strdup(temp_hostescalation->name))==NULL)
05548                 error=TRUE;
05549         if(temp_hostescalation->contact_groups!=NULL && (new_hostescalation->contact_groups=(char *)strdup(temp_hostescalation->contact_groups))==NULL)
05550                 error=TRUE;
05551         if(temp_hostescalation->contacts!=NULL && (new_hostescalation->contacts=(char *)strdup(temp_hostescalation->contacts))==NULL)
05552                 error=TRUE;
05553         if(temp_hostescalation->escalation_period!=NULL && (new_hostescalation->escalation_period=(char *)strdup(temp_hostescalation->escalation_period))==NULL)
05554                 error=TRUE;
05555 
05556         if(error==TRUE){
05557                 my_free(new_hostescalation->escalation_period);
05558                 my_free(new_hostescalation->contact_groups);
05559                 my_free(new_hostescalation->contacts);
05560                 my_free(new_hostescalation->host_name);
05561                 my_free(new_hostescalation->template);
05562                 my_free(new_hostescalation->name);
05563                 my_free(new_hostescalation);
05564                 return ERROR;
05565                 }
05566 
05567         /* duplicate non-string members */
05568         new_hostescalation->first_notification=temp_hostescalation->first_notification;
05569         new_hostescalation->last_notification=temp_hostescalation->last_notification;
05570 #ifdef USE_ST_BASED_ESCAL_RANGES
05571         new_hostescalation->first_down_notification=temp_hostescalation->first_down_notification;
05572         new_hostescalation->last_down_notification=temp_hostescalation->last_down_notification;
05573         new_hostescalation->first_unreachable_notification=temp_hostescalation->first_unreachable_notification;
05574         new_hostescalation->last_unreachable_notification=temp_hostescalation->last_unreachable_notification;
05575 #endif
05576         new_hostescalation->have_first_notification=temp_hostescalation->have_first_notification;
05577         new_hostescalation->have_last_notification=temp_hostescalation->have_last_notification;
05578 #ifdef USE_ST_BASED_ESCAL_RANGES
05579         new_hostescalation->have_first_down_notification=temp_hostescalation->have_first_down_notification;
05580         new_hostescalation->have_last_down_notification=temp_hostescalation->have_last_down_notification;
05581         new_hostescalation->have_first_unreachable_notification=temp_hostescalation->have_first_unreachable_notification;
05582         new_hostescalation->have_last_unreachable_notification=temp_hostescalation->have_last_unreachable_notification;
05583 #endif
05584         new_hostescalation->notification_interval=temp_hostescalation->notification_interval;
05585         new_hostescalation->have_notification_interval=temp_hostescalation->have_notification_interval;
05586         new_hostescalation->escalate_on_down=temp_hostescalation->escalate_on_down;
05587         new_hostescalation->escalate_on_unreachable=temp_hostescalation->escalate_on_unreachable;
05588         new_hostescalation->escalate_on_recovery=temp_hostescalation->escalate_on_recovery;
05589         new_hostescalation->have_escalation_options=temp_hostescalation->have_escalation_options;
05590 
05591         
05592         /* duplicate escalation conditions */
05593         new_hostescalation->condition=NULL;
05594         for(temp_escalationcondition=temp_hostescalation->condition;temp_escalationcondition!=NULL;temp_escalationcondition=temp_escalationcondition->next){
05595                 /* skip escalation conditions without enough data */
05596                 if(temp_escalationcondition->host_name==NULL)
05597                         continue;
05598                 
05599                 /* allocate memory for a new escalation condition */
05600                 new_escalationcondition=(xodtemplate_escalation_condition *)malloc(sizeof(xodtemplate_escalation_condition));
05601                 if(new_escalationcondition==NULL)
05602                         return ERROR;
05603                 
05604                 /* string defaults */
05605                 new_escalationcondition->next=NULL;
05606                 new_escalationcondition->host_name=NULL;
05607                 new_escalationcondition->service_description=NULL;
05608                 
05609                 /* allocate memory for and copy string members of serviceescalation definition */
05610                 if(temp_escalationcondition->host_name!=NULL && (new_escalationcondition->host_name=(char *)strdup(temp_escalationcondition->host_name))==NULL)
05611                         error=TRUE;
05612                 if(temp_escalationcondition->service_description!=NULL && (new_escalationcondition->service_description=(char *)strdup(temp_escalationcondition->service_description))==NULL)
05613                         error=TRUE;
05614                 
05615                 if(error==TRUE){
05616                         my_free(new_escalationcondition->host_name);
05617                         my_free(new_escalationcondition->service_description);
05618                         my_free(new_escalationcondition);
05619                         return ERROR;
05620                 }
05621                 
05622                 /* duplicate non-string members */
05623                 new_escalationcondition->escalate_on_critical=temp_escalationcondition->escalate_on_critical;
05624                 new_escalationcondition->escalate_on_down=temp_escalationcondition->escalate_on_down;
05625                 new_escalationcondition->escalate_on_ok=temp_escalationcondition->escalate_on_ok;
05626                 new_escalationcondition->escalate_on_unknown=temp_escalationcondition->escalate_on_unknown;
05627                 new_escalationcondition->escalate_on_unreachable=temp_escalationcondition->escalate_on_unreachable;
05628                 new_escalationcondition->escalate_on_warning=temp_escalationcondition->escalate_on_warning;
05629                 new_escalationcondition->connector=temp_escalationcondition->connector;
05630                 
05631                 /* first escalation condition is head of the condition list */
05632                 if(new_hostescalation->condition==NULL){
05633                         new_hostescalation->condition=new_escalationcondition;
05634                 }
05635                 /* add new escalation condition to tail of list */
05636                 else {
05637                         new_escalationcondition_tail->next=new_escalationcondition;
05638                 }
05639                 new_escalationcondition_tail=new_escalationcondition;           
05640         }
05641 
05642         /* add new hostescalation to head of list in memory */
05643         new_hostescalation->next=xodtemplate_hostescalation_list;
05644         xodtemplate_hostescalation_list=new_hostescalation;
05645 
05646         return OK;
05647         }
05648 
05649 
05650 
05651 /* duplicates a service escalation definition (with a new host name and/or service description) */
05652 int xodtemplate_duplicate_serviceescalation(xodtemplate_serviceescalation *temp_serviceescalation, char *host_name, char *svc_description){
05653         xodtemplate_serviceescalation *new_serviceescalation=NULL;
05654         xodtemplate_escalation_condition *temp_escalationcondition=NULL;
05655         xodtemplate_escalation_condition *new_escalationcondition=NULL;
05656         xodtemplate_escalation_condition *new_escalationcondition_tail=NULL;
05657         int error=FALSE;
05658 
05659         /* allocate memory for a new service escalation definition */
05660         new_serviceescalation=(xodtemplate_serviceescalation *)malloc(sizeof(xodtemplate_serviceescalation));
05661         if(new_serviceescalation==NULL)
05662                 return ERROR;
05663 
05664         /* standard items */
05665         new_serviceescalation->template=NULL;
05666         new_serviceescalation->name=NULL;
05667         new_serviceescalation->has_been_resolved=temp_serviceescalation->has_been_resolved;
05668         new_serviceescalation->register_object=temp_serviceescalation->register_object;
05669         new_serviceescalation->_config_file=temp_serviceescalation->_config_file;
05670         new_serviceescalation->_start_line=temp_serviceescalation->_start_line;
05671 
05672         /* string defaults */
05673         new_serviceescalation->servicegroup_name=NULL;
05674         new_serviceescalation->have_servicegroup_name=FALSE;
05675         new_serviceescalation->hostgroup_name=NULL;
05676         new_serviceescalation->have_hostgroup_name=FALSE;
05677         new_serviceescalation->host_name=NULL;
05678         new_serviceescalation->have_host_name=(host_name)?TRUE:FALSE;
05679         new_serviceescalation->service_description=NULL;
05680         new_serviceescalation->have_service_description=(svc_description)?TRUE:FALSE;
05681         new_serviceescalation->contact_groups=NULL;
05682         new_serviceescalation->have_contact_groups=temp_serviceescalation->have_contact_groups;
05683         new_serviceescalation->contacts=NULL;
05684         new_serviceescalation->have_contacts=temp_serviceescalation->have_contacts;
05685         new_serviceescalation->escalation_period=NULL;
05686         new_serviceescalation->have_escalation_period=temp_serviceescalation->have_escalation_period;
05687 
05688         /* allocate memory for and copy string members of serviceescalation definition */
05689         if(host_name!=NULL && (new_serviceescalation->host_name=(char *)strdup(host_name))==NULL)
05690                 error=TRUE;
05691         if(svc_description!=NULL && (new_serviceescalation->service_description=(char *)strdup(svc_description))==NULL)
05692                 error=TRUE;
05693 
05694         if(temp_serviceescalation->template!=NULL && (new_serviceescalation->template=(char *)strdup(temp_serviceescalation->template))==NULL)
05695                 error=TRUE;
05696         if(temp_serviceescalation->name!=NULL && (new_serviceescalation->name=(char *)strdup(temp_serviceescalation->name))==NULL)
05697                 error=TRUE;
05698         if(temp_serviceescalation->contact_groups!=NULL && (new_serviceescalation->contact_groups=(char *)strdup(temp_serviceescalation->contact_groups))==NULL)
05699                 error=TRUE;
05700         if(temp_serviceescalation->contacts!=NULL && (new_serviceescalation->contacts=(char *)strdup(temp_serviceescalation->contacts))==NULL)
05701                 error=TRUE;
05702         if(temp_serviceescalation->escalation_period!=NULL && (new_serviceescalation->escalation_period=(char *)strdup(temp_serviceescalation->escalation_period))==NULL)
05703                 error=TRUE;
05704 
05705         if(error==TRUE){
05706                 my_free(new_serviceescalation->host_name);
05707                 my_free(new_serviceescalation->service_description);
05708                 my_free(new_serviceescalation->contact_groups);
05709                 my_free(new_serviceescalation->contacts);
05710                 my_free(new_serviceescalation->escalation_period);
05711                 my_free(new_serviceescalation->template);
05712                 my_free(new_serviceescalation->name);
05713                 my_free(new_serviceescalation);
05714                 return ERROR;
05715                 }
05716 
05717         /* duplicate non-string members */
05718         new_serviceescalation->first_notification=temp_serviceescalation->first_notification;
05719         new_serviceescalation->last_notification=temp_serviceescalation->last_notification;
05720 #ifdef USE_ST_BASED_ESCAL_RANGES
05721         new_serviceescalation->first_warning_notification=temp_serviceescalation->first_warning_notification;
05722         new_serviceescalation->last_warning_notification=temp_serviceescalation->last_warning_notification;
05723         new_serviceescalation->first_critical_notification=temp_serviceescalation->first_critical_notification;
05724         new_serviceescalation->last_critical_notification=temp_serviceescalation->last_critical_notification;
05725         new_serviceescalation->first_unknown_notification=temp_serviceescalation->first_unknown_notification;
05726         new_serviceescalation->last_unknown_notification=temp_serviceescalation->last_unknown_notification;
05727 #endif
05728         new_serviceescalation->have_first_notification=temp_serviceescalation->have_first_notification;
05729         new_serviceescalation->have_last_notification=temp_serviceescalation->have_last_notification;
05730 #ifdef USE_ST_BASED_ESCAL_RANGES
05731         new_serviceescalation->have_first_warning_notification=temp_serviceescalation->have_first_warning_notification;
05732         new_serviceescalation->have_last_warning_notification=temp_serviceescalation->have_last_warning_notification;
05733         new_serviceescalation->have_first_critical_notification=temp_serviceescalation->have_first_critical_notification;
05734         new_serviceescalation->have_last_critical_notification=temp_serviceescalation->have_last_critical_notification;
05735         new_serviceescalation->have_first_unknown_notification=temp_serviceescalation->have_first_unknown_notification;
05736         new_serviceescalation->have_last_unknown_notification=temp_serviceescalation->have_last_unknown_notification;
05737 #endif
05738         new_serviceescalation->notification_interval=temp_serviceescalation->notification_interval;
05739         new_serviceescalation->have_notification_interval=temp_serviceescalation->have_notification_interval;
05740         new_serviceescalation->escalate_on_warning=temp_serviceescalation->escalate_on_warning;
05741         new_serviceescalation->escalate_on_unknown=temp_serviceescalation->escalate_on_unknown;
05742         new_serviceescalation->escalate_on_critical=temp_serviceescalation->escalate_on_critical;
05743         new_serviceescalation->escalate_on_recovery=temp_serviceescalation->escalate_on_recovery;
05744         new_serviceescalation->have_escalation_options=temp_serviceescalation->have_escalation_options;
05745 
05746         /* duplicate escalation conditions */
05747         new_serviceescalation->condition=NULL;
05748         for(temp_escalationcondition=temp_serviceescalation->condition;temp_escalationcondition!=NULL;temp_escalationcondition=temp_escalationcondition->next){
05749  
05750                 /* skip escalation conditions without enough data */
05751                 if(temp_escalationcondition->host_name==NULL)
05752                         continue;
05753  
05754                 /* allocate memory for a new escalation condition */
05755                 new_escalationcondition=(xodtemplate_escalation_condition *)malloc(sizeof(xodtemplate_escalation_condition));
05756                 if(new_escalationcondition==NULL)
05757                         return ERROR;
05758  
05759                 /* string defaults */
05760                 new_escalationcondition->next=NULL;
05761                 new_escalationcondition->host_name=NULL;
05762                 new_escalationcondition->service_description=NULL;
05763  
05764                 /* allocate memory for and copy string members of serviceescalation definition */
05765                 if(temp_escalationcondition->host_name!=NULL && (new_escalationcondition->host_name=(char *)strdup(temp_escalationcondition->host_name))==NULL)
05766                         error=TRUE;
05767                 if(temp_escalationcondition->service_description!=NULL && (new_escalationcondition->service_description=(char *)strdup(temp_escalationcondition->service_description))==NULL)
05768                         error=TRUE;
05769  
05770                 if(error==TRUE){
05771                         my_free(new_escalationcondition->host_name);
05772                         my_free(new_escalationcondition->service_description);
05773                         my_free(new_escalationcondition);
05774                         return ERROR;
05775                 }
05776                 
05777                 /* duplicate non-string members */
05778                 new_escalationcondition->escalate_on_critical=temp_escalationcondition->escalate_on_critical;
05779                 new_escalationcondition->escalate_on_down=temp_escalationcondition->escalate_on_down;
05780                 new_escalationcondition->escalate_on_ok=temp_escalationcondition->escalate_on_ok;
05781                 new_escalationcondition->escalate_on_unknown=temp_escalationcondition->escalate_on_unknown;
05782                 new_escalationcondition->escalate_on_unreachable=temp_escalationcondition->escalate_on_unreachable;
05783                 new_escalationcondition->escalate_on_warning=temp_escalationcondition->escalate_on_warning;
05784                 new_escalationcondition->connector=temp_escalationcondition->connector;
05785                 
05786                 /* first escalation condition is head of the condition list */
05787                 if(new_serviceescalation->condition==NULL){
05788                         new_serviceescalation->condition=new_escalationcondition;
05789                 }
05790                 /* add new escalation condition to tail of list */
05791                 else {
05792                         new_escalationcondition_tail->next=new_escalationcondition;
05793                 }
05794                 new_escalationcondition_tail=new_escalationcondition;
05795         }
05796 
05797         
05798         /* add new serviceescalation to head of list in memory */
05799         new_serviceescalation->next=xodtemplate_serviceescalation_list;
05800         xodtemplate_serviceescalation_list=new_serviceescalation;
05801 
05802         return OK;
05803         }
05804 
05805 
05806 
05807 /* duplicates a host dependency definition (with master and dependent host names) */
05808 int xodtemplate_duplicate_hostdependency(xodtemplate_hostdependency *temp_hostdependency, char *master_host_name, char *dependent_host_name){
05809         xodtemplate_hostdependency *new_hostdependency=NULL;
05810         int error=FALSE;
05811 
05812         /* allocate memory for a new host dependency definition */
05813         new_hostdependency=(xodtemplate_hostdependency *)malloc(sizeof(xodtemplate_hostdependency));
05814         if(new_hostdependency==NULL)
05815                 return ERROR;
05816 
05817         /* standard items */
05818         new_hostdependency->template=NULL;
05819         new_hostdependency->name=NULL;
05820         new_hostdependency->has_been_resolved=temp_hostdependency->has_been_resolved;
05821         new_hostdependency->register_object=temp_hostdependency->register_object;
05822         new_hostdependency->_config_file=temp_hostdependency->_config_file;
05823         new_hostdependency->_start_line=temp_hostdependency->_start_line;
05824 
05825         /* string defaults */
05826         new_hostdependency->hostgroup_name=NULL;
05827         new_hostdependency->have_hostgroup_name=FALSE;
05828         new_hostdependency->dependent_hostgroup_name=NULL;
05829         new_hostdependency->have_dependent_hostgroup_name=FALSE;
05830         new_hostdependency->host_name=NULL;
05831         new_hostdependency->have_host_name=temp_hostdependency->have_host_name;
05832         new_hostdependency->dependent_host_name=NULL;
05833         new_hostdependency->have_dependent_host_name=temp_hostdependency->have_dependent_host_name;
05834         new_hostdependency->dependency_period=NULL;
05835         new_hostdependency->have_dependency_period=temp_hostdependency->have_dependency_period;
05836 
05837         /* allocate memory for and copy string members of hostdependency definition */
05838         if(master_host_name!=NULL && (new_hostdependency->host_name=(char *)strdup(master_host_name))==NULL)
05839                 error=TRUE;
05840         if(dependent_host_name!=NULL && (new_hostdependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
05841                 error=TRUE;
05842 
05843         if(temp_hostdependency->dependency_period!=NULL && (new_hostdependency->dependency_period=(char *)strdup(temp_hostdependency->dependency_period))==NULL)
05844                 error=TRUE;
05845         if(temp_hostdependency->template!=NULL && (new_hostdependency->template=(char *)strdup(temp_hostdependency->template))==NULL)
05846                 error=TRUE;
05847         if(temp_hostdependency->name!=NULL && (new_hostdependency->name=(char *)strdup(temp_hostdependency->name))==NULL)
05848                 error=TRUE;
05849 
05850         if(error==TRUE){
05851                 my_free(new_hostdependency->dependent_host_name);
05852                 my_free(new_hostdependency->host_name);
05853                 my_free(new_hostdependency->template);
05854                 my_free(new_hostdependency->name);
05855                 my_free(new_hostdependency);
05856                 return ERROR;
05857                 } 
05858 
05859         /* duplicate non-string members */
05860         new_hostdependency->fail_notify_on_up=temp_hostdependency->fail_notify_on_up;
05861         new_hostdependency->fail_notify_on_down=temp_hostdependency->fail_notify_on_down;
05862         new_hostdependency->fail_notify_on_unreachable=temp_hostdependency->fail_notify_on_unreachable;
05863         new_hostdependency->fail_notify_on_pending=temp_hostdependency->fail_notify_on_pending;
05864         new_hostdependency->have_notification_dependency_options=temp_hostdependency->have_notification_dependency_options;
05865         new_hostdependency->fail_execute_on_up=temp_hostdependency->fail_execute_on_up;
05866         new_hostdependency->fail_execute_on_down=temp_hostdependency->fail_execute_on_down;
05867         new_hostdependency->fail_execute_on_unreachable=temp_hostdependency->fail_execute_on_unreachable;
05868         new_hostdependency->fail_execute_on_pending=temp_hostdependency->fail_execute_on_pending;
05869         new_hostdependency->have_execution_dependency_options=temp_hostdependency->have_execution_dependency_options;
05870         new_hostdependency->inherits_parent=temp_hostdependency->inherits_parent;
05871         new_hostdependency->have_inherits_parent=temp_hostdependency->have_inherits_parent;
05872 
05873         /* add new hostdependency to head of list in memory */
05874         new_hostdependency->next=xodtemplate_hostdependency_list;
05875         xodtemplate_hostdependency_list=new_hostdependency;
05876 
05877         return OK;
05878         }
05879 
05880 
05881 
05882 /* duplicates a service dependency definition */
05883 int xodtemplate_duplicate_servicedependency(xodtemplate_servicedependency *temp_servicedependency, char *master_host_name, char *master_service_description, char *master_hostgroup_name, char *master_servicegroup_name, char *dependent_host_name, char *dependent_service_description, char *dependent_hostgroup_name, char *dependent_servicegroup_name){
05884         xodtemplate_servicedependency *new_servicedependency=NULL;
05885         int error=FALSE;
05886 
05887         /* allocate memory for a new service dependency definition */
05888         new_servicedependency=(xodtemplate_servicedependency *)malloc(sizeof(xodtemplate_servicedependency));
05889         if(new_servicedependency==NULL)
05890                 return ERROR;
05891 
05892         /* standard items */
05893         new_servicedependency->template=NULL;
05894         new_servicedependency->name=NULL;
05895         new_servicedependency->has_been_resolved=temp_servicedependency->has_been_resolved;
05896         new_servicedependency->register_object=temp_servicedependency->register_object;
05897         new_servicedependency->_config_file=temp_servicedependency->_config_file;
05898         new_servicedependency->_start_line=temp_servicedependency->_start_line;
05899 
05900         /* string defaults */
05901         new_servicedependency->host_name=NULL;
05902         new_servicedependency->have_host_name=(master_host_name)?TRUE:FALSE;
05903         new_servicedependency->service_description=NULL;
05904         new_servicedependency->have_service_description=(master_service_description)?TRUE:FALSE;
05905         new_servicedependency->hostgroup_name=NULL;
05906         new_servicedependency->have_hostgroup_name=(master_hostgroup_name)?TRUE:FALSE;
05907         new_servicedependency->servicegroup_name=NULL;
05908         new_servicedependency->have_servicegroup_name=(master_servicegroup_name)?TRUE:FALSE;
05909 
05910         new_servicedependency->dependent_host_name=NULL;
05911         new_servicedependency->have_dependent_host_name=(dependent_host_name)?TRUE:FALSE;
05912         new_servicedependency->dependent_service_description=NULL;
05913         new_servicedependency->have_dependent_service_description=(dependent_service_description)?TRUE:FALSE;
05914         new_servicedependency->dependent_hostgroup_name=NULL;
05915         new_servicedependency->have_dependent_hostgroup_name=(dependent_hostgroup_name)?TRUE:FALSE;
05916         new_servicedependency->dependent_servicegroup_name=NULL;
05917         new_servicedependency->have_dependent_servicegroup_name=(dependent_servicegroup_name)?TRUE:FALSE;
05918 
05919         new_servicedependency->dependency_period=NULL;
05920         new_servicedependency->have_dependency_period=temp_servicedependency->have_dependency_period;
05921         new_servicedependency->service_description=NULL;
05922         new_servicedependency->dependent_service_description=NULL;
05923 
05924         /* duplicate strings */
05925         if(master_host_name!=NULL && (new_servicedependency->host_name=(char *)strdup(master_host_name))==NULL)
05926                 error=TRUE;
05927         if(master_service_description!=NULL && (new_servicedependency->service_description=(char *)strdup(master_service_description))==NULL)
05928                 error=TRUE;
05929         if(master_hostgroup_name!=NULL && (new_servicedependency->hostgroup_name=(char *)strdup(master_hostgroup_name))==NULL)
05930                 error=TRUE;
05931         if(master_servicegroup_name!=NULL && (new_servicedependency->servicegroup_name=(char *)strdup(master_servicegroup_name))==NULL)
05932                 error=TRUE;
05933         if(dependent_host_name!=NULL && (new_servicedependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
05934                 error=TRUE;
05935         if(dependent_service_description!=NULL && (new_servicedependency->dependent_service_description=(char *)strdup(dependent_service_description))==NULL)
05936                 error=TRUE;
05937         if(dependent_hostgroup_name!=NULL && (new_servicedependency->dependent_hostgroup_name=(char *)strdup(dependent_hostgroup_name))==NULL)
05938                 error=TRUE;
05939         if(dependent_servicegroup_name!=NULL && (new_servicedependency->dependent_servicegroup_name=(char *)strdup(dependent_servicegroup_name))==NULL)
05940                 error=TRUE;
05941 
05942         if(temp_servicedependency->dependency_period!=NULL && (new_servicedependency->dependency_period=(char *)strdup(temp_servicedependency->dependency_period))==NULL)
05943                 error=TRUE;
05944         if(temp_servicedependency->template!=NULL && (new_servicedependency->template=(char *)strdup(temp_servicedependency->template))==NULL)
05945                 error=TRUE;
05946         if(temp_servicedependency->name!=NULL && (new_servicedependency->name=(char *)strdup(temp_servicedependency->name))==NULL)
05947                 error=TRUE;
05948 
05949         if(error==TRUE){
05950                 my_free(new_servicedependency->host_name);
05951                 my_free(new_servicedependency->service_description);
05952                 my_free(new_servicedependency->hostgroup_name);
05953                 my_free(new_servicedependency->servicegroup_name);
05954                 my_free(new_servicedependency->dependent_host_name);
05955                 my_free(new_servicedependency->dependent_service_description);
05956                 my_free(new_servicedependency->dependent_hostgroup_name);
05957                 my_free(new_servicedependency->dependent_servicegroup_name);
05958                 my_free(new_servicedependency->dependency_period);
05959                 my_free(new_servicedependency->template);
05960                 my_free(new_servicedependency->name);
05961                 my_free(new_servicedependency);
05962                 return ERROR;
05963                 } 
05964 
05965         /* duplicate non-string members */
05966         new_servicedependency->fail_notify_on_ok=temp_servicedependency->fail_notify_on_ok;
05967         new_servicedependency->fail_notify_on_unknown=temp_servicedependency->fail_notify_on_unknown;
05968         new_servicedependency->fail_notify_on_warning=temp_servicedependency->fail_notify_on_warning;
05969         new_servicedependency->fail_notify_on_critical=temp_servicedependency->fail_notify_on_critical;
05970         new_servicedependency->fail_notify_on_pending=temp_servicedependency->fail_notify_on_pending;
05971         new_servicedependency->have_notification_dependency_options=temp_servicedependency->have_notification_dependency_options;
05972         new_servicedependency->fail_execute_on_ok=temp_servicedependency->fail_execute_on_ok;
05973         new_servicedependency->fail_execute_on_unknown=temp_servicedependency->fail_execute_on_unknown;
05974         new_servicedependency->fail_execute_on_warning=temp_servicedependency->fail_execute_on_warning;
05975         new_servicedependency->fail_execute_on_critical=temp_servicedependency->fail_execute_on_critical;
05976         new_servicedependency->fail_execute_on_pending=temp_servicedependency->fail_execute_on_pending;
05977         new_servicedependency->have_execution_dependency_options=temp_servicedependency->have_execution_dependency_options;
05978         new_servicedependency->inherits_parent=temp_servicedependency->inherits_parent;
05979         new_servicedependency->have_inherits_parent=temp_servicedependency->have_inherits_parent;
05980         
05981         /* add new servicedependency to head of list in memory */
05982         new_servicedependency->next=xodtemplate_servicedependency_list;
05983         xodtemplate_servicedependency_list=new_servicedependency;
05984 
05985         return OK;
05986         }
05987 
05988 
05989 
05990 /* duplicates a hostextinfo object definition */
05991 int xodtemplate_duplicate_hostextinfo(xodtemplate_hostextinfo *this_hostextinfo, char *host_name){
05992         xodtemplate_hostextinfo *new_hostextinfo=NULL;
05993         int error=FALSE;
05994 
05995         new_hostextinfo=(xodtemplate_hostextinfo *)malloc(sizeof(xodtemplate_hostextinfo));
05996         if(new_hostextinfo==NULL)
05997                 return ERROR;
05998 
05999         /* standard items */
06000         new_hostextinfo->template=NULL;
06001         new_hostextinfo->name=NULL;
06002         new_hostextinfo->has_been_resolved=this_hostextinfo->has_been_resolved;
06003         new_hostextinfo->register_object=this_hostextinfo->register_object;
06004         new_hostextinfo->_config_file=this_hostextinfo->_config_file;
06005         new_hostextinfo->_start_line=this_hostextinfo->_start_line;
06006 
06007         /* string defaults */
06008         new_hostextinfo->host_name=NULL;
06009         new_hostextinfo->have_host_name=this_hostextinfo->have_host_name;
06010         new_hostextinfo->hostgroup_name=NULL;
06011         new_hostextinfo->have_hostgroup_name=this_hostextinfo->have_hostgroup_name;
06012         new_hostextinfo->notes=NULL;
06013         new_hostextinfo->have_notes=this_hostextinfo->have_notes;
06014         new_hostextinfo->notes_url=NULL;
06015         new_hostextinfo->have_notes_url=this_hostextinfo->have_notes_url;
06016         new_hostextinfo->action_url=NULL;
06017         new_hostextinfo->have_action_url=this_hostextinfo->have_action_url;
06018         new_hostextinfo->icon_image=NULL;
06019         new_hostextinfo->have_icon_image=this_hostextinfo->have_icon_image;
06020         new_hostextinfo->icon_image_alt=NULL;
06021         new_hostextinfo->have_icon_image_alt=this_hostextinfo->have_icon_image_alt;
06022         new_hostextinfo->vrml_image=NULL;
06023         new_hostextinfo->have_vrml_image=this_hostextinfo->have_vrml_image;
06024         new_hostextinfo->statusmap_image=NULL;
06025         new_hostextinfo->have_statusmap_image=this_hostextinfo->have_statusmap_image;
06026 
06027         /* duplicate strings (host_name member is passed in) */
06028         if(host_name!=NULL && (new_hostextinfo->host_name=(char *)strdup(host_name))==NULL)
06029                 error=TRUE;
06030         if(this_hostextinfo->template!=NULL && (new_hostextinfo->template=(char *)strdup(this_hostextinfo->template))==NULL)
06031                 error=TRUE;
06032         if(this_hostextinfo->name!=NULL && (new_hostextinfo->name=(char *)strdup(this_hostextinfo->name))==NULL)
06033                 error=TRUE;
06034         if(this_hostextinfo->notes!=NULL && (new_hostextinfo->notes=(char *)strdup(this_hostextinfo->notes))==NULL)
06035                 error=TRUE;
06036         if(this_hostextinfo->notes_url!=NULL && (new_hostextinfo->notes_url=(char *)strdup(this_hostextinfo->notes_url))==NULL)
06037                 error=TRUE;
06038         if(this_hostextinfo->action_url!=NULL && (new_hostextinfo->action_url=(char *)strdup(this_hostextinfo->action_url))==NULL)
06039                 error=TRUE;
06040         if(this_hostextinfo->icon_image!=NULL && (new_hostextinfo->icon_image=(char *)strdup(this_hostextinfo->icon_image))==NULL)
06041                 error=TRUE;
06042         if(this_hostextinfo->icon_image_alt!=NULL && (new_hostextinfo->icon_image_alt=(char *)strdup(this_hostextinfo->icon_image_alt))==NULL)
06043                 error=TRUE;
06044         if(this_hostextinfo->vrml_image!=NULL && (new_hostextinfo->vrml_image=(char *)strdup(this_hostextinfo->vrml_image))==NULL)
06045                 error=TRUE;
06046         if(this_hostextinfo->statusmap_image!=NULL && (new_hostextinfo->statusmap_image=(char *)strdup(this_hostextinfo->statusmap_image))==NULL)
06047                 error=TRUE;
06048 
06049         if(error==TRUE){
06050                 my_free(new_hostextinfo->host_name);
06051                 my_free(new_hostextinfo->template);
06052                 my_free(new_hostextinfo->name);
06053                 my_free(new_hostextinfo->notes);
06054                 my_free(new_hostextinfo->notes_url);
06055                 my_free(new_hostextinfo->action_url);
06056                 my_free(new_hostextinfo->icon_image);
06057                 my_free(new_hostextinfo->icon_image_alt);
06058                 my_free(new_hostextinfo->vrml_image);
06059                 my_free(new_hostextinfo->statusmap_image);
06060                 my_free(new_hostextinfo);
06061                 return ERROR;
06062                 }
06063 
06064         /* duplicate non-string members */
06065         new_hostextinfo->x_2d=this_hostextinfo->x_2d;
06066         new_hostextinfo->y_2d=this_hostextinfo->y_2d;
06067         new_hostextinfo->have_2d_coords=this_hostextinfo->have_2d_coords;
06068         new_hostextinfo->x_3d=this_hostextinfo->x_3d;
06069         new_hostextinfo->y_3d=this_hostextinfo->y_3d;
06070         new_hostextinfo->z_3d=this_hostextinfo->z_3d;
06071         new_hostextinfo->have_3d_coords=this_hostextinfo->have_3d_coords;
06072 
06073         /* add new object to head of list */
06074         new_hostextinfo->next=xodtemplate_hostextinfo_list;
06075         xodtemplate_hostextinfo_list=new_hostextinfo;
06076 
06077         return OK;
06078         }
06079 
06080 
06081 
06082 /* duplicates a serviceextinfo object definition */
06083 int xodtemplate_duplicate_serviceextinfo(xodtemplate_serviceextinfo *this_serviceextinfo, char *host_name){
06084         xodtemplate_serviceextinfo *new_serviceextinfo=NULL;
06085         int error=FALSE;
06086 
06087         new_serviceextinfo=(xodtemplate_serviceextinfo *)malloc(sizeof(xodtemplate_serviceextinfo));
06088         if(new_serviceextinfo==NULL)
06089                 return ERROR;
06090 
06091         /* standard items */
06092         new_serviceextinfo->template=NULL;
06093         new_serviceextinfo->name=NULL;
06094         new_serviceextinfo->has_been_resolved=this_serviceextinfo->has_been_resolved;
06095         new_serviceextinfo->register_object=this_serviceextinfo->register_object;
06096         new_serviceextinfo->_config_file=this_serviceextinfo->_config_file;
06097         new_serviceextinfo->_start_line=this_serviceextinfo->_start_line;
06098 
06099         /* string defaults */
06100         new_serviceextinfo->host_name=NULL;
06101         new_serviceextinfo->have_host_name=this_serviceextinfo->have_host_name;
06102         new_serviceextinfo->service_description=NULL;
06103         new_serviceextinfo->have_service_description=this_serviceextinfo->have_service_description;
06104         new_serviceextinfo->hostgroup_name=NULL;
06105         new_serviceextinfo->have_hostgroup_name=this_serviceextinfo->have_hostgroup_name;
06106         new_serviceextinfo->notes=NULL;
06107         new_serviceextinfo->have_notes=this_serviceextinfo->have_notes;
06108         new_serviceextinfo->notes_url=NULL;
06109         new_serviceextinfo->have_notes_url=this_serviceextinfo->have_notes_url;
06110         new_serviceextinfo->action_url=NULL;
06111         new_serviceextinfo->have_action_url=this_serviceextinfo->have_action_url;
06112         new_serviceextinfo->icon_image=NULL;
06113         new_serviceextinfo->have_icon_image=this_serviceextinfo->have_icon_image;
06114         new_serviceextinfo->icon_image_alt=NULL;
06115         new_serviceextinfo->have_icon_image_alt=this_serviceextinfo->have_icon_image_alt;
06116 
06117         /* duplicate strings (host_name member is passed in) */
06118         if(host_name!=NULL && (new_serviceextinfo->host_name=(char *)strdup(host_name))==NULL)
06119                 error=TRUE;
06120         if(this_serviceextinfo->template!=NULL && (new_serviceextinfo->template=(char *)strdup(this_serviceextinfo->template))==NULL)
06121                 error=TRUE;
06122         if(this_serviceextinfo->name!=NULL && (new_serviceextinfo->name=(char *)strdup(this_serviceextinfo->name))==NULL)
06123                 error=TRUE;
06124         if(this_serviceextinfo->service_description!=NULL && (new_serviceextinfo->service_description=(char *)strdup(this_serviceextinfo->service_description))==NULL)
06125                 error=TRUE;
06126         if(this_serviceextinfo->notes!=NULL && (new_serviceextinfo->notes=(char *)strdup(this_serviceextinfo->notes))==NULL)
06127                 error=TRUE;
06128         if(this_serviceextinfo->notes_url!=NULL && (new_serviceextinfo->notes_url=(char *)strdup(this_serviceextinfo->notes_url))==NULL)
06129                 error=TRUE;
06130         if(this_serviceextinfo->action_url!=NULL && (new_serviceextinfo->action_url=(char *)strdup(this_serviceextinfo->action_url))==NULL)
06131                 error=TRUE;
06132         if(this_serviceextinfo->icon_image!=NULL && (new_serviceextinfo->icon_image=(char *)strdup(this_serviceextinfo->icon_image))==NULL)
06133                 error=TRUE;
06134         if(this_serviceextinfo->icon_image_alt!=NULL && (new_serviceextinfo->icon_image_alt=(char *)strdup(this_serviceextinfo->icon_image_alt))==NULL)
06135                 error=TRUE;
06136 
06137         if(error==TRUE){
06138                 my_free(new_serviceextinfo->host_name);
06139                 my_free(new_serviceextinfo->template);
06140                 my_free(new_serviceextinfo->name);
06141                 my_free(new_serviceextinfo->service_description);
06142                 my_free(new_serviceextinfo->notes);
06143                 my_free(new_serviceextinfo->notes_url);
06144                 my_free(new_serviceextinfo->action_url);
06145                 my_free(new_serviceextinfo->icon_image);
06146                 my_free(new_serviceextinfo->icon_image_alt);
06147                 my_free(new_serviceextinfo);
06148                 return ERROR;
06149                 }
06150 
06151         /* add new object to head of list */
06152         new_serviceextinfo->next=xodtemplate_serviceextinfo_list;
06153         xodtemplate_serviceextinfo_list=new_serviceextinfo;
06154 
06155         return OK;
06156         }
06157 
06158 #endif
06159 
06160 
06161 /******************************************************************/
06162 /***************** OBJECT RESOLUTION FUNCTIONS ********************/
06163 /******************************************************************/
06164 
06165 #ifdef NSCORE
06166 
06167 /* inherit object properties */
06168 /* some missing defaults (notification options, etc.) are also applied here */
06169 int xodtemplate_inherit_object_properties(void){
06170         xodtemplate_host *temp_host=NULL;
06171         xodtemplate_service *temp_service=NULL;
06172         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
06173         xodtemplate_hostescalation *temp_hostescalation=NULL;
06174 
06175 
06176         /* fill in missing defaults for hosts... */
06177         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
06178 
06179                 /* if notification options are missing, assume all */
06180                 if(temp_host->have_notification_options==FALSE){
06181                         temp_host->notify_on_down=TRUE;
06182                         temp_host->notify_on_unreachable=TRUE;
06183                         temp_host->notify_on_recovery=TRUE;
06184                         temp_host->notify_on_flapping=TRUE;
06185                         temp_host->notify_on_downtime=TRUE;
06186                         temp_host->have_notification_options=TRUE;
06187                         }
06188                 }
06189                 
06190         /* services inherit some properties from their associated host... */
06191         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
06192                 
06193                 /* find the host */
06194                 if((temp_host=xodtemplate_find_real_host(temp_service->host_name))==NULL)
06195                         continue;
06196 
06197                 /* services inherit contact groups from host if not already specified */
06198                 if(temp_service->have_contact_groups==FALSE && temp_host->have_contact_groups==TRUE && temp_host->contact_groups!=NULL){
06199                         temp_service->contact_groups=(char *)strdup(temp_host->contact_groups);
06200                         temp_service->have_contact_groups=TRUE;
06201                         }
06202 
06203                 /* services inherit contacts from host if not already specified */
06204                 if(temp_service->have_contacts==FALSE && temp_host->have_contacts==TRUE && temp_host->contacts!=NULL){
06205                         temp_service->contacts=(char *)strdup(temp_host->contacts);
06206                         temp_service->have_contacts=TRUE;
06207                         }
06208 
06209                 /* services inherit notification interval from host if not already specified */
06210                 if(temp_service->have_notification_interval==FALSE && temp_host->have_notification_interval==TRUE){
06211                         temp_service->notification_interval=temp_host->notification_interval;
06212                         temp_service->have_notification_interval=TRUE;
06213                         }
06214 
06215                 /* services inherit notification period from host if not already specified */
06216                 if(temp_service->have_notification_period==FALSE && temp_host->have_notification_period==TRUE && temp_host->notification_period!=NULL){
06217                         temp_service->notification_period=(char *)strdup(temp_host->notification_period);
06218                         temp_service->have_notification_period=TRUE;
06219                         }
06220 
06221                 /* if notification options are missing, assume all */
06222                 if(temp_service->have_notification_options==FALSE){
06223                         temp_service->notify_on_unknown=TRUE;
06224                         temp_service->notify_on_warning=TRUE;
06225                         temp_service->notify_on_critical=TRUE;
06226                         temp_service->notify_on_recovery=TRUE;
06227                         temp_service->notify_on_flapping=TRUE;
06228                         temp_service->notify_on_downtime=TRUE;
06229                         temp_service->have_notification_options=TRUE;
06230                         }
06231                 }
06232 
06233         /* service escalations inherit some properties from their associated service... */
06234         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
06235 
06236                 /* find the service */
06237                 if((temp_service=xodtemplate_find_real_service(temp_serviceescalation->host_name,temp_serviceescalation->service_description))==NULL)
06238                         continue;
06239                 
06240                 /* service escalations inherit contact groups from service if not already specified */
06241                 if(temp_serviceescalation->have_contact_groups==FALSE && temp_service->have_contact_groups==TRUE && temp_service->contact_groups!=NULL){
06242                         temp_serviceescalation->contact_groups=(char *)strdup(temp_service->contact_groups);
06243                         temp_serviceescalation->have_contact_groups=TRUE;
06244                         }
06245 
06246                 /* SPECIAL RULE 10/04/07 - additive inheritance from service's contactgroup(s) */
06247                 if(temp_serviceescalation->contact_groups!=NULL && temp_serviceescalation->contact_groups[0]=='+')
06248                         xodtemplate_get_inherited_string(&temp_service->have_contact_groups,&temp_service->contact_groups,&temp_serviceescalation->have_contact_groups,&temp_serviceescalation->contact_groups);
06249 
06250                 /* service escalations inherit contacts from service if not already specified */
06251                 if(temp_serviceescalation->have_contacts==FALSE && temp_service->have_contacts==TRUE && temp_service->contacts!=NULL){
06252                         temp_serviceescalation->contacts=(char *)strdup(temp_service->contacts);
06253                         temp_serviceescalation->have_contacts=TRUE;
06254                         }
06255 
06256                 /* SPECIAL RULE 10/04/07 - additive inheritance from service's contact(s) */
06257                 if(temp_serviceescalation->contacts!=NULL && temp_serviceescalation->contacts[0]=='+')
06258                         xodtemplate_get_inherited_string(&temp_service->have_contacts,&temp_service->contacts,&temp_serviceescalation->have_contacts,&temp_serviceescalation->contacts);
06259 
06260                 /* service escalations inherit notification interval from service if not already defined */
06261                 if(temp_serviceescalation->have_notification_interval==FALSE && temp_service->have_notification_interval==TRUE){
06262                         temp_serviceescalation->notification_interval=temp_service->notification_interval;
06263                         temp_serviceescalation->have_notification_interval=TRUE;
06264                         }
06265 
06266                 /* service escalations inherit escalation period from service if not already defined */
06267                 if(temp_serviceescalation->have_escalation_period==FALSE && temp_service->have_notification_period==TRUE && temp_service->notification_period!=NULL){
06268                         temp_serviceescalation->escalation_period=(char *)strdup(temp_service->notification_period);
06269                         temp_serviceescalation->have_escalation_period=TRUE;
06270                         }
06271 
06272                 /* if escalation options are missing, assume all */
06273                 if(temp_serviceescalation->have_escalation_options==FALSE){
06274                         temp_serviceescalation->escalate_on_unknown=TRUE;
06275                         temp_serviceescalation->escalate_on_warning=TRUE;
06276                         temp_serviceescalation->escalate_on_critical=TRUE;
06277                         temp_serviceescalation->escalate_on_recovery=TRUE;
06278                         temp_serviceescalation->have_escalation_options=TRUE;
06279                         }
06280 
06281                 /* 03/05/08 clear additive string chars - not done in xodtemplate_clean_additive_strings() anymore */
06282                 xodtemplate_clean_additive_string(&temp_serviceescalation->contact_groups);
06283                 xodtemplate_clean_additive_string(&temp_serviceescalation->contacts);
06284                 }
06285 
06286         /* host escalations inherit some properties from their associated host... */
06287         for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
06288 
06289                 /* find the host */
06290                 if((temp_host=xodtemplate_find_real_host(temp_hostescalation->host_name))==NULL)
06291                         continue;
06292                 
06293                 /* host escalations inherit contact groups from service if not already specified */
06294                 if(temp_hostescalation->have_contact_groups==FALSE && temp_host->have_contact_groups==TRUE && temp_host->contact_groups!=NULL){
06295                         temp_hostescalation->contact_groups=(char *)strdup(temp_host->contact_groups);
06296                         temp_hostescalation->have_contact_groups=TRUE;
06297                         }
06298 
06299                 /* SPECIAL RULE 10/04/07 - additive inheritance from host's contactgroup(s) */
06300                 if(temp_hostescalation->contact_groups!=NULL && temp_hostescalation->contact_groups[0]=='+')
06301                         xodtemplate_get_inherited_string(&temp_host->have_contact_groups,&temp_host->contact_groups,&temp_hostescalation->have_contact_groups,&temp_hostescalation->contact_groups);
06302 
06303                 /* host escalations inherit contacts from service if not already specified */
06304                 if(temp_hostescalation->have_contacts==FALSE && temp_host->have_contacts==TRUE && temp_host->contacts!=NULL){
06305                         temp_hostescalation->contacts=(char *)strdup(temp_host->contacts);
06306                         temp_hostescalation->have_contacts=TRUE;
06307                         }
06308 
06309                 /* SPECIAL RULE 10/04/07 - additive inheritance from host's contact(s) */
06310                 if(temp_hostescalation->contacts!=NULL && temp_hostescalation->contacts[0]=='+')
06311                         xodtemplate_get_inherited_string(&temp_host->have_contacts,&temp_host->contacts,&temp_hostescalation->have_contacts,&temp_hostescalation->contacts);
06312 
06313                 /* host escalations inherit notification interval from host if not already defined */
06314                 if(temp_hostescalation->have_notification_interval==FALSE && temp_host->have_notification_interval==TRUE){
06315                         temp_hostescalation->notification_interval=temp_host->notification_interval;
06316                         temp_hostescalation->have_notification_interval=TRUE;
06317                         }
06318 
06319                 /* host escalations inherit escalation period from host if not already defined */
06320                 if(temp_hostescalation->have_escalation_period==FALSE && temp_host->have_notification_period==TRUE && temp_host->notification_period!=NULL){
06321                         temp_hostescalation->escalation_period=(char *)strdup(temp_host->notification_period);
06322                         temp_hostescalation->have_escalation_period=TRUE;
06323                         }
06324 
06325                 /* if escalation options are missing, assume all */
06326                 if(temp_hostescalation->have_escalation_options==FALSE){
06327                         temp_hostescalation->escalate_on_down=TRUE;
06328                         temp_hostescalation->escalate_on_unreachable=TRUE;
06329                         temp_hostescalation->escalate_on_recovery=TRUE;
06330                         temp_hostescalation->have_escalation_options=TRUE;
06331                         }
06332 
06333                 /* 03/05/08 clear additive string chars - not done in xodtemplate_clean_additive_strings() anymore */
06334                 xodtemplate_clean_additive_string(&temp_hostescalation->contact_groups);
06335                 xodtemplate_clean_additive_string(&temp_hostescalation->contacts);
06336                 }
06337 
06338         return OK;
06339         }
06340 
06341 #endif
06342 
06343 
06344 /******************************************************************/
06345 /***************** OBJECT RESOLUTION FUNCTIONS ********************/
06346 /******************************************************************/
06347 
06348 #ifdef NSCORE
06349 
06350 /* resolves object definitions */
06351 int xodtemplate_resolve_objects(void){
06352         xodtemplate_timeperiod *temp_timeperiod=NULL;
06353         xodtemplate_command *temp_command=NULL;
06354         xodtemplate_contactgroup *temp_contactgroup=NULL;
06355         xodtemplate_hostgroup *temp_hostgroup=NULL;
06356         xodtemplate_servicegroup *temp_servicegroup=NULL;
06357         xodtemplate_servicedependency *temp_servicedependency=NULL;
06358         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
06359         xodtemplate_contact *temp_contact=NULL;
06360         xodtemplate_host *temp_host=NULL;
06361         xodtemplate_service *temp_service=NULL;
06362         xodtemplate_hostdependency *temp_hostdependency=NULL;
06363         xodtemplate_hostescalation *temp_hostescalation=NULL;
06364         xodtemplate_hostextinfo *temp_hostextinfo=NULL;
06365         xodtemplate_serviceextinfo *temp_serviceextinfo=NULL;
06366         xodtemplate_module *temp_module=NULL;
06367 
06368         /* resolve all timeperiod objects */
06369         for(temp_timeperiod=xodtemplate_timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){
06370                 if(xodtemplate_resolve_timeperiod(temp_timeperiod)==ERROR)
06371                         return ERROR;
06372                 }
06373 
06374         /* resolve all command objects */
06375         for(temp_command=xodtemplate_command_list;temp_command!=NULL;temp_command=temp_command->next){
06376                 if(xodtemplate_resolve_command(temp_command)==ERROR)
06377                         return ERROR;
06378                 }
06379 
06380         /* resolve all contactgroup objects */
06381         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
06382                 if(xodtemplate_resolve_contactgroup(temp_contactgroup)==ERROR)
06383                         return ERROR;
06384                 }
06385 
06386         /* resolve all hostgroup objects */
06387         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
06388                 if(xodtemplate_resolve_hostgroup(temp_hostgroup)==ERROR)
06389                         return ERROR;
06390                 }
06391 
06392         /* resolve all servicegroup objects */
06393         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
06394                 if(xodtemplate_resolve_servicegroup(temp_servicegroup)==ERROR)
06395                         return ERROR;
06396                 }
06397 
06398         /* resolve all servicedependency objects */
06399         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
06400                 if(xodtemplate_resolve_servicedependency(temp_servicedependency)==ERROR)
06401                         return ERROR;
06402                 }
06403 
06404         /* resolve all serviceescalation objects */
06405         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
06406                 if(xodtemplate_resolve_serviceescalation(temp_serviceescalation)==ERROR)
06407                         return ERROR;
06408                 }
06409 
06410         /* resolve all contact objects */
06411         for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
06412                 if(xodtemplate_resolve_contact(temp_contact)==ERROR)
06413                         return ERROR;
06414                 }
06415 
06416         /* resolve all host objects */
06417         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
06418                 if(xodtemplate_resolve_host(temp_host)==ERROR)
06419                         return ERROR;
06420                 }
06421 
06422         /* resolve all service objects */
06423         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
06424                 if(xodtemplate_resolve_service(temp_service)==ERROR)
06425                         return ERROR;
06426                 }
06427 
06428         /* resolve all hostdependency objects */
06429         for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
06430                 if(xodtemplate_resolve_hostdependency(temp_hostdependency)==ERROR)
06431                         return ERROR;
06432                 }
06433 
06434         /* resolve all hostescalation objects */
06435         for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
06436                 if(xodtemplate_resolve_hostescalation(temp_hostescalation)==ERROR)
06437                         return ERROR;
06438                 }
06439 
06440         /* resolve all hostextinfo objects */
06441         for(temp_hostextinfo=xodtemplate_hostextinfo_list;temp_hostextinfo!=NULL;temp_hostextinfo=temp_hostextinfo->next){
06442                 if(xodtemplate_resolve_hostextinfo(temp_hostextinfo)==ERROR)
06443                         return ERROR;
06444                 }
06445 
06446         /* resolve all serviceextinfo objects */
06447         for(temp_serviceextinfo=xodtemplate_serviceextinfo_list;temp_serviceextinfo!=NULL;temp_serviceextinfo=temp_serviceextinfo->next){
06448                 if(xodtemplate_resolve_serviceextinfo(temp_serviceextinfo)==ERROR)
06449                         return ERROR;
06450                 }
06451 
06452         /* resolve all module objects */
06453         for(temp_module=xodtemplate_module_list;temp_module!=NULL;temp_module=temp_module->next){
06454                 if(xodtemplate_resolve_module(temp_module)==ERROR)
06455                         return ERROR;
06456                 }
06457 
06458 
06459         return OK;
06460         }
06461 
06462 
06463 
06464 /* resolves a timeperiod object */
06465 int xodtemplate_resolve_timeperiod(xodtemplate_timeperiod *this_timeperiod){
06466         char *temp_ptr=NULL;
06467         char *template_names=NULL;
06468         char *template_name_ptr=NULL;
06469         xodtemplate_daterange *template_daterange=NULL;
06470         xodtemplate_daterange *this_daterange=NULL;
06471         xodtemplate_daterange *new_daterange=NULL;
06472         xodtemplate_timeperiod *template_timeperiod=NULL;
06473         int x;
06474 
06475         /* return if this timeperiod has already been resolved */
06476         if(this_timeperiod->has_been_resolved==TRUE)
06477                 return OK;
06478 
06479         /* set the resolved flag */
06480         this_timeperiod->has_been_resolved=TRUE;
06481 
06482         /* return if we have no template */
06483         if(this_timeperiod->template==NULL)
06484                 return OK;
06485 
06486         if((template_names=(char *)strdup(this_timeperiod->template))==NULL)
06487                 return ERROR;
06488 
06489         /* apply all templates */
06490         template_name_ptr=template_names;
06491         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06492 
06493                 template_timeperiod=xodtemplate_find_timeperiod(temp_ptr);
06494                 if(template_timeperiod==NULL){
06495                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in timeperiod definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
06496                         my_free(template_names);
06497                         return ERROR;
06498                         }
06499 
06500                 /* resolve the template timeperiod... */
06501                 xodtemplate_resolve_timeperiod(template_timeperiod);
06502 
06503                 /* apply missing properties from template timeperiod... */
06504                 if(this_timeperiod->timeperiod_name==NULL && template_timeperiod->timeperiod_name!=NULL)
06505                         this_timeperiod->timeperiod_name=(char *)strdup(template_timeperiod->timeperiod_name);
06506                 if(this_timeperiod->alias==NULL && template_timeperiod->alias!=NULL)
06507                         this_timeperiod->alias=(char *)strdup(template_timeperiod->alias);
06508                 if(this_timeperiod->exclusions==NULL && template_timeperiod->exclusions!=NULL)
06509                         this_timeperiod->exclusions=(char *)strdup(template_timeperiod->exclusions);
06510                 for(x=0;x<7;x++){
06511                         if(this_timeperiod->timeranges[x]==NULL && template_timeperiod->timeranges[x]!=NULL){
06512                                 this_timeperiod->timeranges[x]=(char *)strdup(template_timeperiod->timeranges[x]);
06513                                 }
06514                         }
06515                 /* daterange exceptions require more work to apply missing ranges... */
06516                 for(x=0;x<DATERANGE_TYPES;x++){
06517                         for(template_daterange=template_timeperiod->exceptions[x];template_daterange!=NULL;template_daterange=template_daterange->next){
06518 
06519                                 /* see if this same daterange already exists in the timeperiod */
06520                                 for(this_daterange=this_timeperiod->exceptions[x];this_daterange!=NULL;this_daterange=this_daterange->next){
06521                                         if((this_daterange->type==template_daterange->type) && (this_daterange->syear==template_daterange->syear) && (this_daterange->smon==template_daterange->smon) && (this_daterange->smday==template_daterange->smday) && (this_daterange->swday==template_daterange->swday) && (this_daterange->swday_offset==template_daterange->swday_offset) && (this_daterange->eyear==template_daterange->eyear) && (this_daterange->emon==template_daterange->emon) && (this_daterange->emday==template_daterange->emday) && (this_daterange->ewday==template_daterange->ewday) && (this_daterange->ewday_offset==template_daterange->ewday_offset) && (this_daterange->skip_interval==template_daterange->skip_interval))
06522                                                 break;
06523                                         }
06524 
06525                                 /* this daterange already exists in the timeperiod, so don't inherit it */
06526                                 if(this_daterange!=NULL)
06527                                         continue;
06528 
06529                                 /* inherit the daterange from the template */
06530                                 if((new_daterange=(xodtemplate_daterange *)malloc(sizeof(xodtemplate_daterange)))==NULL)
06531                                         continue;
06532                                 new_daterange->type=template_daterange->type;
06533                                 new_daterange->syear=template_daterange->syear;
06534                                 new_daterange->smon=template_daterange->smon;
06535                                 new_daterange->smday=template_daterange->smday;
06536                                 new_daterange->swday=template_daterange->swday;
06537                                 new_daterange->swday_offset=template_daterange->swday_offset;
06538                                 new_daterange->eyear=template_daterange->eyear;
06539                                 new_daterange->emon=template_daterange->emon;
06540                                 new_daterange->emday=template_daterange->emday;
06541                                 new_daterange->ewday=template_daterange->ewday;
06542                                 new_daterange->ewday_offset=template_daterange->ewday_offset;
06543                                 new_daterange->skip_interval=template_daterange->skip_interval;
06544                                 new_daterange->timeranges=NULL;
06545                                 if(template_daterange->timeranges!=NULL)
06546                                         new_daterange->timeranges=(char *)strdup(template_daterange->timeranges);
06547 
06548                                 /* add new daterange to head of list (should it be added to the end instead?) */
06549                                 new_daterange->next=this_timeperiod->exceptions[x];
06550                                 this_timeperiod->exceptions[x]=new_daterange;
06551                                 }
06552                         }
06553                 }
06554 
06555         my_free(template_names);
06556 
06557         return OK;
06558         }
06559 
06560 
06561 
06562 
06563 /* resolves a command object */
06564 int xodtemplate_resolve_command(xodtemplate_command *this_command){
06565         char *temp_ptr=NULL;
06566         char *template_names=NULL;
06567         char *template_name_ptr=NULL;
06568         xodtemplate_command *template_command=NULL;
06569 
06570         /* return if this command has already been resolved */
06571         if(this_command->has_been_resolved==TRUE)
06572                 return OK;
06573 
06574         /* set the resolved flag */
06575         this_command->has_been_resolved=TRUE;
06576 
06577         /* return if we have no template */
06578         if(this_command->template==NULL)
06579                 return OK;
06580 
06581         if((template_names=(char *)strdup(this_command->template))==NULL)
06582                 return ERROR;
06583 
06584         /* apply all templates */
06585         template_name_ptr=template_names;
06586         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06587 
06588                 template_command=xodtemplate_find_command(temp_ptr);
06589                 if(template_command==NULL){
06590                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in command definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_command->_config_file),this_command->_start_line);
06591                         my_free(template_names);
06592                         return ERROR;
06593                         }
06594 
06595                 /* resolve the template command... */
06596                 xodtemplate_resolve_command(template_command);
06597 
06598                 /* apply missing properties from template command... */
06599                 if(this_command->command_name==NULL && template_command->command_name!=NULL)
06600                         this_command->command_name=(char *)strdup(template_command->command_name);
06601                 if(this_command->command_line==NULL && template_command->command_line!=NULL)
06602                         this_command->command_line=(char *)strdup(template_command->command_line);
06603                 }
06604 
06605         my_free(template_names);
06606 
06607         return OK;
06608         }
06609 
06610 
06611 
06612 
06613 /* resolves a contactgroup object */
06614 int xodtemplate_resolve_contactgroup(xodtemplate_contactgroup *this_contactgroup){
06615         char *temp_ptr=NULL;
06616         char *template_names=NULL;
06617         char *template_name_ptr=NULL;
06618         xodtemplate_contactgroup *template_contactgroup=NULL;
06619 
06620         /* return if this contactgroup has already been resolved */
06621         if(this_contactgroup->has_been_resolved==TRUE)
06622                 return OK;
06623 
06624         /* set the resolved flag */
06625         this_contactgroup->has_been_resolved=TRUE;
06626 
06627         /* return if we have no template */
06628         if(this_contactgroup->template==NULL)
06629                 return OK;
06630 
06631         if((template_names=(char *)strdup(this_contactgroup->template))==NULL)
06632                 return ERROR;
06633 
06634         /* apply all templates */
06635         template_name_ptr=template_names;
06636         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06637 
06638                 template_contactgroup=xodtemplate_find_contactgroup(temp_ptr);
06639                 if(template_contactgroup==NULL){
06640                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in contactgroup definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_contactgroup->_config_file),this_contactgroup->_start_line);
06641                         my_free(template_names);
06642                         return ERROR;
06643                         }
06644 
06645                 /* resolve the template contactgroup... */
06646                 xodtemplate_resolve_contactgroup(template_contactgroup);
06647 
06648                 /* apply missing properties from template contactgroup... */
06649                 if(this_contactgroup->contactgroup_name==NULL && template_contactgroup->contactgroup_name!=NULL)
06650                         this_contactgroup->contactgroup_name=(char *)strdup(template_contactgroup->contactgroup_name);
06651                 if(this_contactgroup->alias==NULL && template_contactgroup->alias!=NULL)
06652                         this_contactgroup->alias=(char *)strdup(template_contactgroup->alias);
06653 
06654                 xodtemplate_get_inherited_string(&template_contactgroup->have_members,&template_contactgroup->members,&this_contactgroup->have_members,&this_contactgroup->members);
06655                 xodtemplate_get_inherited_string(&template_contactgroup->have_contactgroup_members,&template_contactgroup->contactgroup_members,&this_contactgroup->have_contactgroup_members,&this_contactgroup->contactgroup_members);
06656 
06657                 }
06658 
06659         my_free(template_names);
06660 
06661         return OK;
06662         }
06663 
06664 
06665 
06666 
06667 /* resolves a hostgroup object */
06668 int xodtemplate_resolve_hostgroup(xodtemplate_hostgroup *this_hostgroup){
06669         char *temp_ptr=NULL;
06670         char *template_names=NULL;
06671         char *template_name_ptr=NULL;
06672         xodtemplate_hostgroup *template_hostgroup=NULL;
06673 
06674         /* return if this hostgroup has already been resolved */
06675         if(this_hostgroup->has_been_resolved==TRUE)
06676                 return OK;
06677 
06678         /* set the resolved flag */
06679         this_hostgroup->has_been_resolved=TRUE;
06680 
06681         /* return if we have no template */
06682         if(this_hostgroup->template==NULL)
06683                 return OK;
06684 
06685         if((template_names=(char *)strdup(this_hostgroup->template))==NULL)
06686                 return ERROR;
06687 
06688         /* apply all templates */
06689         template_name_ptr=template_names;
06690         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06691 
06692                 template_hostgroup=xodtemplate_find_hostgroup(temp_ptr);
06693                 if(template_hostgroup==NULL){
06694                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in hostgroup definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_hostgroup->_config_file),this_hostgroup->_start_line);
06695                         my_free(template_names);
06696                         return ERROR;
06697                         }
06698 
06699                 /* resolve the template hostgroup... */
06700                 xodtemplate_resolve_hostgroup(template_hostgroup);
06701 
06702                 /* apply missing properties from template hostgroup... */
06703                 if(this_hostgroup->hostgroup_name==NULL && template_hostgroup->hostgroup_name!=NULL)
06704                         this_hostgroup->hostgroup_name=(char *)strdup(template_hostgroup->hostgroup_name);
06705                 if(this_hostgroup->alias==NULL && template_hostgroup->alias!=NULL)
06706                         this_hostgroup->alias=(char *)strdup(template_hostgroup->alias);
06707 
06708                 xodtemplate_get_inherited_string(&template_hostgroup->have_members,&template_hostgroup->members,&this_hostgroup->have_members,&this_hostgroup->members);
06709                 xodtemplate_get_inherited_string(&template_hostgroup->have_hostgroup_members,&template_hostgroup->hostgroup_members,&this_hostgroup->have_hostgroup_members,&this_hostgroup->hostgroup_members);
06710 
06711                 if(this_hostgroup->have_notes==FALSE && template_hostgroup->have_notes==TRUE){
06712                         if(this_hostgroup->notes==NULL && template_hostgroup->notes!=NULL)
06713                                 this_hostgroup->notes=(char *)strdup(template_hostgroup->notes);
06714                         this_hostgroup->have_notes=TRUE;
06715                         }
06716                 if(this_hostgroup->have_notes_url==FALSE && template_hostgroup->have_notes_url==TRUE){
06717                         if(this_hostgroup->notes_url==NULL && template_hostgroup->notes_url!=NULL)
06718                                 this_hostgroup->notes_url=(char *)strdup(template_hostgroup->notes_url);
06719                         this_hostgroup->have_notes_url=TRUE;
06720                         }
06721                 if(this_hostgroup->have_action_url==FALSE && template_hostgroup->have_action_url==TRUE){
06722                         if(this_hostgroup->action_url==NULL && template_hostgroup->action_url!=NULL)
06723                                 this_hostgroup->action_url=(char *)strdup(template_hostgroup->action_url);
06724                         this_hostgroup->have_action_url=TRUE;
06725                         }
06726                 }
06727 
06728         my_free(template_names);
06729 
06730         return OK;
06731         }
06732 
06733 
06734 
06735 
06736 /* resolves a servicegroup object */
06737 int xodtemplate_resolve_servicegroup(xodtemplate_servicegroup *this_servicegroup){
06738         char *temp_ptr=NULL;
06739         char *template_names=NULL;
06740         char *template_name_ptr=NULL;
06741         xodtemplate_servicegroup *template_servicegroup=NULL;
06742 
06743         /* return if this servicegroup has already been resolved */
06744         if(this_servicegroup->has_been_resolved==TRUE)
06745                 return OK;
06746 
06747         /* set the resolved flag */
06748         this_servicegroup->has_been_resolved=TRUE;
06749 
06750         /* return if we have no template */
06751         if(this_servicegroup->template==NULL)
06752                 return OK;
06753 
06754         if((template_names=(char *)strdup(this_servicegroup->template))==NULL)
06755                 return ERROR;
06756 
06757         /* apply all templates */
06758         template_name_ptr=template_names;
06759         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06760 
06761                 template_servicegroup=xodtemplate_find_servicegroup(temp_ptr);
06762                 if(template_servicegroup==NULL){
06763                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in servicegroup definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_servicegroup->_config_file),this_servicegroup->_start_line);
06764                         my_free(template_names);
06765                         return ERROR;
06766                         }
06767 
06768                 /* resolve the template servicegroup... */
06769                 xodtemplate_resolve_servicegroup(template_servicegroup);
06770 
06771                 /* apply missing properties from template servicegroup... */
06772                 if(this_servicegroup->servicegroup_name==NULL && template_servicegroup->servicegroup_name!=NULL)
06773                         this_servicegroup->servicegroup_name=(char *)strdup(template_servicegroup->servicegroup_name);
06774                 if(this_servicegroup->alias==NULL && template_servicegroup->alias!=NULL)
06775                         this_servicegroup->alias=(char *)strdup(template_servicegroup->alias);
06776 
06777                 xodtemplate_get_inherited_string(&template_servicegroup->have_members,&template_servicegroup->members,&this_servicegroup->have_members,&this_servicegroup->members);
06778                 xodtemplate_get_inherited_string(&template_servicegroup->have_servicegroup_members,&template_servicegroup->servicegroup_members,&this_servicegroup->have_servicegroup_members,&this_servicegroup->servicegroup_members);
06779 
06780                 if(this_servicegroup->have_notes==FALSE && template_servicegroup->have_notes==TRUE){
06781                         if(this_servicegroup->notes==NULL && template_servicegroup->notes!=NULL)
06782                                 this_servicegroup->notes=(char *)strdup(template_servicegroup->notes);
06783                         this_servicegroup->have_notes=TRUE;
06784                         }
06785                 if(this_servicegroup->have_notes_url==FALSE && template_servicegroup->have_notes_url==TRUE){
06786                         if(this_servicegroup->notes_url==NULL && template_servicegroup->notes_url!=NULL)
06787                                 this_servicegroup->notes_url=(char *)strdup(template_servicegroup->notes_url);
06788                         this_servicegroup->have_notes_url=TRUE;
06789                         }
06790                 if(this_servicegroup->have_action_url==FALSE && template_servicegroup->have_action_url==TRUE){
06791                         if(this_servicegroup->action_url==NULL && template_servicegroup->action_url!=NULL)
06792                                 this_servicegroup->action_url=(char *)strdup(template_servicegroup->action_url);
06793                         this_servicegroup->have_action_url=TRUE;
06794                         }
06795                 }
06796 
06797         my_free(template_names);
06798 
06799         return OK;
06800         }
06801 
06802 
06803 /* resolves a servicedependency object */
06804 int xodtemplate_resolve_servicedependency(xodtemplate_servicedependency *this_servicedependency){
06805         char *temp_ptr=NULL;
06806         char *template_names=NULL;
06807         char *template_name_ptr=NULL;
06808         xodtemplate_servicedependency *template_servicedependency=NULL;
06809 
06810         /* return if this servicedependency has already been resolved */
06811         if(this_servicedependency->has_been_resolved==TRUE)
06812                 return OK;
06813 
06814         /* set the resolved flag */
06815         this_servicedependency->has_been_resolved=TRUE;
06816 
06817         /* return if we have no template */
06818         if(this_servicedependency->template==NULL)
06819                 return OK;
06820 
06821         if((template_names=(char *)strdup(this_servicedependency->template))==NULL)
06822                 return ERROR;
06823 
06824         /* apply all templates */
06825         template_name_ptr=template_names;
06826         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06827 
06828                 template_servicedependency=xodtemplate_find_servicedependency(temp_ptr);
06829                 if(template_servicedependency==NULL){
06830                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in service dependency definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_servicedependency->_config_file),this_servicedependency->_start_line);
06831                         my_free(template_names);
06832                         return ERROR;
06833                         }
06834 
06835                 /* resolve the template servicedependency... */
06836                 xodtemplate_resolve_servicedependency(template_servicedependency);
06837 
06838                 /* apply missing properties from template servicedependency... */
06839                 xodtemplate_get_inherited_string(&template_servicedependency->have_servicegroup_name,&template_servicedependency->servicegroup_name,&this_servicedependency->have_servicegroup_name,&this_servicedependency->servicegroup_name);
06840                 xodtemplate_get_inherited_string(&template_servicedependency->have_hostgroup_name,&template_servicedependency->hostgroup_name,&this_servicedependency->have_hostgroup_name,&this_servicedependency->hostgroup_name);
06841                 xodtemplate_get_inherited_string(&template_servicedependency->have_host_name,&template_servicedependency->host_name,&this_servicedependency->have_host_name,&this_servicedependency->host_name);
06842                 xodtemplate_get_inherited_string(&template_servicedependency->have_service_description,&template_servicedependency->service_description,&this_servicedependency->have_service_description,&this_servicedependency->service_description);
06843                 xodtemplate_get_inherited_string(&template_servicedependency->have_dependent_servicegroup_name,&template_servicedependency->dependent_servicegroup_name,&this_servicedependency->have_dependent_servicegroup_name,&this_servicedependency->dependent_servicegroup_name);
06844                 xodtemplate_get_inherited_string(&template_servicedependency->have_dependent_hostgroup_name,&template_servicedependency->dependent_hostgroup_name,&this_servicedependency->have_dependent_hostgroup_name,&this_servicedependency->dependent_hostgroup_name);
06845                 xodtemplate_get_inherited_string(&template_servicedependency->have_dependent_host_name,&template_servicedependency->dependent_host_name,&this_servicedependency->have_dependent_host_name,&this_servicedependency->dependent_host_name);
06846                 xodtemplate_get_inherited_string(&template_servicedependency->have_dependent_service_description,&template_servicedependency->dependent_service_description,&this_servicedependency->have_dependent_service_description,&this_servicedependency->dependent_service_description);
06847 
06848                 if(this_servicedependency->have_dependency_period==FALSE && template_servicedependency->have_dependency_period==TRUE){
06849                         if(this_servicedependency->dependency_period==NULL && template_servicedependency->dependency_period!=NULL)
06850                                 this_servicedependency->dependency_period=(char *)strdup(template_servicedependency->dependency_period);
06851                         this_servicedependency->have_dependency_period=TRUE;
06852                         }
06853                 if(this_servicedependency->have_inherits_parent==FALSE && template_servicedependency->have_inherits_parent==TRUE){
06854                         this_servicedependency->inherits_parent=template_servicedependency->inherits_parent;
06855                         this_servicedependency->have_inherits_parent=TRUE;
06856                         }
06857                 if(this_servicedependency->have_execution_dependency_options==FALSE && template_servicedependency->have_execution_dependency_options==TRUE){
06858                         this_servicedependency->fail_execute_on_ok=template_servicedependency->fail_execute_on_ok;
06859                         this_servicedependency->fail_execute_on_unknown=template_servicedependency->fail_execute_on_unknown;
06860                         this_servicedependency->fail_execute_on_warning=template_servicedependency->fail_execute_on_warning;
06861                         this_servicedependency->fail_execute_on_critical=template_servicedependency->fail_execute_on_critical;
06862                         this_servicedependency->fail_execute_on_pending=template_servicedependency->fail_execute_on_pending;
06863                         this_servicedependency->have_execution_dependency_options=TRUE;
06864                         }
06865                 if(this_servicedependency->have_notification_dependency_options==FALSE && template_servicedependency->have_notification_dependency_options==TRUE){
06866                         this_servicedependency->fail_notify_on_ok=template_servicedependency->fail_notify_on_ok;
06867                         this_servicedependency->fail_notify_on_unknown=template_servicedependency->fail_notify_on_unknown;
06868                         this_servicedependency->fail_notify_on_warning=template_servicedependency->fail_notify_on_warning;
06869                         this_servicedependency->fail_notify_on_critical=template_servicedependency->fail_notify_on_critical;
06870                         this_servicedependency->fail_notify_on_pending=template_servicedependency->fail_notify_on_pending;
06871                         this_servicedependency->have_notification_dependency_options=TRUE;
06872                         }
06873                 }
06874 
06875         my_free(template_names);
06876 
06877         return OK;
06878         }
06879 
06880 
06881 /* resolves a serviceescalation object */
06882 int xodtemplate_resolve_serviceescalation(xodtemplate_serviceescalation *this_serviceescalation){
06883         char *temp_ptr=NULL;
06884         char *template_names=NULL;
06885         char *template_name_ptr=NULL;
06886         xodtemplate_serviceescalation *template_serviceescalation=NULL;
06887 
06888         /* return if this serviceescalation has already been resolved */
06889         if(this_serviceescalation->has_been_resolved==TRUE)
06890                 return OK;
06891 
06892         /* set the resolved flag */
06893         this_serviceescalation->has_been_resolved=TRUE;
06894 
06895         /* return if we have no template */
06896         if(this_serviceescalation->template==NULL)
06897                 return OK;
06898 
06899         if((template_names=(char *)strdup(this_serviceescalation->template))==NULL)
06900                 return ERROR;
06901 
06902         /* apply all templates */
06903         template_name_ptr=template_names;
06904         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
06905 
06906                 template_serviceescalation=xodtemplate_find_serviceescalation(temp_ptr);
06907                 if(template_serviceescalation==NULL){
06908                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in service escalation definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_serviceescalation->_config_file),this_serviceescalation->_start_line);
06909                         my_free(template_names);
06910                         return ERROR;
06911                         }
06912 
06913                 /* resolve the template serviceescalation... */
06914                 xodtemplate_resolve_serviceescalation(template_serviceescalation);
06915 
06916                 /* apply missing properties from template serviceescalation... */
06917                 xodtemplate_get_inherited_string(&template_serviceescalation->have_servicegroup_name,&template_serviceescalation->servicegroup_name,&this_serviceescalation->have_servicegroup_name,&this_serviceescalation->servicegroup_name);
06918                 xodtemplate_get_inherited_string(&template_serviceescalation->have_hostgroup_name,&template_serviceescalation->hostgroup_name,&this_serviceescalation->have_hostgroup_name,&this_serviceescalation->hostgroup_name);
06919                 xodtemplate_get_inherited_string(&template_serviceescalation->have_host_name,&template_serviceescalation->host_name,&this_serviceescalation->have_host_name,&this_serviceescalation->host_name);
06920                 xodtemplate_get_inherited_string(&template_serviceescalation->have_service_description,&template_serviceescalation->service_description,&this_serviceescalation->have_service_description,&this_serviceescalation->service_description);
06921                 xodtemplate_get_inherited_string(&template_serviceescalation->have_contact_groups,&template_serviceescalation->contact_groups,&this_serviceescalation->have_contact_groups,&this_serviceescalation->contact_groups);
06922                 xodtemplate_get_inherited_string(&template_serviceescalation->have_contacts,&template_serviceescalation->contacts,&this_serviceescalation->have_contacts,&this_serviceescalation->contacts);
06923 
06924                 if(this_serviceescalation->have_escalation_period==FALSE && template_serviceescalation->have_escalation_period==TRUE){
06925                         if(this_serviceescalation->escalation_period==NULL && template_serviceescalation->escalation_period!=NULL)
06926                                 this_serviceescalation->escalation_period=(char *)strdup(template_serviceescalation->escalation_period);
06927                         this_serviceescalation->have_escalation_period=TRUE;
06928                         }
06929                 if(this_serviceescalation->have_first_notification==FALSE && template_serviceescalation->have_first_notification==TRUE){
06930                         this_serviceescalation->first_notification=template_serviceescalation->first_notification;
06931                         this_serviceescalation->have_first_notification=TRUE;
06932                         }
06933                 if(this_serviceescalation->have_last_notification==FALSE && template_serviceescalation->have_last_notification==TRUE){
06934                         this_serviceescalation->last_notification=template_serviceescalation->last_notification;
06935                         this_serviceescalation->have_last_notification=TRUE;
06936                         }
06937 #ifdef USE_ST_BASED_ESCAL_RANGES
06938                 if(this_serviceescalation->have_first_warning_notification==FALSE && template_serviceescalation->have_first_warning_notification==TRUE){
06939                         this_serviceescalation->first_warning_notification=template_serviceescalation->first_warning_notification;
06940                         this_serviceescalation->have_first_warning_notification=TRUE;
06941                         }
06942                 if(this_serviceescalation->have_last_warning_notification==FALSE && template_serviceescalation->have_last_warning_notification==TRUE){
06943                         this_serviceescalation->last_warning_notification=template_serviceescalation->last_warning_notification;
06944                         this_serviceescalation->have_last_warning_notification=TRUE;
06945                         }
06946                 if(this_serviceescalation->have_first_critical_notification==FALSE && template_serviceescalation->have_first_critical_notification==TRUE){
06947                         this_serviceescalation->first_critical_notification=template_serviceescalation->first_critical_notification;
06948                         this_serviceescalation->have_first_critical_notification=TRUE;
06949                         }
06950                 if(this_serviceescalation->have_last_critical_notification==FALSE && template_serviceescalation->have_last_critical_notification==TRUE){
06951                         this_serviceescalation->last_critical_notification=template_serviceescalation->last_critical_notification;
06952                         this_serviceescalation->have_last_critical_notification=TRUE;
06953                         }
06954                 if(this_serviceescalation->have_first_unknown_notification==FALSE && template_serviceescalation->have_first_unknown_notification==TRUE){
06955                         this_serviceescalation->first_unknown_notification=template_serviceescalation->first_unknown_notification;
06956                         this_serviceescalation->have_first_unknown_notification=TRUE;
06957                         }
06958                 if(this_serviceescalation->have_last_unknown_notification==FALSE && template_serviceescalation->have_last_unknown_notification==TRUE){
06959                         this_serviceescalation->last_unknown_notification=template_serviceescalation->last_unknown_notification;
06960                         this_serviceescalation->have_last_unknown_notification=TRUE;
06961                         }
06962 #endif
06963                 if(this_serviceescalation->have_notification_interval==FALSE && template_serviceescalation->have_notification_interval==TRUE){
06964                         this_serviceescalation->notification_interval=template_serviceescalation->notification_interval;
06965                         this_serviceescalation->have_notification_interval=TRUE;
06966                         }
06967                 if(this_serviceescalation->have_escalation_options==FALSE && template_serviceescalation->have_escalation_options==TRUE){
06968                         this_serviceescalation->escalate_on_warning=template_serviceescalation->escalate_on_warning;
06969                         this_serviceescalation->escalate_on_unknown=template_serviceescalation->escalate_on_unknown;
06970                         this_serviceescalation->escalate_on_critical=template_serviceescalation->escalate_on_critical;
06971                         this_serviceescalation->escalate_on_recovery=template_serviceescalation->escalate_on_recovery;
06972                         this_serviceescalation->have_escalation_options=TRUE;
06973                         }
06974                 }
06975 
06976         my_free(template_names);
06977 
06978         return OK;
06979         }
06980 
06981 
06982 
06983 /* resolves a contact object */
06984 int xodtemplate_resolve_contact(xodtemplate_contact *this_contact){
06985         char *temp_ptr=NULL;
06986         char *template_names=NULL;
06987         char *template_name_ptr=NULL;
06988         xodtemplate_contact *template_contact=NULL;
06989         xodtemplate_customvariablesmember *this_customvariablesmember=NULL;
06990         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
06991         int x;
06992 
06993         /* return if this contact has already been resolved */
06994         if(this_contact->has_been_resolved==TRUE)
06995                 return OK;
06996 
06997         /* set the resolved flag */
06998         this_contact->has_been_resolved=TRUE;
06999 
07000         /* return if we have no template */
07001         if(this_contact->template==NULL)
07002                 return OK;
07003 
07004         if((template_names=(char *)strdup(this_contact->template))==NULL)
07005                 return ERROR;
07006 
07007         /* apply all templates */
07008         template_name_ptr=template_names;
07009         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07010 
07011                 template_contact=xodtemplate_find_contact(temp_ptr);
07012                 if(template_contact==NULL){
07013                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in contact definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_contact->_config_file),this_contact->_start_line);
07014                         my_free(template_names);
07015                         return ERROR;
07016                         }
07017 
07018                 /* resolve the template contact... */
07019                 xodtemplate_resolve_contact(template_contact);
07020 
07021                 /* apply missing properties from template contact... */
07022                 if(this_contact->contact_name==NULL && template_contact->contact_name!=NULL)
07023                         this_contact->contact_name=(char *)strdup(template_contact->contact_name);
07024                 if(this_contact->alias==NULL && template_contact->alias!=NULL)
07025                         this_contact->alias=(char *)strdup(template_contact->alias);
07026 
07027                 if(this_contact->have_email==FALSE && template_contact->have_email==TRUE){
07028                         if(this_contact->email==NULL && template_contact->email!=NULL)
07029                                 this_contact->email=(char *)strdup(template_contact->email);
07030                         this_contact->have_email=TRUE;
07031                         }
07032                 if(this_contact->have_pager==FALSE && template_contact->have_pager==TRUE){
07033                         if(this_contact->pager==NULL && template_contact->pager!=NULL)
07034                                 this_contact->pager=(char *)strdup(template_contact->pager);
07035                         this_contact->have_pager=TRUE;
07036                         }
07037                 for(x=0;x<MAX_XODTEMPLATE_CONTACT_ADDRESSES;x++){
07038                         if(this_contact->have_address[x]==FALSE && template_contact->have_address[x]==TRUE){
07039                                 if(this_contact->address[x]==NULL && template_contact->address[x]!=NULL)
07040                                         this_contact->address[x]=(char *)strdup(template_contact->address[x]);
07041                                 this_contact->have_address[x]=TRUE;
07042                                 }
07043                         }
07044 
07045                 xodtemplate_get_inherited_string(&template_contact->have_contact_groups,&template_contact->contact_groups,&this_contact->have_contact_groups,&this_contact->contact_groups);
07046                 xodtemplate_get_inherited_string(&template_contact->have_host_notification_commands,&template_contact->host_notification_commands,&this_contact->have_host_notification_commands,&this_contact->host_notification_commands);
07047                 xodtemplate_get_inherited_string(&template_contact->have_service_notification_commands,&template_contact->service_notification_commands,&this_contact->have_service_notification_commands,&this_contact->service_notification_commands);
07048 
07049                 if(this_contact->have_host_notification_period==FALSE && template_contact->have_host_notification_period==TRUE){
07050                         if(this_contact->host_notification_period==NULL && template_contact->host_notification_period!=NULL)
07051                                 this_contact->host_notification_period=(char *)strdup(template_contact->host_notification_period);
07052                         this_contact->have_host_notification_period=TRUE;
07053                         }
07054                 if(this_contact->have_service_notification_period==FALSE && template_contact->have_service_notification_period==TRUE){
07055                         if(this_contact->service_notification_period==NULL && template_contact->service_notification_period!=NULL)
07056                                 this_contact->service_notification_period=(char *)strdup(template_contact->service_notification_period);
07057                         this_contact->have_service_notification_period=TRUE;
07058                         }
07059                 if(this_contact->have_host_notification_options==FALSE && template_contact->have_host_notification_options==TRUE){
07060                         this_contact->notify_on_host_down=template_contact->notify_on_host_down;
07061                         this_contact->notify_on_host_unreachable=template_contact->notify_on_host_unreachable;
07062                         this_contact->notify_on_host_recovery=template_contact->notify_on_host_recovery;
07063                         this_contact->notify_on_host_flapping=template_contact->notify_on_host_flapping;
07064                         this_contact->notify_on_host_downtime=template_contact->notify_on_host_downtime;
07065                         this_contact->have_host_notification_options=TRUE;
07066                         }
07067                 if(this_contact->have_service_notification_options==FALSE && template_contact->have_service_notification_options==TRUE){
07068                         this_contact->notify_on_service_unknown=template_contact->notify_on_service_unknown;
07069                         this_contact->notify_on_service_warning=template_contact->notify_on_service_warning;
07070                         this_contact->notify_on_service_critical=template_contact->notify_on_service_critical;
07071                         this_contact->notify_on_service_recovery=template_contact->notify_on_service_recovery;
07072                         this_contact->notify_on_service_flapping=template_contact->notify_on_service_flapping;
07073                         this_contact->notify_on_service_downtime=template_contact->notify_on_service_downtime;
07074                         this_contact->have_service_notification_options=TRUE;
07075                         }
07076                 if(this_contact->have_host_notifications_enabled==FALSE && template_contact->have_host_notifications_enabled==TRUE){
07077                         this_contact->host_notifications_enabled=template_contact->host_notifications_enabled;
07078                         this_contact->have_host_notifications_enabled=TRUE;
07079                         }
07080                 if(this_contact->have_service_notifications_enabled==FALSE && template_contact->have_service_notifications_enabled==TRUE){
07081                         this_contact->service_notifications_enabled=template_contact->service_notifications_enabled;
07082                         this_contact->have_service_notifications_enabled=TRUE;
07083                         }
07084                 if(this_contact->have_can_submit_commands==FALSE && template_contact->have_can_submit_commands==TRUE){
07085                         this_contact->can_submit_commands=template_contact->can_submit_commands;
07086                         this_contact->have_can_submit_commands=TRUE;
07087                         }
07088                 if(this_contact->have_retain_status_information==FALSE && template_contact->have_retain_status_information==TRUE){
07089                         this_contact->retain_status_information=template_contact->retain_status_information;
07090                         this_contact->have_retain_status_information=TRUE;
07091                         }
07092                 if(this_contact->have_retain_nonstatus_information==FALSE && template_contact->have_retain_nonstatus_information==TRUE){
07093                         this_contact->retain_nonstatus_information=template_contact->retain_nonstatus_information;
07094                         this_contact->have_retain_nonstatus_information=TRUE;
07095                         }
07096 
07097                 /* apply missing custom variables from template contact... */
07098                 for(temp_customvariablesmember=template_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
07099 
07100                         /* see if this host has a variable by the same name */
07101                         for(this_customvariablesmember=this_contact->custom_variables;this_customvariablesmember!=NULL;this_customvariablesmember=this_customvariablesmember->next){
07102                                 if(!strcmp(temp_customvariablesmember->variable_name,this_customvariablesmember->variable_name))
07103                                         break;
07104                                 }
07105 
07106                         /* we didn't find the same variable name, so add a new custom variable */
07107                         if(this_customvariablesmember==NULL)
07108                                 xodtemplate_add_custom_variable_to_contact(this_contact,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value);
07109                         }
07110                 }
07111         
07112         my_free(template_names);
07113 
07114         return OK;
07115         }
07116 
07117 
07118 
07119 /* resolves a host object */
07120 int xodtemplate_resolve_host(xodtemplate_host *this_host){
07121         char *temp_ptr=NULL;
07122         char *template_names=NULL;
07123         char *template_name_ptr=NULL;
07124         xodtemplate_host *template_host=NULL;
07125         xodtemplate_customvariablesmember *this_customvariablesmember=NULL;
07126         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
07127 
07128         /* return if this host has already been resolved */
07129         if(this_host->has_been_resolved==TRUE)
07130                 return OK;
07131 
07132         /* set the resolved flag */
07133         this_host->has_been_resolved=TRUE;
07134 
07135         /* return if we have no template */
07136         if(this_host->template==NULL)
07137                 return OK;
07138 
07139         if((template_names=(char *)strdup(this_host->template))==NULL)
07140                 return ERROR;
07141 
07142         /* apply all templates */
07143         template_name_ptr=template_names;
07144         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07145 
07146                 template_host=xodtemplate_find_host(temp_ptr);
07147                 if(template_host==NULL){
07148                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in host definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
07149                         my_free(template_names);
07150                         return ERROR;
07151                         }
07152 
07153                 /* resolve the template host... */
07154                 xodtemplate_resolve_host(template_host);
07155 
07156                 /* apply missing properties from template host... */
07157                 if(this_host->host_name==NULL && template_host->host_name!=NULL)
07158                         this_host->host_name=(char *)strdup(template_host->host_name);
07159                 if(this_host->have_display_name==FALSE && template_host->have_display_name==TRUE){
07160                         if(this_host->display_name==NULL && template_host->display_name!=NULL)
07161                                 this_host->display_name=(char *)strdup(template_host->display_name);
07162                         this_host->have_display_name=TRUE;
07163                         }
07164                 if(this_host->alias==NULL && template_host->alias!=NULL)
07165                         this_host->alias=(char *)strdup(template_host->alias);
07166                 if(this_host->address==NULL && template_host->address!=NULL)
07167                         this_host->address=(char *)strdup(template_host->address);
07168                 if(this_host->address6==NULL && template_host->address6!=NULL)
07169                         this_host->address6=(char *)strdup(template_host->address6);
07170 
07171                 xodtemplate_get_inherited_string(&template_host->have_parents,&template_host->parents,&this_host->have_parents,&this_host->parents);
07172                 xodtemplate_get_inherited_string(&template_host->have_host_groups,&template_host->host_groups,&this_host->have_host_groups,&this_host->host_groups);
07173                 xodtemplate_get_inherited_string(&template_host->have_contact_groups,&template_host->contact_groups,&this_host->have_contact_groups,&this_host->contact_groups);
07174                 xodtemplate_get_inherited_string(&template_host->have_contacts,&template_host->contacts,&this_host->have_contacts,&this_host->contacts);
07175 
07176                 if(this_host->have_check_command==FALSE && template_host->have_check_command==TRUE){
07177                         if(this_host->check_command==NULL && template_host->check_command!=NULL)
07178                                 this_host->check_command=(char *)strdup(template_host->check_command);
07179                         this_host->have_check_command=TRUE;
07180                         }
07181                 if(this_host->have_check_period==FALSE && template_host->have_check_period==TRUE){
07182                         if(this_host->check_period==NULL && template_host->check_period!=NULL)
07183                                 this_host->check_period=(char *)strdup(template_host->check_period);
07184                         this_host->have_check_period=TRUE;
07185                         }
07186                 if(this_host->have_event_handler==FALSE && template_host->have_event_handler==TRUE){
07187                         if(this_host->event_handler==NULL && template_host->event_handler!=NULL)
07188                                 this_host->event_handler=(char *)strdup(template_host->event_handler);
07189                         this_host->have_event_handler=TRUE;
07190                         }
07191                 if(this_host->have_notification_period==FALSE && template_host->have_notification_period==TRUE){
07192                         if(this_host->notification_period==NULL && template_host->notification_period!=NULL)
07193                                 this_host->notification_period=(char *)strdup(template_host->notification_period);
07194                         this_host->have_notification_period=TRUE;
07195                         }
07196                 if(this_host->have_failure_prediction_options==FALSE && template_host->have_failure_prediction_options==TRUE){
07197                         if(this_host->failure_prediction_options==NULL && template_host->failure_prediction_options!=NULL)
07198                                 this_host->failure_prediction_options=(char *)strdup(template_host->failure_prediction_options);
07199                         this_host->have_failure_prediction_options=TRUE;
07200                         }
07201                 if(this_host->have_notes==FALSE && template_host->have_notes==TRUE){
07202                         if(this_host->notes==NULL && template_host->notes!=NULL)
07203                                 this_host->notes=(char *)strdup(template_host->notes);
07204                         this_host->have_notes=TRUE;
07205                         }
07206                 if(this_host->have_notes_url==FALSE && template_host->have_notes_url==TRUE){
07207                         if(this_host->notes_url==NULL && template_host->notes_url!=NULL)
07208                                 this_host->notes_url=(char *)strdup(template_host->notes_url);
07209                         this_host->have_notes_url=TRUE;
07210                         }
07211                 if(this_host->have_action_url==FALSE && template_host->have_action_url==TRUE){
07212                         if(this_host->action_url==NULL && template_host->action_url!=NULL)
07213                                 this_host->action_url=(char *)strdup(template_host->action_url);
07214                         this_host->have_action_url=TRUE;
07215                         }
07216                 if(this_host->have_icon_image==FALSE && template_host->have_icon_image==TRUE){
07217                         if(this_host->icon_image==NULL && template_host->icon_image!=NULL)
07218                                 this_host->icon_image=(char *)strdup(template_host->icon_image);
07219                         this_host->have_icon_image=TRUE;
07220                         }
07221                 if(this_host->have_icon_image_alt==FALSE && template_host->have_icon_image_alt==TRUE){
07222                         if(this_host->icon_image_alt==NULL && template_host->icon_image_alt!=NULL)
07223                                 this_host->icon_image_alt=(char *)strdup(template_host->icon_image_alt);
07224                         this_host->have_icon_image_alt=TRUE;
07225                         }
07226                 if(this_host->have_vrml_image==FALSE && template_host->have_vrml_image==TRUE){
07227                         if(this_host->vrml_image==NULL && template_host->vrml_image!=NULL)
07228                                 this_host->vrml_image=(char *)strdup(template_host->vrml_image);
07229                         this_host->have_vrml_image=TRUE;
07230                         }
07231                 if(this_host->have_statusmap_image==FALSE && template_host->have_statusmap_image==TRUE){
07232                         if(this_host->statusmap_image==NULL && template_host->statusmap_image!=NULL)
07233                                 this_host->statusmap_image=(char *)strdup(template_host->statusmap_image);
07234                         this_host->have_statusmap_image=TRUE;
07235                         }
07236                 if(this_host->have_initial_state==FALSE && template_host->have_initial_state==TRUE){
07237                         this_host->initial_state=template_host->initial_state;
07238                         this_host->have_initial_state=TRUE;
07239                         }
07240                 if(this_host->have_check_interval==FALSE && template_host->have_check_interval==TRUE){
07241                         this_host->check_interval=template_host->check_interval;
07242                         this_host->have_check_interval=TRUE;
07243                         }
07244                 if(this_host->have_retry_interval==FALSE && template_host->have_retry_interval==TRUE){
07245                         this_host->retry_interval=template_host->retry_interval;
07246                         this_host->have_retry_interval=TRUE;
07247                         }
07248                 if(this_host->have_max_check_attempts==FALSE && template_host->have_max_check_attempts==TRUE){
07249                         this_host->max_check_attempts=template_host->max_check_attempts;
07250                         this_host->have_max_check_attempts=TRUE;
07251                         }
07252                 if(this_host->have_active_checks_enabled==FALSE && template_host->have_active_checks_enabled==TRUE){
07253                         this_host->active_checks_enabled=template_host->active_checks_enabled;
07254                         this_host->have_active_checks_enabled=TRUE;
07255                         }
07256                 if(this_host->have_passive_checks_enabled==FALSE && template_host->have_passive_checks_enabled==TRUE){
07257                         this_host->passive_checks_enabled=template_host->passive_checks_enabled;
07258                         this_host->have_passive_checks_enabled=TRUE;
07259                         }
07260                 if(this_host->have_obsess_over_host==FALSE && template_host->have_obsess_over_host==TRUE){
07261                         this_host->obsess_over_host=template_host->obsess_over_host;
07262                         this_host->have_obsess_over_host=TRUE;
07263                         }
07264                 if(this_host->have_event_handler_enabled==FALSE && template_host->have_event_handler_enabled==TRUE){
07265                         this_host->event_handler_enabled=template_host->event_handler_enabled;
07266                         this_host->have_event_handler_enabled=TRUE;
07267                         }
07268                 if(this_host->have_check_freshness==FALSE && template_host->have_check_freshness==TRUE){
07269                         this_host->check_freshness=template_host->check_freshness;
07270                         this_host->have_check_freshness=TRUE;
07271                         }
07272                 if(this_host->have_freshness_threshold==FALSE && template_host->have_freshness_threshold==TRUE){
07273                         this_host->freshness_threshold=template_host->freshness_threshold;
07274                         this_host->have_freshness_threshold=TRUE;
07275                         }
07276                 if(this_host->have_low_flap_threshold==FALSE && template_host->have_low_flap_threshold==TRUE){
07277                         this_host->low_flap_threshold=template_host->low_flap_threshold;
07278                         this_host->have_low_flap_threshold=TRUE;
07279                         }
07280                 if(this_host->have_high_flap_threshold==FALSE && template_host->have_high_flap_threshold==TRUE){
07281                         this_host->high_flap_threshold=template_host->high_flap_threshold;
07282                         this_host->have_high_flap_threshold=TRUE;
07283                         }
07284                 if(this_host->have_flap_detection_enabled==FALSE && template_host->have_flap_detection_enabled==TRUE){
07285                         this_host->flap_detection_enabled=template_host->flap_detection_enabled;
07286                         this_host->have_flap_detection_enabled=TRUE;
07287                         }
07288                 if(this_host->have_flap_detection_options==FALSE && template_host->have_flap_detection_options==TRUE){
07289                         this_host->flap_detection_on_up=template_host->flap_detection_on_up;
07290                         this_host->flap_detection_on_down=template_host->flap_detection_on_down;
07291                         this_host->flap_detection_on_unreachable=template_host->flap_detection_on_unreachable;
07292                         this_host->have_flap_detection_options=TRUE;
07293                         }
07294                 if(this_host->have_notification_options==FALSE && template_host->have_notification_options==TRUE){
07295                         this_host->notify_on_down=template_host->notify_on_down;
07296                         this_host->notify_on_unreachable=template_host->notify_on_unreachable;
07297                         this_host->notify_on_recovery=template_host->notify_on_recovery;
07298                         this_host->notify_on_flapping=template_host->notify_on_flapping;
07299                         this_host->notify_on_downtime=template_host->notify_on_downtime;
07300                         this_host->have_notification_options=TRUE;
07301                         }
07302                 if(this_host->have_notifications_enabled==FALSE && template_host->have_notifications_enabled==TRUE){
07303                         this_host->notifications_enabled=template_host->notifications_enabled;
07304                         this_host->have_notifications_enabled=TRUE;
07305                         }
07306                 if(this_host->have_notification_interval==FALSE && template_host->have_notification_interval==TRUE){
07307                         this_host->notification_interval=template_host->notification_interval;
07308                         this_host->have_notification_interval=TRUE;
07309                         }
07310                 if(this_host->have_first_notification_delay==FALSE && template_host->have_first_notification_delay==TRUE){
07311                         this_host->first_notification_delay=template_host->first_notification_delay;
07312                         this_host->have_first_notification_delay=TRUE;
07313                         }
07314                 if(this_host->have_stalking_options==FALSE && template_host->have_stalking_options==TRUE){
07315                         this_host->stalk_on_up=template_host->stalk_on_up;
07316                         this_host->stalk_on_down=template_host->stalk_on_down;
07317                         this_host->stalk_on_unreachable=template_host->stalk_on_unreachable;
07318                         this_host->have_stalking_options=TRUE;
07319                         }
07320                 if(this_host->have_process_perf_data==FALSE && template_host->have_process_perf_data==TRUE){
07321                         this_host->process_perf_data=template_host->process_perf_data;
07322                         this_host->have_process_perf_data=TRUE;
07323                         }
07324                 if(this_host->have_failure_prediction_enabled==FALSE && template_host->have_failure_prediction_enabled==TRUE){
07325                         this_host->failure_prediction_enabled=template_host->failure_prediction_enabled;
07326                         this_host->have_failure_prediction_enabled=TRUE;
07327                         }
07328                 if(this_host->have_2d_coords==FALSE && template_host->have_2d_coords==TRUE){
07329                         this_host->x_2d=template_host->x_2d;
07330                         this_host->y_2d=template_host->y_2d;
07331                         this_host->have_2d_coords=TRUE;
07332                         }
07333                 if(this_host->have_3d_coords==FALSE && template_host->have_3d_coords==TRUE){
07334                         this_host->x_3d=template_host->x_3d;
07335                         this_host->y_3d=template_host->y_3d;
07336                         this_host->z_3d=template_host->z_3d;
07337                         this_host->have_3d_coords=TRUE;
07338                         }
07339                 if(this_host->have_retain_status_information==FALSE && template_host->have_retain_status_information==TRUE){
07340                         this_host->retain_status_information=template_host->retain_status_information;
07341                         this_host->have_retain_status_information=TRUE;
07342                         }
07343                 if(this_host->have_retain_nonstatus_information==FALSE && template_host->have_retain_nonstatus_information==TRUE){
07344                         this_host->retain_nonstatus_information=template_host->retain_nonstatus_information;
07345                         this_host->have_retain_nonstatus_information=TRUE;
07346                         }
07347 
07348                 /* apply missing custom variables from template host... */
07349                 for(temp_customvariablesmember=template_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
07350 
07351                         /* see if this host has a variable by the same name */
07352                         for(this_customvariablesmember=this_host->custom_variables;this_customvariablesmember!=NULL;this_customvariablesmember=this_customvariablesmember->next){
07353                                 if(!strcmp(temp_customvariablesmember->variable_name,this_customvariablesmember->variable_name))
07354                                         break;
07355                                 }
07356 
07357                         /* we didn't find the same variable name, so add a new custom variable */
07358                         if(this_customvariablesmember==NULL)
07359                                 xodtemplate_add_custom_variable_to_host(this_host,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value);
07360                         }
07361                 }
07362 
07363         my_free(template_names);
07364 
07365         return OK;
07366         }
07367 
07368 
07369 
07370 /* resolves a service object */
07371 int xodtemplate_resolve_service(xodtemplate_service *this_service){
07372         char *temp_ptr=NULL;
07373         char *template_names=NULL;
07374         char *template_name_ptr=NULL;
07375         xodtemplate_service *template_service=NULL;
07376         xodtemplate_customvariablesmember *this_customvariablesmember=NULL;
07377         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
07378 
07379         /* return if this service has already been resolved */
07380         if(this_service->has_been_resolved==TRUE)
07381                 return OK;
07382 
07383         /* set the resolved flag */
07384         this_service->has_been_resolved=TRUE;
07385 
07386         /* return if we have no template */
07387         if(this_service->template==NULL)
07388                 return OK;
07389 
07390         if((template_names=(char *)strdup(this_service->template))==NULL)
07391                 return ERROR;
07392 
07393         /* apply all templates */
07394         template_name_ptr=template_names;
07395         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07396 
07397                 template_service=xodtemplate_find_service(temp_ptr);
07398                 if(template_service==NULL){
07399                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in service definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_service->_config_file),this_service->_start_line);
07400                         my_free(template_names);
07401                         return ERROR;
07402                         }
07403 
07404                 /* resolve the template service... */
07405                 xodtemplate_resolve_service(template_service);
07406 
07407                 /* apply missing properties from template service... */
07408                 if(this_service->have_service_description==FALSE && template_service->have_service_description==TRUE){
07409                         if(this_service->service_description==NULL && template_service->service_description!=NULL)
07410                                 this_service->service_description=(char *)strdup(template_service->service_description);
07411                         this_service->have_service_description=TRUE;
07412                         }
07413                 if(this_service->have_display_name==FALSE && template_service->have_display_name==TRUE){
07414                         if(this_service->display_name==NULL && template_service->display_name!=NULL)
07415                                 this_service->display_name=(char *)strdup(template_service->display_name);
07416                         this_service->have_display_name=TRUE;
07417                         }
07418 
07419                 xodtemplate_get_inherited_string(&template_service->have_host_name,&template_service->host_name,&this_service->have_host_name,&this_service->host_name);
07420                 xodtemplate_get_inherited_string(&template_service->have_hostgroup_name,&template_service->hostgroup_name,&this_service->have_hostgroup_name,&this_service->hostgroup_name);
07421                 xodtemplate_get_inherited_string(&template_service->have_service_groups,&template_service->service_groups,&this_service->have_service_groups,&this_service->service_groups);
07422                 xodtemplate_get_inherited_string(&template_service->have_contact_groups,&template_service->contact_groups,&this_service->have_contact_groups,&this_service->contact_groups);
07423                 xodtemplate_get_inherited_string(&template_service->have_contacts,&template_service->contacts,&this_service->have_contacts,&this_service->contacts);
07424 
07425                 if(template_service->have_check_command==TRUE){
07426                         if(template_service->have_important_check_command==TRUE){
07427                                 my_free(this_service->check_command);
07428                                 this_service->have_check_command=FALSE;
07429                                 }
07430                         if(this_service->have_check_command==FALSE){
07431                                 if(this_service->check_command==NULL && template_service->check_command!=NULL)
07432                                         this_service->check_command=(char *)strdup(template_service->check_command);
07433                                 this_service->have_check_command=TRUE;
07434                                 }
07435                         }
07436                 if(this_service->have_check_period==FALSE && template_service->have_check_period==TRUE){
07437                         if(this_service->check_period==NULL && template_service->check_period!=NULL)
07438                                 this_service->check_period=(char *)strdup(template_service->check_period);
07439                         this_service->have_check_period=TRUE;
07440                         }
07441                 if(this_service->have_event_handler==FALSE && template_service->have_event_handler==TRUE){
07442                         if(this_service->event_handler==NULL && template_service->event_handler!=NULL)
07443                                 this_service->event_handler=(char *)strdup(template_service->event_handler);
07444                         this_service->have_event_handler=TRUE;
07445                         }
07446                 if(this_service->have_notification_period==FALSE && template_service->have_notification_period==TRUE){
07447                         if(this_service->notification_period==NULL && template_service->notification_period!=NULL)
07448                                 this_service->notification_period=(char *)strdup(template_service->notification_period);
07449                         this_service->have_notification_period=TRUE;
07450                         }
07451                 if(this_service->have_failure_prediction_options==FALSE && template_service->have_failure_prediction_options==TRUE){
07452                         if(this_service->failure_prediction_options==NULL && template_service->failure_prediction_options!=NULL)
07453                                 this_service->failure_prediction_options=(char *)strdup(template_service->failure_prediction_options);
07454                         this_service->have_failure_prediction_options=TRUE;
07455                         }
07456                 if(this_service->have_notes==FALSE && template_service->have_notes==TRUE){
07457                         if(this_service->notes==NULL && template_service->notes!=NULL)
07458                                 this_service->notes=(char *)strdup(template_service->notes);
07459                         this_service->have_notes=TRUE;
07460                         }
07461                 if(this_service->have_notes_url==FALSE && template_service->have_notes_url==TRUE){
07462                         if(this_service->notes_url==NULL && template_service->notes_url!=NULL)
07463                                 this_service->notes_url=(char *)strdup(template_service->notes_url);
07464                         this_service->have_notes_url=TRUE;
07465                         }
07466                 if(this_service->have_action_url==FALSE && template_service->have_action_url==TRUE){
07467                         if(this_service->action_url==NULL && template_service->action_url!=NULL)
07468                                 this_service->action_url=(char *)strdup(template_service->action_url);
07469                         this_service->have_action_url=TRUE;
07470                         }
07471                 if(this_service->have_icon_image==FALSE && template_service->have_icon_image==TRUE){
07472                         if(this_service->icon_image==NULL && template_service->icon_image!=NULL)
07473                                 this_service->icon_image=(char *)strdup(template_service->icon_image);
07474                         this_service->have_icon_image=TRUE;
07475                         }
07476                 if(this_service->have_icon_image_alt==FALSE && template_service->have_icon_image_alt==TRUE){
07477                         if(this_service->icon_image_alt==NULL && template_service->icon_image_alt!=NULL)
07478                                 this_service->icon_image_alt=(char *)strdup(template_service->icon_image_alt);
07479                         this_service->have_icon_image_alt=TRUE;
07480                         }
07481                 if(this_service->have_initial_state==FALSE && template_service->have_initial_state==TRUE){
07482                         this_service->initial_state=template_service->initial_state;
07483                         this_service->have_initial_state=TRUE;
07484                         }
07485                 if(this_service->have_max_check_attempts==FALSE && template_service->have_max_check_attempts==TRUE){
07486                         this_service->max_check_attempts=template_service->max_check_attempts;
07487                         this_service->have_max_check_attempts=TRUE;
07488                         }
07489                 if(this_service->have_check_interval==FALSE && template_service->have_check_interval==TRUE){
07490                         this_service->check_interval=template_service->check_interval;
07491                         this_service->have_check_interval=TRUE;
07492                         }
07493                 if(this_service->have_retry_interval==FALSE && template_service->have_retry_interval==TRUE){
07494                         this_service->retry_interval=template_service->retry_interval;
07495                         this_service->have_retry_interval=TRUE;
07496                         }
07497                 if(this_service->have_active_checks_enabled==FALSE && template_service->have_active_checks_enabled==TRUE){
07498                         this_service->active_checks_enabled=template_service->active_checks_enabled;
07499                         this_service->have_active_checks_enabled=TRUE;
07500                         }
07501                 if(this_service->have_passive_checks_enabled==FALSE && template_service->have_passive_checks_enabled==TRUE){
07502                         this_service->passive_checks_enabled=template_service->passive_checks_enabled;
07503                         this_service->have_passive_checks_enabled=TRUE;
07504                         }
07505                 if(this_service->have_parallelize_check==FALSE && template_service->have_parallelize_check==TRUE){
07506                         this_service->parallelize_check=template_service->parallelize_check;
07507                         this_service->have_parallelize_check=TRUE;
07508                         }
07509                 if(this_service->have_is_volatile==FALSE && template_service->have_is_volatile==TRUE){
07510                         this_service->is_volatile=template_service->is_volatile;
07511                         this_service->have_is_volatile=TRUE;
07512                         }
07513                 if(this_service->have_obsess_over_service==FALSE && template_service->have_obsess_over_service==TRUE){
07514                         this_service->obsess_over_service=template_service->obsess_over_service;
07515                         this_service->have_obsess_over_service=TRUE;
07516                         }
07517                 if(this_service->have_event_handler_enabled==FALSE && template_service->have_event_handler_enabled==TRUE){
07518                         this_service->event_handler_enabled=template_service->event_handler_enabled;
07519                         this_service->have_event_handler_enabled=TRUE;
07520                         }
07521                 if(this_service->have_check_freshness==FALSE && template_service->have_check_freshness==TRUE){
07522                         this_service->check_freshness=template_service->check_freshness;
07523                         this_service->have_check_freshness=TRUE;
07524                         }
07525                 if(this_service->have_freshness_threshold==FALSE && template_service->have_freshness_threshold==TRUE){
07526                         this_service->freshness_threshold=template_service->freshness_threshold;
07527                         this_service->have_freshness_threshold=TRUE;
07528                         }
07529                 if(this_service->have_low_flap_threshold==FALSE && template_service->have_low_flap_threshold==TRUE){
07530                         this_service->low_flap_threshold=template_service->low_flap_threshold;
07531                         this_service->have_low_flap_threshold=TRUE;
07532                         }
07533                 if(this_service->have_high_flap_threshold==FALSE && template_service->have_high_flap_threshold==TRUE){
07534                         this_service->high_flap_threshold=template_service->high_flap_threshold;
07535                         this_service->have_high_flap_threshold=TRUE;
07536                         }
07537                 if(this_service->have_flap_detection_enabled==FALSE && template_service->have_flap_detection_enabled==TRUE){
07538                         this_service->flap_detection_enabled=template_service->flap_detection_enabled;
07539                         this_service->have_flap_detection_enabled=TRUE;
07540                         }
07541                 if(this_service->have_flap_detection_options==FALSE && template_service->have_flap_detection_options==TRUE){
07542                         this_service->flap_detection_on_ok=template_service->flap_detection_on_ok;
07543                         this_service->flap_detection_on_unknown=template_service->flap_detection_on_unknown;
07544                         this_service->flap_detection_on_warning=template_service->flap_detection_on_warning;
07545                         this_service->flap_detection_on_critical=template_service->flap_detection_on_critical;
07546                         this_service->have_flap_detection_options=TRUE;
07547                         }
07548                 if(this_service->have_notification_options==FALSE && template_service->have_notification_options==TRUE){
07549                         this_service->notify_on_unknown=template_service->notify_on_unknown;
07550                         this_service->notify_on_warning=template_service->notify_on_warning;
07551                         this_service->notify_on_critical=template_service->notify_on_critical;
07552                         this_service->notify_on_recovery=template_service->notify_on_recovery;
07553                         this_service->notify_on_flapping=template_service->notify_on_flapping;
07554                         this_service->notify_on_downtime=template_service->notify_on_downtime;
07555                         this_service->have_notification_options=TRUE;
07556                         }
07557                 if(this_service->have_notifications_enabled==FALSE && template_service->have_notifications_enabled==TRUE){
07558                         this_service->notifications_enabled=template_service->notifications_enabled;
07559                         this_service->have_notifications_enabled=TRUE;
07560                         }
07561                 if(this_service->have_notification_interval==FALSE && template_service->have_notification_interval==TRUE){
07562                         this_service->notification_interval=template_service->notification_interval;
07563                         this_service->have_notification_interval=TRUE;
07564                         }
07565                 if(this_service->have_first_notification_delay==FALSE && template_service->have_first_notification_delay==TRUE){
07566                         this_service->first_notification_delay=template_service->first_notification_delay;
07567                         this_service->have_first_notification_delay=TRUE;
07568                         }
07569                 if(this_service->have_stalking_options==FALSE && template_service->have_stalking_options==TRUE){
07570                         this_service->stalk_on_ok=template_service->stalk_on_ok;
07571                         this_service->stalk_on_unknown=template_service->stalk_on_unknown;
07572                         this_service->stalk_on_warning=template_service->stalk_on_warning;
07573                         this_service->stalk_on_critical=template_service->stalk_on_critical;
07574                         this_service->have_stalking_options=TRUE;
07575                         }
07576                 if(this_service->have_process_perf_data==FALSE && template_service->have_process_perf_data==TRUE){
07577                         this_service->process_perf_data=template_service->process_perf_data;
07578                         this_service->have_process_perf_data=TRUE;
07579                         }
07580                 if(this_service->have_failure_prediction_enabled==FALSE && template_service->have_failure_prediction_enabled==TRUE){
07581                         this_service->failure_prediction_enabled=template_service->failure_prediction_enabled;
07582                         this_service->have_failure_prediction_enabled=TRUE;
07583                         }
07584                 if(this_service->have_retain_status_information==FALSE && template_service->have_retain_status_information==TRUE){
07585                         this_service->retain_status_information=template_service->retain_status_information;
07586                         this_service->have_retain_status_information=TRUE;
07587                         }
07588                 if(this_service->have_retain_nonstatus_information==FALSE && template_service->have_retain_nonstatus_information==TRUE){
07589                         this_service->retain_nonstatus_information=template_service->retain_nonstatus_information;
07590                         this_service->have_retain_nonstatus_information=TRUE;
07591                         }
07592 
07593                 /* apply missing custom variables from template service... */
07594                 for(temp_customvariablesmember=template_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
07595 
07596                         /* see if this host has a variable by the same name */
07597                         for(this_customvariablesmember=this_service->custom_variables;this_customvariablesmember!=NULL;this_customvariablesmember=this_customvariablesmember->next){
07598                                 if(!strcmp(temp_customvariablesmember->variable_name,this_customvariablesmember->variable_name))
07599                                         break;
07600                                 }
07601 
07602                         /* we didn't find the same variable name, so add a new custom variable */
07603                         if(this_customvariablesmember==NULL)
07604                                 xodtemplate_add_custom_variable_to_service(this_service,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value);
07605                         }
07606                 }
07607 
07608         my_free(template_names);
07609 
07610         return OK;
07611         }
07612 
07613 
07614 /* resolves a hostdependency object */
07615 int xodtemplate_resolve_hostdependency(xodtemplate_hostdependency *this_hostdependency){
07616         char *temp_ptr=NULL;
07617         char *template_names=NULL;
07618         char *template_name_ptr=NULL;
07619         xodtemplate_hostdependency *template_hostdependency=NULL;
07620 
07621         /* return if this hostdependency has already been resolved */
07622         if(this_hostdependency->has_been_resolved==TRUE)
07623                 return OK;
07624 
07625         /* set the resolved flag */
07626         this_hostdependency->has_been_resolved=TRUE;
07627 
07628         /* return if we have no template */
07629         if(this_hostdependency->template==NULL)
07630                 return OK;
07631 
07632         if((template_names=(char *)strdup(this_hostdependency->template))==NULL)
07633                 return ERROR;
07634 
07635         /* apply all templates */
07636         template_name_ptr=template_names;
07637         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07638 
07639                 template_hostdependency=xodtemplate_find_hostdependency(temp_ptr);
07640                 if(template_hostdependency==NULL){
07641                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in host dependency definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_hostdependency->_config_file),this_hostdependency->_start_line);
07642                         my_free(template_names);
07643                         return ERROR;
07644                         }
07645 
07646                 /* resolve the template hostdependency... */
07647                 xodtemplate_resolve_hostdependency(template_hostdependency);
07648 
07649                 /* apply missing properties from template hostdependency... */
07650 
07651                 xodtemplate_get_inherited_string(&template_hostdependency->have_host_name,&template_hostdependency->host_name,&this_hostdependency->have_host_name,&this_hostdependency->host_name);
07652                 xodtemplate_get_inherited_string(&template_hostdependency->have_dependent_host_name,&template_hostdependency->dependent_host_name,&this_hostdependency->have_dependent_host_name,&this_hostdependency->dependent_host_name);
07653                 xodtemplate_get_inherited_string(&template_hostdependency->have_hostgroup_name,&template_hostdependency->hostgroup_name,&this_hostdependency->have_hostgroup_name,&this_hostdependency->hostgroup_name);
07654                 xodtemplate_get_inherited_string(&template_hostdependency->have_dependent_hostgroup_name,&template_hostdependency->dependent_hostgroup_name,&this_hostdependency->have_dependent_hostgroup_name,&this_hostdependency->dependent_hostgroup_name);
07655 
07656                 if(this_hostdependency->have_dependency_period==FALSE && template_hostdependency->have_dependency_period==TRUE){
07657                         if(this_hostdependency->dependency_period==NULL && template_hostdependency->dependency_period!=NULL)
07658                                 this_hostdependency->dependency_period=(char *)strdup(template_hostdependency->dependency_period);
07659                         this_hostdependency->have_dependency_period=TRUE;
07660                         }
07661                 if(this_hostdependency->have_inherits_parent==FALSE && template_hostdependency->have_inherits_parent==TRUE){
07662                         this_hostdependency->inherits_parent=template_hostdependency->inherits_parent;
07663                         this_hostdependency->have_inherits_parent=TRUE;
07664                         }
07665                 if(this_hostdependency->have_execution_dependency_options==FALSE && template_hostdependency->have_execution_dependency_options==TRUE){
07666                         this_hostdependency->fail_execute_on_up=template_hostdependency->fail_execute_on_up;
07667                         this_hostdependency->fail_execute_on_down=template_hostdependency->fail_execute_on_down;
07668                         this_hostdependency->fail_execute_on_unreachable=template_hostdependency->fail_execute_on_unreachable;
07669                         this_hostdependency->fail_execute_on_pending=template_hostdependency->fail_execute_on_pending;
07670                         this_hostdependency->have_execution_dependency_options=TRUE;
07671                         }
07672                 if(this_hostdependency->have_notification_dependency_options==FALSE && template_hostdependency->have_notification_dependency_options==TRUE){
07673                         this_hostdependency->fail_notify_on_up=template_hostdependency->fail_notify_on_up;
07674                         this_hostdependency->fail_notify_on_down=template_hostdependency->fail_notify_on_down;
07675                         this_hostdependency->fail_notify_on_unreachable=template_hostdependency->fail_notify_on_unreachable;
07676                         this_hostdependency->fail_notify_on_pending=template_hostdependency->fail_notify_on_pending;
07677                         this_hostdependency->have_notification_dependency_options=TRUE;
07678                         }
07679                 }
07680 
07681         my_free(template_names);
07682 
07683         return OK;
07684         }
07685 
07686 
07687 /* resolves a hostescalation object */
07688 int xodtemplate_resolve_hostescalation(xodtemplate_hostescalation *this_hostescalation){
07689         char *temp_ptr=NULL;
07690         char *template_names=NULL;
07691         char *template_name_ptr=NULL;
07692         xodtemplate_hostescalation *template_hostescalation=NULL;
07693 
07694         /* return if this hostescalation has already been resolved */
07695         if(this_hostescalation->has_been_resolved==TRUE)
07696                 return OK;
07697 
07698         /* set the resolved flag */
07699         this_hostescalation->has_been_resolved=TRUE;
07700 
07701         /* return if we have no template */
07702         if(this_hostescalation->template==NULL)
07703                 return OK;
07704 
07705         if((template_names=(char *)strdup(this_hostescalation->template))==NULL)
07706                 return ERROR;
07707 
07708         /* apply all templates */
07709         template_name_ptr=template_names;
07710         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07711 
07712                 template_hostescalation=xodtemplate_find_hostescalation(temp_ptr);
07713                 if(template_hostescalation==NULL){
07714                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in host escalation definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_hostescalation->_config_file),this_hostescalation->_start_line);
07715                         my_free(template_names);
07716                         return ERROR;
07717                         }
07718 
07719                 /* resolve the template hostescalation... */
07720                 xodtemplate_resolve_hostescalation(template_hostescalation);
07721 
07722                 /* apply missing properties from template hostescalation... */
07723                 xodtemplate_get_inherited_string(&template_hostescalation->have_host_name,&template_hostescalation->host_name,&this_hostescalation->have_host_name,&this_hostescalation->host_name);
07724                 xodtemplate_get_inherited_string(&template_hostescalation->have_hostgroup_name,&template_hostescalation->hostgroup_name,&this_hostescalation->have_hostgroup_name,&this_hostescalation->hostgroup_name);
07725                 xodtemplate_get_inherited_string(&template_hostescalation->have_contact_groups,&template_hostescalation->contact_groups,&this_hostescalation->have_contact_groups,&this_hostescalation->contact_groups);
07726                 xodtemplate_get_inherited_string(&template_hostescalation->have_contacts,&template_hostescalation->contacts,&this_hostescalation->have_contacts,&this_hostescalation->contacts);
07727 
07728                 if(this_hostescalation->have_escalation_period==FALSE && template_hostescalation->have_escalation_period==TRUE){
07729                         if(this_hostescalation->escalation_period==NULL && template_hostescalation->escalation_period!=NULL)
07730                                 this_hostescalation->escalation_period=(char *)strdup(template_hostescalation->escalation_period);
07731                         this_hostescalation->have_escalation_period=TRUE;
07732                         }
07733                 if(this_hostescalation->have_first_notification==FALSE && template_hostescalation->have_first_notification==TRUE){
07734                         this_hostescalation->first_notification=template_hostescalation->first_notification;
07735                         this_hostescalation->have_first_notification=TRUE;
07736                         }
07737                 if(this_hostescalation->have_last_notification==FALSE && template_hostescalation->have_last_notification==TRUE){
07738                         this_hostescalation->last_notification=template_hostescalation->last_notification;
07739                         this_hostescalation->have_last_notification=TRUE;
07740                         }
07741 #ifdef USE_ST_BASED_ESCAL_RANGES
07742                 if(this_hostescalation->have_first_down_notification==FALSE && template_hostescalation->have_first_down_notification==TRUE){
07743                         this_hostescalation->first_down_notification=template_hostescalation->first_down_notification;
07744                         this_hostescalation->have_first_down_notification=TRUE;
07745                         }
07746                 if(this_hostescalation->have_last_down_notification==FALSE && template_hostescalation->have_last_down_notification==TRUE){
07747                         this_hostescalation->last_down_notification=template_hostescalation->last_down_notification;
07748                         this_hostescalation->have_last_down_notification=TRUE;
07749                         }
07750                 if(this_hostescalation->have_first_unreachable_notification==FALSE && template_hostescalation->have_first_unreachable_notification==TRUE){
07751                         this_hostescalation->first_unreachable_notification=template_hostescalation->first_unreachable_notification;
07752                         this_hostescalation->have_first_unreachable_notification=TRUE;
07753                         }
07754                 if(this_hostescalation->have_last_unreachable_notification==FALSE && template_hostescalation->have_last_unreachable_notification==TRUE){
07755                         this_hostescalation->last_unreachable_notification=template_hostescalation->last_unreachable_notification;
07756                         this_hostescalation->have_last_unreachable_notification=TRUE;
07757                         }
07758 #endif
07759                 if(this_hostescalation->have_notification_interval==FALSE && template_hostescalation->have_notification_interval==TRUE){
07760                         this_hostescalation->notification_interval=template_hostescalation->notification_interval;
07761                         this_hostescalation->have_notification_interval=TRUE;
07762                         }
07763                 if(this_hostescalation->have_escalation_options==FALSE && template_hostescalation->have_escalation_options==TRUE){
07764                         this_hostescalation->escalate_on_down=template_hostescalation->escalate_on_down;
07765                         this_hostescalation->escalate_on_unreachable=template_hostescalation->escalate_on_unreachable;
07766                         this_hostescalation->escalate_on_recovery=template_hostescalation->escalate_on_recovery;
07767                         this_hostescalation->have_escalation_options=TRUE;
07768                         }
07769                 }
07770 
07771         my_free(template_names);
07772 
07773         return OK;
07774         }
07775 
07776 
07777 
07778 /* resolves a hostextinfo object */
07779 int xodtemplate_resolve_hostextinfo(xodtemplate_hostextinfo *this_hostextinfo){
07780         char *temp_ptr=NULL;
07781         char *template_names=NULL;
07782         char *template_name_ptr=NULL;
07783         xodtemplate_hostextinfo *template_hostextinfo=NULL;
07784 
07785         /* return if this object has already been resolved */
07786         if(this_hostextinfo->has_been_resolved==TRUE)
07787                 return OK;
07788 
07789         /* set the resolved flag */
07790         this_hostextinfo->has_been_resolved=TRUE;
07791 
07792         /* return if we have no template */
07793         if(this_hostextinfo->template==NULL)
07794                 return OK;
07795 
07796         if((template_names=(char *)strdup(this_hostextinfo->template))==NULL)
07797                 return ERROR;
07798 
07799         /* apply all templates */
07800         template_name_ptr=template_names;
07801         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07802 
07803                 template_hostextinfo=xodtemplate_find_hostextinfo(temp_ptr);
07804                 if(template_hostextinfo==NULL){
07805                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in extended host info definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_hostextinfo->_config_file),this_hostextinfo->_start_line);
07806                         my_free(template_names);
07807                         return ERROR;
07808                         }
07809 
07810                 /* resolve the template hostextinfo... */
07811                 xodtemplate_resolve_hostextinfo(template_hostextinfo);
07812 
07813                 /* apply missing properties from template hostextinfo... */
07814                 if(this_hostextinfo->have_host_name==FALSE && template_hostextinfo->have_host_name==TRUE){
07815                         if(this_hostextinfo->host_name==NULL && template_hostextinfo->host_name!=NULL)
07816                                 this_hostextinfo->host_name=(char *)strdup(template_hostextinfo->host_name);
07817                         this_hostextinfo->have_host_name=TRUE;
07818                         }
07819                 if(this_hostextinfo->have_hostgroup_name==FALSE && template_hostextinfo->have_hostgroup_name==TRUE){
07820                         if(this_hostextinfo->hostgroup_name==NULL && template_hostextinfo->hostgroup_name!=NULL)
07821                                 this_hostextinfo->hostgroup_name=(char *)strdup(template_hostextinfo->hostgroup_name);
07822                         this_hostextinfo->have_hostgroup_name=TRUE;
07823                         }
07824                 if(this_hostextinfo->have_notes==FALSE && template_hostextinfo->have_notes==TRUE){
07825                         if(this_hostextinfo->notes==NULL && template_hostextinfo->notes!=NULL)
07826                                 this_hostextinfo->notes=(char *)strdup(template_hostextinfo->notes);
07827                         this_hostextinfo->have_notes=TRUE;
07828                         }
07829                 if(this_hostextinfo->have_notes_url==FALSE && template_hostextinfo->have_notes_url==TRUE){
07830                         if(this_hostextinfo->notes_url==NULL && template_hostextinfo->notes_url!=NULL)
07831                                 this_hostextinfo->notes_url=(char *)strdup(template_hostextinfo->notes_url);
07832                         this_hostextinfo->have_notes_url=TRUE;
07833                         }
07834                 if(this_hostextinfo->have_action_url==FALSE && template_hostextinfo->have_action_url==TRUE){
07835                         if(this_hostextinfo->action_url==NULL && template_hostextinfo->action_url!=NULL)
07836                                 this_hostextinfo->action_url=(char *)strdup(template_hostextinfo->action_url);
07837                         this_hostextinfo->have_action_url=TRUE;
07838                         }
07839                 if(this_hostextinfo->have_icon_image==FALSE && template_hostextinfo->have_icon_image==TRUE){
07840                         if(this_hostextinfo->icon_image==NULL && template_hostextinfo->icon_image!=NULL)
07841                                 this_hostextinfo->icon_image=(char *)strdup(template_hostextinfo->icon_image);
07842                         this_hostextinfo->have_icon_image=TRUE;
07843                         }
07844                 if(this_hostextinfo->have_icon_image_alt==FALSE && template_hostextinfo->have_icon_image_alt==TRUE){
07845                         if(this_hostextinfo->icon_image_alt==NULL && template_hostextinfo->icon_image_alt!=NULL)
07846                                 this_hostextinfo->icon_image_alt=(char *)strdup(template_hostextinfo->icon_image_alt);
07847                         this_hostextinfo->have_icon_image_alt=TRUE;
07848                         }
07849                 if(this_hostextinfo->have_vrml_image==FALSE && template_hostextinfo->have_vrml_image==TRUE){
07850                         if(this_hostextinfo->vrml_image==NULL && template_hostextinfo->vrml_image!=NULL)
07851                                 this_hostextinfo->vrml_image=(char *)strdup(template_hostextinfo->vrml_image);
07852                         this_hostextinfo->have_vrml_image=TRUE;
07853                         }
07854                 if(this_hostextinfo->have_statusmap_image==FALSE && template_hostextinfo->have_statusmap_image==TRUE){
07855                         if(this_hostextinfo->statusmap_image==NULL && template_hostextinfo->statusmap_image!=NULL)
07856                                 this_hostextinfo->statusmap_image=(char *)strdup(template_hostextinfo->statusmap_image);
07857                         this_hostextinfo->have_statusmap_image=TRUE;
07858                         }
07859                 if(this_hostextinfo->have_2d_coords==FALSE && template_hostextinfo->have_2d_coords==TRUE){
07860                         this_hostextinfo->x_2d=template_hostextinfo->x_2d;
07861                         this_hostextinfo->y_2d=template_hostextinfo->y_2d;
07862                         this_hostextinfo->have_2d_coords=TRUE;
07863                         }
07864                 if(this_hostextinfo->have_3d_coords==FALSE && template_hostextinfo->have_3d_coords==TRUE){
07865                         this_hostextinfo->x_3d=template_hostextinfo->x_3d;
07866                         this_hostextinfo->y_3d=template_hostextinfo->y_3d;
07867                         this_hostextinfo->z_3d=template_hostextinfo->z_3d;
07868                         this_hostextinfo->have_3d_coords=TRUE;
07869                         }
07870                 }
07871 
07872         my_free(template_names);
07873 
07874         return OK;
07875         }
07876 
07877 
07878 
07879 /* resolves a serviceextinfo object */
07880 int xodtemplate_resolve_serviceextinfo(xodtemplate_serviceextinfo *this_serviceextinfo){
07881         char *temp_ptr=NULL;
07882         char *template_names=NULL;
07883         char *template_name_ptr=NULL;
07884         xodtemplate_serviceextinfo *template_serviceextinfo=NULL;
07885 
07886         /* return if this object has already been resolved */
07887         if(this_serviceextinfo->has_been_resolved==TRUE)
07888                 return OK;
07889 
07890         /* set the resolved flag */
07891         this_serviceextinfo->has_been_resolved=TRUE;
07892 
07893         /* return if we have no template */
07894         if(this_serviceextinfo->template==NULL)
07895                 return OK;
07896 
07897         if((template_names=(char *)strdup(this_serviceextinfo->template))==NULL)
07898                 return ERROR;
07899 
07900         /* apply all templates */
07901         template_name_ptr=template_names;
07902         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07903 
07904                 template_serviceextinfo=xodtemplate_find_serviceextinfo(temp_ptr);
07905                 if(template_serviceextinfo==NULL){
07906                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in extended service info definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_serviceextinfo->_config_file),this_serviceextinfo->_start_line);
07907                         my_free(template_names);
07908                         return ERROR;
07909                         }
07910 
07911                 /* resolve the template serviceextinfo... */
07912                 xodtemplate_resolve_serviceextinfo(template_serviceextinfo);
07913 
07914                 /* apply missing properties from template serviceextinfo... */
07915                 if(this_serviceextinfo->have_host_name==FALSE && template_serviceextinfo->have_host_name==TRUE){
07916                         if(this_serviceextinfo->host_name==NULL && template_serviceextinfo->host_name!=NULL)
07917                                 this_serviceextinfo->host_name=(char *)strdup(template_serviceextinfo->host_name);
07918                         this_serviceextinfo->have_host_name=TRUE;
07919                         }
07920                 if(this_serviceextinfo->have_hostgroup_name==FALSE && template_serviceextinfo->have_hostgroup_name==TRUE){
07921                 if(this_serviceextinfo->hostgroup_name==NULL && template_serviceextinfo->hostgroup_name!=NULL)
07922                         this_serviceextinfo->hostgroup_name=(char *)strdup(template_serviceextinfo->hostgroup_name);
07923                         this_serviceextinfo->have_hostgroup_name=TRUE;
07924                         }
07925                 if(this_serviceextinfo->have_service_description==FALSE && template_serviceextinfo->have_service_description==TRUE){
07926                 if(this_serviceextinfo->service_description==NULL && template_serviceextinfo->service_description!=NULL)
07927                         this_serviceextinfo->service_description=(char *)strdup(template_serviceextinfo->service_description);
07928                         this_serviceextinfo->have_service_description=TRUE;
07929                         }
07930                 if(this_serviceextinfo->have_notes==FALSE && template_serviceextinfo->have_notes==TRUE){
07931                 if(this_serviceextinfo->notes==NULL && template_serviceextinfo->notes!=NULL)
07932                         this_serviceextinfo->notes=(char *)strdup(template_serviceextinfo->notes);
07933                         this_serviceextinfo->have_notes=TRUE;
07934                         }
07935                 if(this_serviceextinfo->have_notes_url==FALSE && template_serviceextinfo->have_notes_url==TRUE){
07936                 if(this_serviceextinfo->notes_url==NULL && template_serviceextinfo->notes_url!=NULL)
07937                         this_serviceextinfo->notes_url=(char *)strdup(template_serviceextinfo->notes_url);
07938                         this_serviceextinfo->have_notes_url=TRUE;
07939                         }
07940                 if(this_serviceextinfo->have_action_url==FALSE && template_serviceextinfo->have_action_url==TRUE){
07941                 if(this_serviceextinfo->action_url==NULL && template_serviceextinfo->action_url!=NULL)
07942                         this_serviceextinfo->action_url=(char *)strdup(template_serviceextinfo->action_url);
07943                         this_serviceextinfo->have_action_url=TRUE;
07944                         }
07945                 if(this_serviceextinfo->have_icon_image==FALSE && template_serviceextinfo->have_icon_image==TRUE){
07946                 if(this_serviceextinfo->icon_image==NULL && template_serviceextinfo->icon_image!=NULL)
07947                         this_serviceextinfo->icon_image=(char *)strdup(template_serviceextinfo->icon_image);
07948                         this_serviceextinfo->have_icon_image=TRUE;
07949                         }
07950                 if(this_serviceextinfo->have_icon_image_alt==FALSE && template_serviceextinfo->have_icon_image_alt==TRUE){
07951                 if(this_serviceextinfo->icon_image_alt==NULL && template_serviceextinfo->icon_image_alt!=NULL)
07952                         this_serviceextinfo->icon_image_alt=(char *)strdup(template_serviceextinfo->icon_image_alt);
07953                         this_serviceextinfo->have_icon_image_alt=TRUE;
07954                         }
07955                 }
07956 
07957         my_free(template_names);
07958 
07959         return OK;
07960         }
07961 
07962 
07963 /* resolves a module object */
07964 int xodtemplate_resolve_module(xodtemplate_module *this_module){
07965         char *temp_ptr=NULL;
07966         char *template_names=NULL;
07967         char *template_name_ptr=NULL;
07968         xodtemplate_module *template_module=NULL;
07969 
07970         /* return if this command has already been resolved */
07971         if(this_module->has_been_resolved==TRUE)
07972                 return OK;
07973 
07974         /* set the resolved flag */
07975         this_module->has_been_resolved=TRUE;
07976 
07977         /* return if we have no template */
07978         if(this_module->template==NULL)
07979                 return OK;
07980 
07981         if((template_names=(char *)strdup(this_module->template))==NULL)
07982                 return ERROR;
07983 
07984         /* apply all templates */
07985         template_name_ptr=template_names;
07986         for(temp_ptr=my_strsep(&template_name_ptr,",");temp_ptr!=NULL;temp_ptr=my_strsep(&template_name_ptr,",")){
07987 
07988                 template_module=xodtemplate_find_module(temp_ptr);
07989                 if(template_module==NULL){
07990                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Template '%s' specified in module definition could not be not found (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_module->_config_file),this_module->_start_line);
07991                         my_free(template_names);
07992                         return ERROR;
07993                         }
07994 
07995                 /* resolve the template module... */
07996                 xodtemplate_resolve_module(template_module);
07997 
07998                 /* apply missing properties from template module... */
07999                 if(this_module->module_name==NULL && template_module->module_name!=NULL)
08000                         this_module->module_name=(char *)strdup(template_module->module_name);
08001                 if(this_module->module_type==NULL && template_module->module_type!=NULL)
08002                         this_module->module_type=(char *)strdup(template_module->module_type);
08003                 if(this_module->path==NULL && template_module->path!=NULL)
08004                         this_module->path=(char *)strdup(template_module->path);
08005                 if(this_module->args==NULL && template_module->args!=NULL)
08006                         this_module->args=(char *)strdup(template_module->args);
08007                 }
08008 
08009         my_free(template_names);
08010 
08011         return OK;
08012         }
08013 
08014 
08015 #endif
08016 
08017 
08018 
08019 /******************************************************************/
08020 /*************** OBJECT RECOMBOBULATION FUNCTIONS *****************/
08021 /******************************************************************/
08022 
08023 #ifdef NSCORE
08024 
08025 
08026 /* recombobulates contactgroup definitions */
08027 int xodtemplate_recombobulate_contactgroups(void){
08028         xodtemplate_contact *temp_contact=NULL;
08029         xodtemplate_contactgroup *temp_contactgroup=NULL;
08030         xodtemplate_memberlist *temp_memberlist=NULL;
08031         xodtemplate_memberlist *this_memberlist=NULL;
08032         char *contactgroup_names=NULL;
08033         char *temp_ptr=NULL;
08034         char *new_members=NULL;
08035 
08036         /* This should happen before we expand contactgroup members, to avoid duplicate contact memberships 01/07/2006 EG */
08037         /* process all contacts that have contactgroup directives */
08038         for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
08039 
08040                 /* skip contacts without contactgroup directives or contact names */
08041                 if(temp_contact->contact_groups==NULL || temp_contact->contact_name==NULL)
08042                         continue;
08043 
08044                 /* preprocess the contactgroup list, to change "grp1,grp2,grp3,!grp2" into "grp1,grp3" */
08045                 if((contactgroup_names=xodtemplate_process_contactgroup_names(temp_contact->contact_groups,temp_contact->_config_file,temp_contact->_start_line))==NULL)
08046                         return ERROR;
08047 
08048                 /* process the list of contactgroups */
08049                 for(temp_ptr=strtok(contactgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
08050 
08051                         /* strip trailing spaces */
08052                         strip(temp_ptr);
08053                         
08054                         /* find the contactgroup */
08055                         temp_contactgroup=xodtemplate_find_real_contactgroup(temp_ptr);
08056                         if(temp_contactgroup==NULL){
08057                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find contactgroup '%s' specified in contact '%s' definition (config file '%s', starting on line %d)\n",temp_ptr,temp_contact->contact_name,xodtemplate_config_file_name(temp_contact->_config_file),temp_contact->_start_line);
08058                                 my_free(contactgroup_names);
08059                                 return ERROR;
08060                                 }
08061 
08062                         /* add this contact to the contactgroup members directive */
08063                         if(temp_contactgroup->members==NULL)
08064                                 temp_contactgroup->members=(char *)strdup(temp_contact->contact_name);
08065                         else{
08066                                 new_members=(char *)realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(temp_contact->contact_name)+2);
08067                                 if(new_members!=NULL){
08068                                         temp_contactgroup->members=new_members;
08069                                         strcat(temp_contactgroup->members,",");
08070                                         strcat(temp_contactgroup->members,temp_contact->contact_name);
08071                                         }
08072                                 }
08073                         }
08074 
08075                 /* free memory */
08076                 my_free(contactgroup_names);
08077                 }
08078 
08079 
08080         /* expand subgroup membership recursively */
08081         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup;temp_contactgroup=temp_contactgroup->next)
08082                 xodtemplate_recombobulate_contactgroup_subgroups(temp_contactgroup,NULL);
08083 
08084 
08085         /* expand members of all contactgroups - this could be done in xodtemplate_register_contactgroup(), but we can save the CGIs some work if we do it here */
08086         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup;temp_contactgroup=temp_contactgroup->next){
08087 
08088                 if(temp_contactgroup->members==NULL)
08089                         continue;
08090 
08091                 /* get list of contacts in the contactgroup */
08092                 temp_memberlist=xodtemplate_expand_contactgroups_and_contacts(temp_contactgroup->contactgroup_members,temp_contactgroup->members,temp_contactgroup->_config_file,temp_contactgroup->_start_line);
08093 
08094                 /* add all members to the contact group */
08095                 if(temp_memberlist==NULL){
08096                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand member contacts specified in contactgroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_contactgroup->_config_file),temp_contactgroup->_start_line);
08097                         return ERROR;
08098                         }
08099                 my_free(temp_contactgroup->members);
08100                 for(this_memberlist=temp_memberlist;this_memberlist;this_memberlist=this_memberlist->next){
08101 
08102                         /* add this contact to the contactgroup members directive */
08103                         if(temp_contactgroup->members==NULL)
08104                                 temp_contactgroup->members=(char *)strdup(this_memberlist->name1);
08105                         else{
08106                                 new_members=(char *)realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(this_memberlist->name1)+2);
08107                                 if(new_members!=NULL){
08108                                         temp_contactgroup->members=new_members;
08109                                         strcat(temp_contactgroup->members,",");
08110                                         strcat(temp_contactgroup->members,this_memberlist->name1);
08111                                         }
08112                                 }
08113                         }
08114                 xodtemplate_free_memberlist(&temp_memberlist);
08115                 }
08116 
08117         return OK;
08118         }
08119 
08120 
08121 
08122 int xodtemplate_recombobulate_contactgroup_subgroups(xodtemplate_contactgroup *temp_contactgroup, char **members){
08123         xodtemplate_contactgroup *sub_group=NULL;
08124         char *orig_cgmembers=NULL;
08125         char *cgmembers=NULL;
08126         char *newmembers=NULL;
08127         char *buf=NULL;
08128         char *ptr=NULL;
08129 
08130         if(temp_contactgroup==NULL)
08131                 return ERROR;
08132 
08133         /* resolve subgroup memberships first */
08134         if(temp_contactgroup->contactgroup_members!=NULL){
08135 
08136                 /* save members, null pointer so we don't recurse into infinite hell */
08137                 orig_cgmembers=temp_contactgroup->contactgroup_members;
08138                 temp_contactgroup->contactgroup_members=NULL;
08139 
08140                 /* make new working copy of members */
08141                 cgmembers=(char *)strdup(orig_cgmembers);
08142 
08143                 ptr=cgmembers;
08144                 while((buf=ptr)!=NULL){
08145 
08146                         /* get next member for next run*/
08147                         ptr=strchr(ptr,',');
08148                         if(ptr){
08149                                 ptr[0]='\x0';
08150                                 ptr++;
08151                                 }
08152 
08153                         strip(buf);
08154 
08155                         /* find subgroup and recurse */
08156                         if((sub_group=xodtemplate_find_real_contactgroup(buf))==NULL){
08157                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find member group '%s' specified in contactgroup (config file '%s', starting on line %d)\n",buf,xodtemplate_config_file_name(temp_contactgroup->_config_file),temp_contactgroup->_start_line);
08158                                 return ERROR;
08159                                 }
08160                         xodtemplate_recombobulate_contactgroup_subgroups(sub_group,&newmembers);
08161 
08162                         /* add new (sub) members */
08163                         if(newmembers!=NULL){
08164                                 if(temp_contactgroup->members==NULL)
08165                                         temp_contactgroup->members=(char *)strdup(newmembers);
08166                                 else if((temp_contactgroup->members=realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(newmembers)+2))){
08167                                         strcat(temp_contactgroup->members,",");
08168                                         strcat(temp_contactgroup->members,newmembers);
08169                                         }
08170                                 }
08171                         }
08172 
08173                 /* free memory */
08174                 my_free(cgmembers);
08175 
08176                 /* restore group members */
08177                 temp_contactgroup->contactgroup_members=orig_cgmembers;
08178                 }
08179 
08180         /* return contact members */
08181         if(members!=NULL)
08182                 *members=temp_contactgroup->members;
08183 
08184         return OK;
08185         }
08186 
08187 
08188 /* NOTE: this was originally implemented in the late alpha cycle of
08189  * Nagios 3.0 development, but was removed in 3.0b2, as flattening
08190  * contactgroups into a list of contacts makes it impossible for
08191  * IDOUtils to create a reverse mapping */
08192 int xodtemplate_recombobulate_object_contacts(void){
08193         return OK;
08194 }
08195 
08196 
08197 /* recombobulates hostgroup definitions */
08198 int xodtemplate_recombobulate_hostgroups(void){
08199         xodtemplate_host *temp_host=NULL;
08200         xodtemplate_hostgroup *temp_hostgroup=NULL;
08201         xodtemplate_memberlist *temp_memberlist=NULL;
08202         xodtemplate_memberlist *this_memberlist=NULL;
08203         char *hostgroup_names=NULL;
08204         char *temp_ptr=NULL;
08205         char *new_members=NULL;
08206 
08207 #ifdef DEBUG
08208         printf("** PRE-EXPANSION 1\n");
08209         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup;temp_hostgroup=temp_hostgroup->next){
08210                 printf("HOSTGROUP [%s]\n",temp_hostgroup->hostgroup_name);
08211                 printf("H MEMBERS: %s\n",temp_hostgroup->members);
08212                 printf("G MEMBERS: %s\n",temp_hostgroup->hostgroup_members);
08213                 printf("\n");
08214                 }
08215 #endif
08216 
08217         /* This should happen before we expand hostgroup members, to avoid duplicate host memberships 01/07/2006 EG */
08218         /* process all hosts that have hostgroup directives */
08219         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
08220 
08221                 /* skip hosts without hostgroup directives or host names */
08222                 if(temp_host->host_groups==NULL || temp_host->host_name==NULL)
08223                         continue;
08224 
08225                 /* skip hosts that shouldn't be registered */
08226                 if(temp_host->register_object==FALSE)
08227                         continue;
08228 
08229                 /* preprocess the hostgroup list, to change "grp1,grp2,grp3,!grp2" into "grp1,grp3" */
08230                 /* 10/18/07 EG an empty return value means an error occured */
08231                 if((hostgroup_names=xodtemplate_process_hostgroup_names(temp_host->host_groups,temp_host->_config_file,temp_host->_start_line))==NULL)
08232                         return ERROR;
08233 
08234                 /* process the list of hostgroups */
08235                 for(temp_ptr=strtok(hostgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
08236 
08237                         /* strip trailing spaces */
08238                         strip(temp_ptr);
08239                         
08240                         /* find the hostgroup */
08241                         temp_hostgroup=xodtemplate_find_real_hostgroup(temp_ptr);
08242                         if(temp_hostgroup==NULL){
08243                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find hostgroup '%s' specified in host '%s' definition (config file '%s', starting on line %d)\n",temp_ptr,temp_host->host_name,xodtemplate_config_file_name(temp_host->_config_file),temp_host->_start_line);
08244                                 my_free(hostgroup_names);
08245                                 return ERROR;
08246                                 }
08247 
08248                         /* add this list to the hostgroup members directive */
08249                         if(temp_hostgroup->members==NULL)
08250                                 temp_hostgroup->members=(char *)strdup(temp_host->host_name);
08251                         else{
08252                                 new_members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(temp_host->host_name)+2);
08253                                 if(new_members!=NULL){
08254                                         temp_hostgroup->members=new_members;
08255                                         strcat(temp_hostgroup->members,",");
08256                                         strcat(temp_hostgroup->members,temp_host->host_name);
08257                                         }
08258                                 }
08259                         }
08260 
08261                 /* free memory */
08262                 my_free(hostgroup_names);
08263                 }
08264 
08265 #ifdef DEBUG
08266         printf("** POST-EXPANSION 1\n");
08267         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup;temp_hostgroup=temp_hostgroup->next){
08268                 printf("HOSTGROUP [%s]\n",temp_hostgroup->hostgroup_name);
08269                 printf("H MEMBERS: %s\n",temp_hostgroup->members);
08270                 printf("G MEMBERS: %s\n",temp_hostgroup->hostgroup_members);
08271                 printf("\n");
08272                 }
08273 #endif
08274 
08275         /* expand subgroup membership recursively */
08276         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup;temp_hostgroup=temp_hostgroup->next)
08277                 xodtemplate_recombobulate_hostgroup_subgroups(temp_hostgroup,NULL);
08278 
08279         /* expand members of all hostgroups - this could be done in xodtemplate_register_hostgroup(), but we can save the CGIs some work if we do it here */
08280         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup;temp_hostgroup=temp_hostgroup->next){
08281 
08282                 if(temp_hostgroup->members==NULL && temp_hostgroup->hostgroup_members==NULL)
08283                         continue;
08284 
08285                 /* skip hostgroups that shouldn't be registered */
08286                 if(temp_hostgroup->register_object==FALSE)
08287                         continue;
08288 
08289                 /* get list of hosts in the hostgroup */
08290                 temp_memberlist=xodtemplate_expand_hostgroups_and_hosts(NULL,temp_hostgroup->members,temp_hostgroup->_config_file,temp_hostgroup->_start_line);
08291 
08292                 /* add all members to the host group */
08293                 if(temp_memberlist==NULL){
08294                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand members specified in hostgroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostgroup->_config_file),temp_hostgroup->_start_line);
08295                         return ERROR;
08296                         }
08297                 my_free(temp_hostgroup->members);
08298                 for(this_memberlist=temp_memberlist;this_memberlist;this_memberlist=this_memberlist->next){
08299 
08300                         /* add this host to the hostgroup members directive */
08301                         if(temp_hostgroup->members==NULL)
08302                                 temp_hostgroup->members=(char *)strdup(this_memberlist->name1);
08303                         else{
08304                                 new_members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(this_memberlist->name1)+2);
08305                                 if(new_members!=NULL){
08306                                         temp_hostgroup->members=new_members;
08307                                         strcat(temp_hostgroup->members,",");
08308                                         strcat(temp_hostgroup->members,this_memberlist->name1);
08309                                         }
08310                                 }
08311                         }
08312                 xodtemplate_free_memberlist(&temp_memberlist);
08313                 }
08314 
08315 #ifdef DEBUG
08316         printf("** POST-EXPANSION 2\n");
08317         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup;temp_hostgroup=temp_hostgroup->next){
08318                 printf("HOSTGROUP [%s]\n",temp_hostgroup->hostgroup_name);
08319                 printf("H MEMBERS: %s\n",temp_hostgroup->members);
08320                 printf("G MEMBERS: %s\n",temp_hostgroup->hostgroup_members);
08321                 printf("\n");
08322                 }
08323 #endif
08324 
08325         return OK;
08326         }
08327 
08328 
08329 
08330 
08331 int xodtemplate_recombobulate_hostgroup_subgroups(xodtemplate_hostgroup *temp_hostgroup, char **members){
08332         xodtemplate_hostgroup *sub_group=NULL;
08333         char *orig_hgmembers=NULL;
08334         char *hgmembers=NULL;
08335         char *newmembers=NULL;
08336         char *buf=NULL;
08337         char *ptr=NULL;
08338 
08339         if(temp_hostgroup==NULL)
08340                 return ERROR;
08341 
08342         /* resolve subgroup memberships first */
08343         if(temp_hostgroup->hostgroup_members!=NULL){
08344 
08345                 /* save members, null pointer so we don't recurse into infinite hell */
08346                 orig_hgmembers=temp_hostgroup->hostgroup_members;
08347                 temp_hostgroup->hostgroup_members=NULL;
08348 
08349                 /* make new working copy of members */
08350                 hgmembers=(char *)strdup(orig_hgmembers);
08351 
08352                 ptr=hgmembers;
08353                 while((buf=ptr)!=NULL){
08354 
08355                         /* get next member for next run*/
08356                         ptr=strchr(ptr,',');
08357                         if(ptr){
08358                                 ptr[0]='\x0';
08359                                 ptr++;
08360                                 }
08361 
08362                         strip(buf);
08363 
08364                         /* find subgroup and recurse */
08365                         if((sub_group=xodtemplate_find_real_hostgroup(buf))==NULL){
08366                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find member group '%s' specified in hostgroup (config file '%s', starting on line %d)\n",buf,xodtemplate_config_file_name(temp_hostgroup->_config_file),temp_hostgroup->_start_line);
08367                                 return ERROR;
08368                                 }
08369                         xodtemplate_recombobulate_hostgroup_subgroups(sub_group,&newmembers);
08370 
08371                         /* add new (sub) members */
08372                         if(newmembers!=NULL){
08373                                 if(temp_hostgroup->members==NULL)
08374                                         temp_hostgroup->members=(char *)strdup(newmembers);
08375                                 else if((temp_hostgroup->members=realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(newmembers)+2))){
08376                                         strcat(temp_hostgroup->members,",");
08377                                         strcat(temp_hostgroup->members,newmembers);
08378                                         }
08379                                 }
08380                         }
08381 
08382                 /* free memory */
08383                 my_free(hgmembers);
08384 
08385                 /* restore group members */
08386                 temp_hostgroup->hostgroup_members=orig_hgmembers;
08387                 }
08388 
08389         /* return host members */
08390         if(members!=NULL)
08391                 *members=temp_hostgroup->members;
08392 
08393         return OK;
08394         }
08395 
08396 
08397 
08398 /* recombobulates servicegroup definitions */
08399 /***** THIS NEEDS TO BE CALLED AFTER OBJECTS (SERVICES) ARE RESOLVED AND DUPLICATED *****/
08400 int xodtemplate_recombobulate_servicegroups(void){
08401         xodtemplate_service *temp_service=NULL;
08402         xodtemplate_servicegroup *temp_servicegroup=NULL;
08403         xodtemplate_memberlist *temp_memberlist=NULL;
08404         xodtemplate_memberlist *this_memberlist=NULL;
08405         char *servicegroup_names=NULL;
08406         char *member_names=NULL;
08407         char *host_name=NULL;
08408         char *service_description=NULL;
08409         char *temp_ptr=NULL;
08410         char *temp_ptr2=NULL;
08411         char *new_members=NULL;
08412 
08413         /* This should happen before we expand servicegroup members, to avoid duplicate service memberships 01/07/2006 EG */
08414         /* process all services that have servicegroup directives */
08415         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
08416 
08417                 /* skip services without servicegroup directives or service names */
08418                 if(temp_service->service_groups==NULL || temp_service->host_name==NULL || temp_service->service_description==NULL)
08419                         continue;
08420 
08421                 /* skip services that shouldn't be registered */
08422                 if(temp_service->register_object==FALSE)
08423                         continue;
08424 
08425                 /* preprocess the servicegroup list, to change "grp1,grp2,grp3,!grp2" into "grp1,grp3" */
08426                 /* 10/19/07 EG an empry return value means an error occured */
08427                 if((servicegroup_names=xodtemplate_process_servicegroup_names(temp_service->service_groups,temp_service->_config_file,temp_service->_start_line))==NULL)
08428                         return ERROR;
08429 
08430                 /* process the list of servicegroups */
08431                 for(temp_ptr=strtok(servicegroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
08432 
08433                         /* strip trailing spaces */
08434                         strip(temp_ptr);
08435                         
08436                         /* find the servicegroup */
08437                         temp_servicegroup=xodtemplate_find_real_servicegroup(temp_ptr);
08438                         if(temp_servicegroup==NULL){
08439                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find servicegroup '%s' specified in service '%s' on host '%s' definition (config file '%s', starting on line %d)\n",temp_ptr,temp_service->service_description,temp_service->host_name,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
08440                                 my_free(servicegroup_names);
08441                                 return ERROR;
08442                                 }
08443 
08444                         /* add this list to the servicegroup members directive */
08445                         if(temp_servicegroup->members==NULL){
08446                                 temp_servicegroup->members=(char *)malloc(strlen(temp_service->host_name)+strlen(temp_service->service_description)+2);
08447                                 if(temp_servicegroup->members!=NULL){
08448                                         strcpy(temp_servicegroup->members,temp_service->host_name);
08449                                         strcat(temp_servicegroup->members,",");
08450                                         strcat(temp_servicegroup->members,temp_service->service_description);
08451                                         }
08452                                 }
08453                         else{
08454                                 new_members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(temp_service->host_name)+strlen(temp_service->service_description)+3);
08455                                 if(new_members!=NULL){
08456                                         temp_servicegroup->members=new_members;
08457                                         strcat(temp_servicegroup->members,",");
08458                                         strcat(temp_servicegroup->members,temp_service->host_name);
08459                                         strcat(temp_servicegroup->members,",");
08460                                         strcat(temp_servicegroup->members,temp_service->service_description);
08461                                         }
08462                                 }
08463                         }
08464 
08465                 /* free servicegroup names */
08466                 my_free(servicegroup_names);
08467                 }
08468 
08469 
08470         /* expand subgroup membership recursively */
08471         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup;temp_servicegroup=temp_servicegroup->next)
08472                 xodtemplate_recombobulate_servicegroup_subgroups(temp_servicegroup,NULL);
08473 
08474         /* expand members of all servicegroups - this could be done in xodtemplate_register_servicegroup(), but we can save the CGIs some work if we do it here */
08475         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup;temp_servicegroup=temp_servicegroup->next){
08476 
08477                 if(temp_servicegroup->members==NULL)
08478                         continue;
08479 
08480                 /* skip servicegroups that shouldn't be registered */
08481                 if(temp_servicegroup->register_object==FALSE)
08482                         continue;
08483 
08484                 member_names=temp_servicegroup->members;
08485                 temp_servicegroup->members=NULL;
08486 
08487                 for(temp_ptr=member_names;temp_ptr;temp_ptr=strchr(temp_ptr+1,',')){
08488 
08489                         /* this is the host name */
08490                         if(host_name==NULL)
08491                                 host_name=(char *)strdup((temp_ptr[0]==',')?temp_ptr+1:temp_ptr);
08492 
08493                         /* this is the service description */
08494                         else{
08495                                 service_description=(char *)strdup(temp_ptr+1);
08496 
08497                                 /* strsep and strtok cannot be used, as they're used in expand_servicegroups...() */
08498                                 temp_ptr2=strchr(host_name,',');
08499                                 if(temp_ptr2)
08500                                         temp_ptr2[0]='\x0';
08501                                 temp_ptr2=strchr(service_description,',');
08502                                 if(temp_ptr2)
08503                                         temp_ptr2[0]='\x0';
08504 
08505                                 /* strip trailing spaces */
08506                                 strip(host_name);
08507                                 strip(service_description);
08508 
08509                                 /* get list of services in the servicegroup */
08510                                 temp_memberlist=xodtemplate_expand_servicegroups_and_services(NULL,host_name,service_description,temp_servicegroup->_config_file,temp_servicegroup->_start_line);
08511 
08512                                 /* add all members to the service group */
08513                                 if(temp_memberlist==NULL){
08514                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not expand member services specified in servicegroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
08515                                         my_free(member_names);
08516                                         my_free(host_name);
08517                                         my_free(service_description);
08518                                         return ERROR;
08519                                         }
08520 
08521                                 for(this_memberlist=temp_memberlist;this_memberlist;this_memberlist=this_memberlist->next){
08522 
08523                                         /* add this service to the servicegroup members directive */
08524                                         if(temp_servicegroup->members==NULL){
08525                                                 temp_servicegroup->members=(char *)malloc(strlen(this_memberlist->name1)+strlen(this_memberlist->name2)+2);
08526                                                 if(temp_servicegroup!=NULL){
08527                                                         strcpy(temp_servicegroup->members,this_memberlist->name1);
08528                                                         strcat(temp_servicegroup->members,",");
08529                                                         strcat(temp_servicegroup->members,this_memberlist->name2);
08530                                                         }
08531                                                 }
08532                                         else{
08533                                                 new_members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(this_memberlist->name1)+strlen(this_memberlist->name2)+3);
08534                                                 if(new_members!=NULL){
08535                                                         temp_servicegroup->members=new_members;
08536                                                         strcat(temp_servicegroup->members,",");
08537                                                         strcat(temp_servicegroup->members,this_memberlist->name1);
08538                                                         strcat(temp_servicegroup->members,",");
08539                                                         strcat(temp_servicegroup->members,this_memberlist->name2);
08540                                                         }
08541                                                 }
08542                                         }
08543                                 xodtemplate_free_memberlist(&temp_memberlist);
08544 
08545                                 my_free(host_name);
08546                                 my_free(service_description);
08547                                 }
08548                         }
08549 
08550                 my_free(member_names);
08551 
08552                 /* error if there were an odd number of items specified (unmatched host/service pair) */
08553                 if(host_name!=NULL){
08554                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup members must be specified in <host_name>,<service_description> pairs (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
08555                         my_free(host_name);
08556                         return ERROR;
08557                         }
08558                 }
08559 
08560         return OK;
08561         }
08562 
08563 
08564 
08565 
08566 int xodtemplate_recombobulate_servicegroup_subgroups(xodtemplate_servicegroup *temp_servicegroup, char **members){
08567         xodtemplate_servicegroup *sub_group=NULL;
08568         char *orig_sgmembers=NULL;
08569         char *sgmembers=NULL;
08570         char *newmembers=NULL;
08571         char *buf=NULL;
08572         char *ptr=NULL;
08573 
08574         if(temp_servicegroup==NULL)
08575                 return ERROR;
08576 
08577         /* resolve subgroup memberships first */
08578         if(temp_servicegroup->servicegroup_members!=NULL){
08579 
08580                 /* save members, null pointer so we don't recurse into infinite hell */
08581                 orig_sgmembers=temp_servicegroup->servicegroup_members;
08582                 temp_servicegroup->servicegroup_members=NULL;
08583 
08584                 /* make new working copy of members */
08585                 sgmembers=(char *)strdup(orig_sgmembers);
08586 
08587                 ptr=sgmembers;
08588                 while((buf=ptr)!=NULL){
08589 
08590                         /* get next member for next run*/
08591                         ptr=strchr(ptr,',');
08592                         if(ptr){
08593                                 ptr[0]='\x0';
08594                                 ptr++;
08595                                 }
08596 
08597                         strip(buf);
08598 
08599                         /* find subgroup and recurse */
08600                         if((sub_group=xodtemplate_find_real_servicegroup(buf))==NULL){
08601                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find member group '%s' specified in servicegroup (config file '%s', starting on line %d)\n",buf,xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
08602                                 return ERROR;
08603                                 }
08604                         xodtemplate_recombobulate_servicegroup_subgroups(sub_group,&newmembers);
08605 
08606                         /* add new (sub) members */
08607                         if(newmembers!=NULL){
08608                                 if(temp_servicegroup->members==NULL)
08609                                         temp_servicegroup->members=(char *)strdup(newmembers);
08610                                 else if((temp_servicegroup->members=realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(newmembers)+2))){
08611                                         strcat(temp_servicegroup->members,",");
08612                                         strcat(temp_servicegroup->members,newmembers);
08613                                         }
08614                                 }
08615                         }
08616 
08617                 /* free memory */
08618                 my_free(sgmembers);
08619 
08620                 /* restore group members */
08621                 temp_servicegroup->servicegroup_members=orig_sgmembers;
08622                 }
08623 
08624         /* return service members */
08625         if(members!=NULL)
08626                 *members=temp_servicegroup->members;
08627 
08628         return OK;
08629         }
08630 
08631 #endif
08632 
08633 
08634 
08635 /******************************************************************/
08636 /******************* OBJECT SEARCH FUNCTIONS **********************/
08637 /******************************************************************/
08638 
08639 #ifdef NSCORE
08640 
08641 /* finds a specific timeperiod object */
08642 xodtemplate_timeperiod *xodtemplate_find_timeperiod(char *name){
08643         xodtemplate_timeperiod temp_timeperiod;
08644 
08645         if(name==NULL)
08646                 return NULL;
08647 
08648         temp_timeperiod.name=name;
08649 
08650         return skiplist_find_first(xobject_template_skiplists[X_TIMEPERIOD_SKIPLIST],&temp_timeperiod,NULL);
08651         }
08652 
08653 
08654 /* finds a specific command object */
08655 xodtemplate_command *xodtemplate_find_command(char *name){
08656         xodtemplate_command temp_command;
08657 
08658         if(name==NULL)
08659                 return NULL;
08660 
08661         temp_command.name=name;
08662 
08663         return skiplist_find_first(xobject_template_skiplists[X_COMMAND_SKIPLIST],&temp_command,NULL);
08664         }
08665 
08666 
08667 /* finds a specific contactgroup object */
08668 xodtemplate_contactgroup *xodtemplate_find_contactgroup(char *name){
08669         xodtemplate_contactgroup temp_contactgroup;
08670 
08671         if(name==NULL)
08672                 return NULL;
08673 
08674         temp_contactgroup.name=name;
08675 
08676         return skiplist_find_first(xobject_template_skiplists[X_CONTACTGROUP_SKIPLIST],&temp_contactgroup,NULL);
08677         }
08678 
08679 
08680 /* finds a specific contactgroup object by its REAL name, not its TEMPLATE name */
08681 xodtemplate_contactgroup *xodtemplate_find_real_contactgroup(char *name){
08682         xodtemplate_contactgroup temp_contactgroup;
08683 
08684         if(name==NULL)
08685                 return NULL;
08686 
08687         temp_contactgroup.contactgroup_name=name;
08688 
08689         return skiplist_find_first(xobject_skiplists[X_CONTACTGROUP_SKIPLIST],&temp_contactgroup,NULL);
08690         }
08691 
08692 
08693 /* finds a specific hostgroup object */
08694 xodtemplate_hostgroup *xodtemplate_find_hostgroup(char *name){
08695         xodtemplate_hostgroup temp_hostgroup;
08696 
08697         if(name==NULL)
08698                 return NULL;
08699 
08700         temp_hostgroup.name=name;
08701 
08702         return skiplist_find_first(xobject_template_skiplists[X_HOSTGROUP_SKIPLIST],&temp_hostgroup,NULL);
08703         }
08704 
08705 
08706 /* finds a specific hostgroup object by its REAL name, not its TEMPLATE name */
08707 xodtemplate_hostgroup *xodtemplate_find_real_hostgroup(char *name){
08708         xodtemplate_hostgroup temp_hostgroup;
08709 
08710         if(name==NULL)
08711                 return NULL;
08712 
08713         temp_hostgroup.hostgroup_name=name;
08714 
08715         return skiplist_find_first(xobject_skiplists[X_HOSTGROUP_SKIPLIST],&temp_hostgroup,NULL);
08716         }
08717 
08718 
08719 /* finds a specific servicegroup object */
08720 xodtemplate_servicegroup *xodtemplate_find_servicegroup(char *name){
08721         xodtemplate_servicegroup temp_servicegroup;
08722 
08723         if(name==NULL)
08724                 return NULL;
08725 
08726         temp_servicegroup.name=name;
08727 
08728         return skiplist_find_first(xobject_template_skiplists[X_SERVICEGROUP_SKIPLIST],&temp_servicegroup,NULL);
08729         }
08730 
08731 
08732 /* finds a specific servicegroup object by its REAL name, not its TEMPLATE name */
08733 xodtemplate_servicegroup *xodtemplate_find_real_servicegroup(char *name){
08734         xodtemplate_servicegroup temp_servicegroup;
08735 
08736         if(name==NULL)
08737                 return NULL;
08738 
08739         temp_servicegroup.servicegroup_name=name;
08740 
08741         return skiplist_find_first(xobject_skiplists[X_SERVICEGROUP_SKIPLIST],&temp_servicegroup,NULL);
08742        }
08743 
08744 
08745 /* finds a specific servicedependency object */
08746 xodtemplate_servicedependency *xodtemplate_find_servicedependency(char *name){
08747         xodtemplate_servicedependency temp_servicedependency;
08748 
08749         if(name==NULL)
08750                 return NULL;
08751 
08752         temp_servicedependency.name=name;
08753 
08754         return skiplist_find_first(xobject_template_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],&temp_servicedependency,NULL);
08755         }
08756 
08757 
08758 /* finds a specific serviceescalation object */
08759 xodtemplate_serviceescalation *xodtemplate_find_serviceescalation(char *name){
08760         xodtemplate_serviceescalation temp_serviceescalation;
08761 
08762         if(name==NULL)
08763                 return NULL;
08764 
08765         temp_serviceescalation.name=name;
08766 
08767         return skiplist_find_first(xobject_template_skiplists[X_SERVICEESCALATION_SKIPLIST],&temp_serviceescalation,NULL);
08768         }
08769 
08770 
08771 /* finds a specific contact object */
08772 xodtemplate_contact *xodtemplate_find_contact(char *name){
08773         xodtemplate_contact temp_contact;
08774 
08775         if(name==NULL)
08776                 return NULL;
08777 
08778         temp_contact.name=name;
08779 
08780         return skiplist_find_first(xobject_template_skiplists[X_CONTACT_SKIPLIST],&temp_contact,NULL);
08781         }
08782 
08783 
08784 /* finds a specific contact object by its REAL name, not its TEMPLATE name */
08785 xodtemplate_contact *xodtemplate_find_real_contact(char *name){
08786         xodtemplate_contact temp_contact;
08787 
08788         if(name==NULL)
08789                 return NULL;
08790 
08791         temp_contact.contact_name=name;
08792 
08793         return skiplist_find_first(xobject_skiplists[X_CONTACT_SKIPLIST],&temp_contact,NULL);
08794         }
08795 
08796 
08797 /* finds a specific host object */
08798 xodtemplate_host *xodtemplate_find_host(char *name){
08799         xodtemplate_host temp_host;
08800 
08801         if(name==NULL)
08802                 return NULL;
08803 
08804         temp_host.name=name;
08805 
08806         return skiplist_find_first(xobject_template_skiplists[X_HOST_SKIPLIST],&temp_host,NULL);
08807         }
08808 
08809 
08810 /* finds a specific host object by its REAL name, not its TEMPLATE name */
08811 xodtemplate_host *xodtemplate_find_real_host(char *name){
08812         xodtemplate_host temp_host;
08813 
08814         if(name==NULL)
08815                 return NULL;
08816 
08817         temp_host.host_name=name;
08818 
08819         return skiplist_find_first(xobject_skiplists[X_HOST_SKIPLIST],&temp_host,NULL);
08820         }
08821 
08822 
08823 /* finds a specific hostdependency object */
08824 xodtemplate_hostdependency *xodtemplate_find_hostdependency(char *name){
08825         xodtemplate_hostdependency temp_hostdependency;
08826 
08827         if(name==NULL)
08828                 return NULL;
08829 
08830         temp_hostdependency.name=name;
08831 
08832         return skiplist_find_first(xobject_template_skiplists[X_HOSTDEPENDENCY_SKIPLIST],&temp_hostdependency,NULL);
08833         }
08834 
08835 
08836 /* finds a specific hostescalation object */
08837 xodtemplate_hostescalation *xodtemplate_find_hostescalation(char *name){
08838         xodtemplate_hostescalation temp_hostescalation;
08839 
08840         if(name==NULL)
08841                 return NULL;
08842 
08843         temp_hostescalation.name=name;
08844 
08845         return skiplist_find_first(xobject_template_skiplists[X_HOSTESCALATION_SKIPLIST],&temp_hostescalation,NULL);
08846         }
08847 
08848 
08849 /* finds a specific hostextinfo object */
08850 xodtemplate_hostextinfo *xodtemplate_find_hostextinfo(char *name){
08851         xodtemplate_hostextinfo temp_hostextinfo;
08852 
08853         if(name==NULL)
08854                 return NULL;
08855 
08856         temp_hostextinfo.name=name;
08857 
08858         return skiplist_find_first(xobject_template_skiplists[X_HOSTEXTINFO_SKIPLIST],&temp_hostextinfo,NULL);
08859         }
08860 
08861 
08862 /* finds a specific serviceextinfo object */
08863 xodtemplate_serviceextinfo *xodtemplate_find_serviceextinfo(char *name){
08864         xodtemplate_serviceextinfo temp_serviceextinfo;
08865 
08866         if(name==NULL)
08867                 return NULL;
08868 
08869         temp_serviceextinfo.name=name;
08870 
08871         return skiplist_find_first(xobject_template_skiplists[X_SERVICEEXTINFO_SKIPLIST],&temp_serviceextinfo,NULL);
08872         }
08873 
08874 
08875 /* finds a specific service object */
08876 xodtemplate_service *xodtemplate_find_service(char *name){
08877         xodtemplate_service temp_service;
08878 
08879         if(name==NULL)
08880                 return NULL;
08881 
08882         temp_service.name=name;
08883 
08884         return skiplist_find_first(xobject_template_skiplists[X_SERVICE_SKIPLIST],&temp_service,NULL);
08885         }
08886 
08887 
08888 /* finds a specific module object */
08889 xodtemplate_module *xodtemplate_find_module(char *name){
08890         xodtemplate_module temp_module;
08891 
08892         if(name==NULL)
08893                 return NULL;
08894 
08895         temp_module.name=name;
08896 
08897         return skiplist_find_first(xobject_template_skiplists[X_MODULE_SKIPLIST],&temp_module,NULL);
08898         }
08899 
08900 
08901 /* finds a specific service object by its REAL name, not its TEMPLATE name */
08902 xodtemplate_service *xodtemplate_find_real_service(char *host_name, char *service_description){
08903         xodtemplate_service temp_service;
08904 
08905         if(host_name==NULL || service_description==NULL)
08906                 return NULL;
08907 
08908         temp_service.host_name=host_name;
08909         temp_service.service_description=service_description;
08910 
08911         return skiplist_find_first(xobject_skiplists[X_SERVICE_SKIPLIST],&temp_service,NULL);
08912         }
08913 
08914 #endif
08915 
08916 
08917 
08918 /******************************************************************/
08919 /**************** OBJECT REGISTRATION FUNCTIONS *******************/
08920 /******************************************************************/
08921 
08922 /* registers object definitions */
08923 int xodtemplate_register_objects(void){
08924         int result=OK;
08925         xodtemplate_timeperiod *temp_timeperiod=NULL;
08926         xodtemplate_command *temp_command=NULL;
08927         xodtemplate_contactgroup *temp_contactgroup=NULL;
08928         xodtemplate_hostgroup *temp_hostgroup=NULL;
08929         xodtemplate_servicegroup *temp_servicegroup=NULL;
08930         xodtemplate_contact *temp_contact=NULL;
08931         xodtemplate_host *temp_host=NULL;
08932         xodtemplate_service *temp_service=NULL;
08933         xodtemplate_servicedependency *temp_servicedependency=NULL;
08934         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
08935         xodtemplate_hostdependency *temp_hostdependency=NULL;
08936         xodtemplate_hostescalation *temp_hostescalation=NULL;
08937         xodtemplate_module *temp_module=NULL;
08938         void *ptr=NULL;
08939 
08940         /* register timeperiods */
08941         /*for(temp_timeperiod=xodtemplate_timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){*/
08942         ptr=NULL;
08943         for(temp_timeperiod=(xodtemplate_timeperiod *)skiplist_get_first(xobject_skiplists[X_TIMEPERIOD_SKIPLIST],&ptr);temp_timeperiod!=NULL;temp_timeperiod=(xodtemplate_timeperiod *)skiplist_get_next(&ptr)){
08944                 if((result=xodtemplate_register_timeperiod(temp_timeperiod))==ERROR)
08945                         return ERROR;
08946                 }
08947 
08948         /* register commands */
08949         /*for(temp_command=xodtemplate_command_list;temp_command!=NULL;temp_command=temp_command->next){*/
08950         ptr=NULL;
08951         for(temp_command=(xodtemplate_command *)skiplist_get_first(xobject_skiplists[X_COMMAND_SKIPLIST],&ptr);temp_command!=NULL;temp_command=(xodtemplate_command *)skiplist_get_next(&ptr)){
08952                 if((result=xodtemplate_register_command(temp_command))==ERROR)
08953                         return ERROR;
08954                 }
08955 
08956         /* register contactgroups */
08957         /*for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){*/
08958         ptr=NULL;
08959         for(temp_contactgroup=(xodtemplate_contactgroup *)skiplist_get_first(xobject_skiplists[X_CONTACTGROUP_SKIPLIST],&ptr);temp_contactgroup!=NULL;temp_contactgroup=(xodtemplate_contactgroup *)skiplist_get_next(&ptr)){
08960                 if((result=xodtemplate_register_contactgroup(temp_contactgroup))==ERROR)
08961                         return ERROR;
08962                 }
08963 
08964         /* register hostgroups */
08965         /*for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){*/
08966         ptr=NULL;
08967         for(temp_hostgroup=(xodtemplate_hostgroup *)skiplist_get_first(xobject_skiplists[X_HOSTGROUP_SKIPLIST],&ptr);temp_hostgroup!=NULL;temp_hostgroup=(xodtemplate_hostgroup *)skiplist_get_next(&ptr)){
08968                 if((result=xodtemplate_register_hostgroup(temp_hostgroup))==ERROR)
08969                         return ERROR;
08970                 }
08971 
08972         /* register servicegroups */
08973         /*for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){*/
08974         ptr=NULL;
08975         for(temp_servicegroup=(xodtemplate_servicegroup *)skiplist_get_first(xobject_skiplists[X_SERVICEGROUP_SKIPLIST],&ptr);temp_servicegroup!=NULL;temp_servicegroup=(xodtemplate_servicegroup *)skiplist_get_next(&ptr)){
08976                 if((result=xodtemplate_register_servicegroup(temp_servicegroup))==ERROR)
08977                         return ERROR;
08978                 }
08979 
08980         /* register contacts */
08981         /*for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){*/
08982         ptr=NULL;
08983         for(temp_contact=(xodtemplate_contact *)skiplist_get_first(xobject_skiplists[X_CONTACT_SKIPLIST],&ptr);temp_contact!=NULL;temp_contact=(xodtemplate_contact *)skiplist_get_next(&ptr)){
08984                 if((result=xodtemplate_register_contact(temp_contact))==ERROR)
08985                         return ERROR;
08986                 }
08987 
08988         /* register hosts */
08989         /*for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){*/
08990         ptr=NULL;
08991         for(temp_host=(xodtemplate_host *)skiplist_get_first(xobject_skiplists[X_HOST_SKIPLIST],&ptr);temp_host!=NULL;temp_host=(xodtemplate_host *)skiplist_get_next(&ptr)){
08992                 if((result=xodtemplate_register_host(temp_host))==ERROR)
08993                         return ERROR;
08994                 }
08995 
08996         /* register services */
08997         /*for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){*/
08998         ptr=NULL;
08999         for(temp_service=(xodtemplate_service *)skiplist_get_first(xobject_skiplists[X_SERVICE_SKIPLIST],&ptr);temp_service!=NULL;temp_service=(xodtemplate_service *)skiplist_get_next(&ptr)){
09000 
09001                 if((result=xodtemplate_register_service(temp_service))==ERROR)
09002                         return ERROR;
09003                 }
09004 
09005         /* register service dependencies */
09006         /*for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){*/
09007         ptr=NULL;
09008         for(temp_servicedependency=(xodtemplate_servicedependency *)skiplist_get_first(xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],&ptr);temp_servicedependency!=NULL;temp_servicedependency=(xodtemplate_servicedependency *)skiplist_get_next(&ptr)){
09009                 if((result=xodtemplate_register_servicedependency(temp_servicedependency))==ERROR)
09010                         return ERROR;
09011                 }
09012 
09013         /* register service escalations */
09014         /*for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){*/
09015         ptr=NULL;
09016         for(temp_serviceescalation=(xodtemplate_serviceescalation *)skiplist_get_first(xobject_skiplists[X_SERVICEESCALATION_SKIPLIST],&ptr);temp_serviceescalation!=NULL;temp_serviceescalation=(xodtemplate_serviceescalation *)skiplist_get_next(&ptr)){
09017                 if((result=xodtemplate_register_serviceescalation(temp_serviceescalation))==ERROR)
09018                         return ERROR;
09019                 }
09020 
09021         /* register host dependencies */
09022         /*for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){*/
09023         ptr=NULL;
09024         for(temp_hostdependency=(xodtemplate_hostdependency *)skiplist_get_first(xobject_skiplists[X_HOSTDEPENDENCY_SKIPLIST],&ptr);temp_hostdependency!=NULL;temp_hostdependency=(xodtemplate_hostdependency *)skiplist_get_next(&ptr)){
09025                 if((result=xodtemplate_register_hostdependency(temp_hostdependency))==ERROR)
09026                         return ERROR;
09027                 }
09028 
09029         /* register host escalations */
09030         /*for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){*/
09031         ptr=NULL;
09032         for(temp_hostescalation=(xodtemplate_hostescalation *)skiplist_get_first(xobject_skiplists[X_HOSTESCALATION_SKIPLIST],&ptr);temp_hostescalation!=NULL;temp_hostescalation=(xodtemplate_hostescalation *)skiplist_get_next(&ptr)){
09033                 if((result=xodtemplate_register_hostescalation(temp_hostescalation))==ERROR)
09034                         return ERROR;
09035                 }
09036 
09037         /* register modules */
09038         /*for(temp_module=xodtemplate_module_list;temp_module!=NULL;temp_module=temp_module->next){*/
09039         ptr=NULL;
09040         for(temp_module=(xodtemplate_module *)skiplist_get_first(xobject_skiplists[X_MODULE_SKIPLIST],&ptr);temp_module!=NULL;temp_module=(xodtemplate_module *)skiplist_get_next(&ptr)){
09041                 if((result=xodtemplate_register_module(temp_module))==ERROR)
09042                         return ERROR;
09043                 }
09044 
09045 
09046         return OK;
09047         }
09048 
09049 
09050 
09051 /* registers a timeperiod definition */
09052 int xodtemplate_register_timeperiod(xodtemplate_timeperiod *this_timeperiod){
09053         xodtemplate_daterange *temp_daterange=NULL;
09054         timeperiod *new_timeperiod=NULL;
09055         daterange *new_daterange=NULL;
09056         timerange *new_timerange=NULL;
09057         timeperiodexclusion *new_timeperiodexclusion=NULL;
09058         int day=0;
09059         int range=0;
09060         int x=0;
09061         char *day_range_ptr=NULL;
09062         char *day_range_start_buffer=NULL;
09063         char *temp_ptr=NULL;
09064         unsigned long range_start_time=0L;
09065         unsigned long range_end_time=0L;
09066         
09067 
09068         /* bail out if we shouldn't register this object */
09069         if(this_timeperiod->register_object==FALSE)
09070                 return OK;
09071 
09072         /* add the timeperiod */
09073         new_timeperiod=add_timeperiod(this_timeperiod->timeperiod_name,this_timeperiod->alias);
09074 
09075         /* return with an error if we couldn't add the timeperiod */
09076         if(new_timeperiod==NULL){
09077                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register timeperiod (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09078                 return ERROR;
09079                 }
09080 
09081         /* add all exceptions to timeperiod */
09082         for(x=0;x<DATERANGE_TYPES;x++){
09083                 for(temp_daterange=this_timeperiod->exceptions[x];temp_daterange!=NULL;temp_daterange=temp_daterange->next){
09084 
09085                         /* skip null entries */
09086                         if(temp_daterange->timeranges==NULL || !strcmp(temp_daterange->timeranges,XODTEMPLATE_NULL))
09087                                 continue;
09088 
09089                         /* add new exception to timeperiod */
09090                         new_daterange=add_exception_to_timeperiod(new_timeperiod,temp_daterange->type,temp_daterange->syear,temp_daterange->smon,temp_daterange->smday,temp_daterange->swday,temp_daterange->swday_offset,temp_daterange->eyear,temp_daterange->emon,temp_daterange->emday,temp_daterange->ewday,temp_daterange->ewday_offset,temp_daterange->skip_interval);
09091                         if(new_daterange==NULL){
09092                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add date exception to timeperiod (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09093                                 return ERROR;
09094                                 }
09095 
09096                         /* add timeranges to exception */
09097                         day_range_ptr=temp_daterange->timeranges;
09098                         range=0;
09099                         for(day_range_start_buffer=my_strsep(&day_range_ptr,", ");day_range_start_buffer!=NULL;day_range_start_buffer=my_strsep(&day_range_ptr,", ")){
09100 
09101                                 range++;
09102 
09103                                 /* get time ranges */
09104                                 if(xodtemplate_get_time_ranges(day_range_start_buffer,&range_start_time,&range_end_time)==ERROR){
09105                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not parse timerange #%d of timeperiod (config file '%s', starting on line %d)\n",range,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09106                                         return ERROR;
09107                                         }
09108 
09109                                 /* add the new time range to the date range */
09110                                 new_timerange=add_timerange_to_daterange(new_daterange,range_start_time,range_end_time);
09111                                 if(new_timerange==NULL){
09112                                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add timerange #%d to timeperiod (config file '%s', starting on line %d)\n",range,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09113                                         return ERROR;
09114                                         }
09115                                 }
09116                         }
09117                 }
09118 
09119         /* add all necessary timeranges to timeperiod */
09120         for(day=0;day<7;day++){
09121 
09122                 /* skip null entries */
09123                 if(this_timeperiod->timeranges[day]==NULL || !strcmp(this_timeperiod->timeranges[day],XODTEMPLATE_NULL))
09124                         continue;
09125 
09126                 day_range_ptr=this_timeperiod->timeranges[day];
09127                 range=0;
09128                 for(day_range_start_buffer=my_strsep(&day_range_ptr,", ");day_range_start_buffer!=NULL;day_range_start_buffer=my_strsep(&day_range_ptr,", ")){
09129 
09130                         range++;
09131 
09132                         /* get time ranges */
09133                         if(xodtemplate_get_time_ranges(day_range_start_buffer,&range_start_time,&range_end_time)==ERROR){
09134                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not parse timerange #%d for day %d of timeperiod (config file '%s', starting on line %d)\n",range,day,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09135                                 return ERROR;
09136                                 }
09137 
09138                         /* add the new time range to the time period */
09139                         new_timerange=add_timerange_to_timeperiod(new_timeperiod,day,range_start_time,range_end_time);
09140                         if(new_timerange==NULL){
09141                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add timerange #%d for day %d to timeperiod (config file '%s', starting on line %d)\n",range,day,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09142                                 return ERROR;
09143                                 }
09144                         }
09145                 
09146                 }
09147 
09148         /* add timeperiod exclusions */
09149         if(this_timeperiod->exclusions){
09150                 for(temp_ptr=strtok(this_timeperiod->exclusions,",");temp_ptr!=NULL;temp_ptr=strtok(NULL,",")){
09151                         strip(temp_ptr);
09152                         new_timeperiodexclusion=add_exclusion_to_timeperiod(new_timeperiod,temp_ptr);
09153                         if(new_timeperiodexclusion==NULL){
09154                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add excluded timeperiod '%s' to timeperiod (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(this_timeperiod->_config_file),this_timeperiod->_start_line);
09155                                 return ERROR;
09156                                 }
09157                         }
09158                 }
09159 
09160         return OK;
09161         }
09162 
09163 
09164 
09165 /* parses timerange string into start and end minutes */
09166 int xodtemplate_get_time_ranges(char *buf, unsigned long *range_start, unsigned long *range_end){
09167         char *range_ptr=NULL;
09168         char *range_buffer=NULL;
09169         char *time_ptr=NULL;
09170         char *time_buffer=NULL;
09171         int hours=0;
09172         int minutes=0;
09173 
09174         if(buf==NULL || range_start==NULL || range_end==NULL)
09175                 return ERROR;
09176 
09177         range_ptr=buf;
09178         range_buffer=my_strsep(&range_ptr,"-");
09179         if(range_buffer==NULL)
09180                 return ERROR;
09181 
09182         time_ptr=range_buffer;
09183         time_buffer=my_strsep(&time_ptr,":");
09184         if(time_buffer==NULL)
09185                 return ERROR;
09186         hours=atoi(time_buffer);
09187 
09188         time_buffer=my_strsep(&time_ptr,":");
09189         if(time_buffer==NULL)
09190                 return ERROR;
09191         minutes=atoi(time_buffer);
09192 
09193         /* calculate the range start time in seconds */
09194         *range_start=(unsigned long)((minutes*60)+(hours*60*60));
09195 
09196         range_buffer=my_strsep(&range_ptr,"-");
09197         if(range_buffer==NULL)
09198                 return ERROR;
09199 
09200         time_ptr=range_buffer;
09201         time_buffer=my_strsep(&time_ptr,":");
09202         if(time_buffer==NULL)
09203                 return ERROR;
09204         hours=atoi(time_buffer);
09205 
09206         time_buffer=my_strsep(&time_ptr,":");
09207         if(time_buffer==NULL)
09208                 return ERROR;
09209         minutes=atoi(time_buffer);
09210 
09211         /* calculate the range end time in seconds */
09212         *range_end=(unsigned long)((minutes*60)+(hours*3600));
09213 
09214         return OK;
09215         }
09216 
09217 
09218 
09219 /* registers a command definition */
09220 int xodtemplate_register_command(xodtemplate_command *this_command){
09221         command *new_command=NULL;
09222 
09223         /* bail out if we shouldn't register this object */
09224         if(this_command->register_object==FALSE)
09225                 return OK;
09226 
09227         /* add the command */
09228         new_command=add_command(this_command->command_name,this_command->command_line);
09229 
09230         /* return with an error if we couldn't add the command */
09231         if(new_command==NULL){
09232                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register command (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_command->_config_file),this_command->_start_line);
09233                 return ERROR;
09234                 }
09235 
09236         return OK;
09237         }
09238 
09239 
09240 
09241 /* registers a contactgroup definition */
09242 int xodtemplate_register_contactgroup(xodtemplate_contactgroup *this_contactgroup){
09243         contactgroup *new_contactgroup=NULL;
09244         contactsmember *new_contactsmember=NULL;
09245         char *contact_name=NULL;
09246 
09247         /* bail out if we shouldn't register this object */
09248         if(this_contactgroup->register_object==FALSE)
09249                 return OK;
09250 
09251         /* add the contact group */
09252         new_contactgroup=add_contactgroup(this_contactgroup->contactgroup_name,this_contactgroup->alias);
09253 
09254         /* return with an error if we couldn't add the contactgroup */
09255         if(new_contactgroup==NULL){
09256                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register contactgroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_contactgroup->_config_file),this_contactgroup->_start_line);
09257                 return ERROR;
09258                 }
09259 
09260         /* Need to check for NULL because strtok could use a NULL value to check the previous string's token value */
09261         if(this_contactgroup->members!=NULL){
09262                 for(contact_name=strtok(this_contactgroup->members,",");contact_name!=NULL;contact_name=strtok(NULL,",")){
09263                         strip(contact_name);
09264                         new_contactsmember=add_contact_to_contactgroup(new_contactgroup,contact_name);
09265                         if(new_contactsmember==NULL){
09266                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to contactgroup (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_contactgroup->_config_file),this_contactgroup->_start_line);
09267                                 return ERROR;
09268                                 }
09269                         }
09270                 }
09271 
09272         return OK;
09273         }
09274 
09275 
09276 
09277 /* registers a hostgroup definition */
09278 int xodtemplate_register_hostgroup(xodtemplate_hostgroup *this_hostgroup){
09279         hostgroup *new_hostgroup=NULL;
09280         hostsmember *new_hostsmember=NULL;
09281         char *host_name=NULL;
09282 
09283         /* bail out if we shouldn't register this object */
09284         if(this_hostgroup->register_object==FALSE)
09285                 return OK;
09286 
09287         /* add the  host group */
09288         new_hostgroup=add_hostgroup(this_hostgroup->hostgroup_name,this_hostgroup->alias,this_hostgroup->notes,this_hostgroup->notes_url,this_hostgroup->action_url);
09289 
09290         /* return with an error if we couldn't add the hostgroup */
09291         if(new_hostgroup==NULL){
09292                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register hostgroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_hostgroup->_config_file),this_hostgroup->_start_line);
09293                 return ERROR;
09294                 }
09295 
09296         if (this_hostgroup->members!=NULL) {
09297                 for(host_name=strtok(this_hostgroup->members,",");host_name!=NULL;host_name=strtok(NULL,",")){
09298                         strip(host_name);
09299                         new_hostsmember=add_host_to_hostgroup(new_hostgroup,host_name);
09300                         if(new_hostsmember==NULL){
09301                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host '%s' to hostgroup (config file '%s', starting on line %d)\n",host_name,xodtemplate_config_file_name(this_hostgroup->_config_file),this_hostgroup->_start_line);
09302                                 return ERROR;
09303                                 }
09304                         }
09305                 }
09306 
09307         return OK;
09308         }
09309 
09310 
09311 
09312 /* registers a servicegroup definition */
09313 int xodtemplate_register_servicegroup(xodtemplate_servicegroup *this_servicegroup){
09314         servicegroup *new_servicegroup=NULL;
09315         servicesmember *new_servicesmember=NULL;
09316         char *host_name=NULL;
09317         char *svc_description=NULL;
09318 
09319         /* bail out if we shouldn't register this object */
09320         if(this_servicegroup->register_object==FALSE)
09321                 return OK;
09322 
09323         /* add the  service group */
09324         new_servicegroup=add_servicegroup(this_servicegroup->servicegroup_name,this_servicegroup->alias,this_servicegroup->notes,this_servicegroup->notes_url,this_servicegroup->action_url);
09325 
09326         /* return with an error if we couldn't add the servicegroup */
09327         if(new_servicegroup==NULL){
09328                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register servicegroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_servicegroup->_config_file),this_servicegroup->_start_line);
09329                 return ERROR;
09330                 }
09331 
09332         if(this_servicegroup->members!=NULL) {
09333                 for(host_name=strtok(this_servicegroup->members,",");host_name!=NULL;host_name=strtok(NULL,",")){
09334                         strip(host_name);
09335                         svc_description=strtok(NULL,",");
09336                         if(svc_description==NULL){
09337                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Missing service name in servicegroup definition (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_servicegroup->_config_file),this_servicegroup->_start_line);
09338                                 return ERROR;
09339                                 }
09340                         strip(svc_description);
09341 
09342                         new_servicesmember=add_service_to_servicegroup(new_servicegroup,host_name,svc_description);
09343                         if(new_servicesmember==NULL){
09344                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service '%s' on host '%s' to servicegroup (config file '%s', starting on line %d)\n",svc_description,host_name,xodtemplate_config_file_name(this_servicegroup->_config_file),this_servicegroup->_start_line);
09345                                 return ERROR;
09346                                 }
09347                         }
09348                 }
09349 
09350         return OK;
09351         }
09352 
09353 
09354 
09355 /* registers a servicedependency definition */
09356 int xodtemplate_register_servicedependency(xodtemplate_servicedependency *this_servicedependency){
09357         servicedependency *new_servicedependency=NULL;
09358 
09359         /* bail out if we shouldn't register this object */
09360         if(this_servicedependency->register_object==FALSE)
09361                 return OK;
09362 
09363         /* throw a warning on servicedeps that have no options */
09364         if(this_servicedependency->have_notification_dependency_options==FALSE && this_servicedependency->have_execution_dependency_options==FALSE){
09365                 logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Ignoring lame service dependency (config file '%s', line %d)\n",xodtemplate_config_file_name(this_servicedependency->_config_file),this_servicedependency->_start_line);
09366                 return OK;
09367                 }
09368 
09369         /* add the servicedependency */
09370         if(this_servicedependency->have_execution_dependency_options==TRUE){
09371 
09372                 new_servicedependency=add_service_dependency(this_servicedependency->dependent_host_name,this_servicedependency->dependent_service_description,this_servicedependency->host_name,this_servicedependency->service_description,EXECUTION_DEPENDENCY,this_servicedependency->inherits_parent,this_servicedependency->fail_execute_on_ok,this_servicedependency->fail_execute_on_warning,this_servicedependency->fail_execute_on_unknown,this_servicedependency->fail_execute_on_critical,this_servicedependency->fail_execute_on_pending,this_servicedependency->dependency_period);
09373 
09374                 /* return with an error if we couldn't add the servicedependency */
09375                 if(new_servicedependency==NULL){
09376                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register service execution dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_servicedependency->_config_file),this_servicedependency->_start_line);
09377                         return ERROR;
09378                         }
09379                 }
09380         if(this_servicedependency->have_notification_dependency_options==TRUE){
09381 
09382                 new_servicedependency=add_service_dependency(this_servicedependency->dependent_host_name,this_servicedependency->dependent_service_description,this_servicedependency->host_name,this_servicedependency->service_description,NOTIFICATION_DEPENDENCY,this_servicedependency->inherits_parent,this_servicedependency->fail_notify_on_ok,this_servicedependency->fail_notify_on_warning,this_servicedependency->fail_notify_on_unknown,this_servicedependency->fail_notify_on_critical,this_servicedependency->fail_notify_on_pending,this_servicedependency->dependency_period);
09383 
09384                 /* return with an error if we couldn't add the servicedependency */
09385                 if(new_servicedependency==NULL){
09386                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register service notification dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_servicedependency->_config_file),this_servicedependency->_start_line);
09387                         return ERROR;
09388                         }
09389                 }
09390 
09391         return OK;
09392         }
09393 
09394 
09395 
09396 /* registers a serviceescalation definition */
09397 int xodtemplate_register_serviceescalation(xodtemplate_serviceescalation *this_serviceescalation){
09398         serviceescalation *new_serviceescalation=NULL;
09399         contactsmember *new_contactsmember=NULL;
09400         contactgroupsmember *new_contactgroupsmember=NULL;
09401         char *contact_name=NULL;
09402         char *contact_group=NULL;
09403 
09404         /* bail out if we shouldn't register this object */
09405         if(this_serviceescalation->register_object==FALSE)
09406                 return OK;
09407 
09408         /* default options if none specified */
09409         if(this_serviceescalation->have_escalation_options==FALSE){
09410                 this_serviceescalation->escalate_on_warning=TRUE;
09411                 this_serviceescalation->escalate_on_unknown=TRUE;
09412                 this_serviceescalation->escalate_on_critical=TRUE;
09413                 this_serviceescalation->escalate_on_recovery=TRUE;
09414                 }
09415 
09416         /* add the serviceescalation */
09417 #ifndef USE_ST_BASED_ESCAL_RANGES
09418         new_serviceescalation=add_serviceescalation(this_serviceescalation->host_name,this_serviceescalation->service_description,this_serviceescalation->first_notification,this_serviceescalation->last_notification,this_serviceescalation->notification_interval,this_serviceescalation->escalation_period,this_serviceescalation->escalate_on_warning,this_serviceescalation->escalate_on_unknown,this_serviceescalation->escalate_on_critical,this_serviceescalation->escalate_on_recovery);
09419 #else
09420         new_serviceescalation=add_serviceescalation(this_serviceescalation->host_name,this_serviceescalation->service_description,this_serviceescalation->first_notification,this_serviceescalation->last_notification,this_serviceescalation->first_warning_notification,this_serviceescalation->last_warning_notification,this_serviceescalation->first_critical_notification,this_serviceescalation->last_critical_notification,this_serviceescalation->first_unknown_notification,this_serviceescalation->last_unknown_notification,this_serviceescalation->notification_interval,this_serviceescalation->escalation_period,this_serviceescalation->escalate_on_warning,this_serviceescalation->escalate_on_unknown,this_serviceescalation->escalate_on_critical,this_serviceescalation->escalate_on_recovery);
09421 #endif
09422 
09423         /* return with an error if we couldn't add the serviceescalation */
09424         if(new_serviceescalation==NULL){
09425                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register service escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_serviceescalation->_config_file),this_serviceescalation->_start_line);
09426                 return ERROR;
09427                 }
09428 
09429         /* add the contact groups */
09430         if(this_serviceescalation->contact_groups!=NULL){
09431 
09432                 for(contact_group=strtok(this_serviceescalation->contact_groups,",");contact_group!=NULL;contact_group=strtok(NULL,", ")){
09433 
09434                         strip(contact_group);
09435                         new_contactgroupsmember=add_contactgroup_to_serviceescalation(new_serviceescalation,contact_group);
09436                         if(new_contactgroupsmember==NULL){
09437                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to service escalation (config file '%s', starting on line %d)\n",contact_group,xodtemplate_config_file_name(this_serviceescalation->_config_file),this_serviceescalation->_start_line);
09438                                 return ERROR;
09439                                 }
09440                         }
09441                 }
09442 
09443         /* add the contacts */
09444         if(this_serviceescalation->contacts!=NULL){
09445 
09446                 for(contact_name=strtok(this_serviceescalation->contacts,",");contact_name!=NULL;contact_name=strtok(NULL,", ")){
09447 
09448                         strip(contact_name);
09449                         new_contactsmember=add_contact_to_serviceescalation(new_serviceescalation,contact_name);
09450                         if(new_contactsmember==NULL){
09451                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to service escalation (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_serviceescalation->_config_file),this_serviceescalation->_start_line);
09452                                 return ERROR;
09453                                 }
09454                         }
09455                 }
09456  
09457         /* add conditions */
09458         new_serviceescalation->condition=NULL;
09459         if(this_serviceescalation->condition!=NULL){
09460                 escalation_condition *last_condition=NULL;
09461                 xodtemplate_escalation_condition *temp_condition=this_serviceescalation->condition;
09462                 while(temp_condition!=NULL){
09463                                 last_condition=add_serviceescalation_condition(new_serviceescalation, last_condition, 
09464                                         temp_condition->host_name,
09465                                         temp_condition->service_description,
09466                                         temp_condition->connector,
09467                                         temp_condition->escalate_on_down,
09468                                         temp_condition->escalate_on_unreachable,
09469                                         temp_condition->escalate_on_warning,
09470                                         temp_condition->escalate_on_unknown,
09471                                         temp_condition->escalate_on_critical,
09472                                         temp_condition->escalate_on_ok);
09473                                        
09474                         temp_condition=temp_condition->next;
09475                        
09476                         if(last_condition==NULL){
09477                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add condition to service escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_serviceescalation->_config_file),this_serviceescalation->_start_line);
09478                                 return ERROR;
09479                         }
09480                 }
09481         }
09482    
09483         return OK;
09484         }
09485 
09486 
09487 
09488 /* registers a contact definition */
09489 int xodtemplate_register_contact(xodtemplate_contact *this_contact){
09490         contact *new_contact=NULL;
09491         char *command_name=NULL;
09492         commandsmember *new_commandsmember=NULL;
09493         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
09494 
09495         /* bail out if we shouldn't register this object */
09496         if(this_contact->register_object==FALSE)
09497                 return OK;
09498 
09499         /* add the contact */
09500         new_contact=add_contact(this_contact->contact_name,this_contact->alias,this_contact->email,this_contact->pager,this_contact->address,this_contact->service_notification_period,this_contact->host_notification_period,this_contact->notify_on_service_recovery,this_contact->notify_on_service_critical,this_contact->notify_on_service_warning,this_contact->notify_on_service_unknown,this_contact->notify_on_service_flapping,this_contact->notify_on_service_downtime,this_contact->notify_on_host_recovery,this_contact->notify_on_host_down,this_contact->notify_on_host_unreachable,this_contact->notify_on_host_flapping,this_contact->notify_on_host_downtime,this_contact->host_notifications_enabled,this_contact->service_notifications_enabled,this_contact->can_submit_commands,this_contact->retain_status_information,this_contact->retain_nonstatus_information);
09501 
09502         /* return with an error if we couldn't add the contact */
09503         if(new_contact==NULL){
09504                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register contact (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_contact->_config_file),this_contact->_start_line);
09505                 return ERROR;
09506                 }
09507 
09508         /* add all the host notification commands */
09509         if(this_contact->host_notification_commands!=NULL){
09510 
09511                 for(command_name=strtok(this_contact->host_notification_commands,", ");command_name!=NULL;command_name=strtok(NULL,", ")){
09512                         new_commandsmember=add_host_notification_command_to_contact(new_contact,command_name);
09513                         if(new_commandsmember==NULL){
09514                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host notification command '%s' to contact (config file '%s', starting on line %d)\n",command_name,xodtemplate_config_file_name(this_contact->_config_file),this_contact->_start_line);
09515                                 return ERROR;
09516                                 }
09517                         }
09518                 }
09519 
09520         /* add all the service notification commands */
09521         if(this_contact->service_notification_commands!=NULL){
09522 
09523                 for(command_name=strtok(this_contact->service_notification_commands,", ");command_name!=NULL;command_name=strtok(NULL,", ")){
09524                         new_commandsmember=add_service_notification_command_to_contact(new_contact,command_name);
09525                         if(new_commandsmember==NULL){
09526                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service notification command '%s' to contact (config file '%s', starting on line %d)\n",command_name,xodtemplate_config_file_name(this_contact->_config_file),this_contact->_start_line);
09527                                 return ERROR;
09528                                 }
09529                         }
09530                 }
09531 
09532         /* add all custom variables */
09533         for(temp_customvariablesmember=this_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
09534                 if((add_custom_variable_to_contact(new_contact,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value))==NULL){
09535                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not custom variable to contact (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_contact->_config_file),this_contact->_start_line);
09536                         return ERROR;
09537                         }
09538                 }
09539 
09540         return OK;
09541         }
09542 
09543 
09544 
09545 /* registers a host definition */
09546 int xodtemplate_register_host(xodtemplate_host *this_host){
09547         host *new_host=NULL;
09548         char *parent_host=NULL;
09549         hostsmember *new_hostsmember=NULL;
09550         contactsmember *new_contactsmember=NULL;
09551         contactgroupsmember *new_contactgroupsmember=NULL;
09552         char *contact_name=NULL;
09553         char *contact_group=NULL;
09554         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
09555 
09556         /* bail out if we shouldn't register this object */
09557         if(this_host->register_object==FALSE)
09558                 return OK;
09559 
09560         /* if host has no alias or address, use host name - added 3/11/05 */
09561         if(this_host->alias==NULL && this_host->host_name!=NULL)
09562                 this_host->alias=(char *)strdup(this_host->host_name);
09563         if(this_host->address==NULL && this_host->host_name!=NULL)
09564                 this_host->address=(char *)strdup(this_host->host_name);
09565         if(this_host->address6==NULL && this_host->host_name!=NULL)
09566                 this_host->address6=(char *)strdup(this_host->host_name);
09567 
09568         /* add the host definition */
09569         new_host=add_host(this_host->host_name,this_host->display_name,this_host->alias,(this_host->address==NULL)?this_host->host_name:this_host->address,(this_host->address6==NULL)?this_host->host_name:this_host->address6,this_host->check_period,this_host->initial_state,this_host->check_interval,this_host->retry_interval,this_host->max_check_attempts,this_host->notify_on_recovery,this_host->notify_on_down,this_host->notify_on_unreachable,this_host->notify_on_flapping,this_host->notify_on_downtime,this_host->notification_interval,this_host->first_notification_delay,this_host->notification_period,this_host->notifications_enabled,this_host->check_command,this_host->active_checks_enabled,this_host->passive_checks_enabled,this_host->event_handler,this_host->event_handler_enabled,this_host->flap_detection_enabled,this_host->low_flap_threshold,this_host->high_flap_threshold,this_host->flap_detection_on_up,this_host->flap_detection_on_down,this_host->flap_detection_on_unreachable,this_host->stalk_on_up,this_host->stalk_on_down,this_host->stalk_on_unreachable,this_host->process_perf_data,this_host->failure_prediction_enabled,this_host->failure_prediction_options,this_host->check_freshness,this_host->freshness_threshold,this_host->notes,this_host->notes_url,this_host->action_url,this_host->icon_image,this_host->icon_image_alt,this_host->vrml_image,this_host->statusmap_image,this_host->x_2d,this_host->y_2d,this_host->have_2d_coords,this_host->x_3d,this_host->y_3d,this_host->z_3d,this_host->have_3d_coords,TRUE,this_host->retain_status_information,this_host->retain_nonstatus_information,this_host->obsess_over_host);
09570 
09571 
09572         /* return with an error if we couldn't add the host */
09573         if(new_host==NULL){
09574                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register host (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
09575                 return ERROR;
09576                 }
09577 
09578         /* add the parent hosts */
09579         if(this_host->parents!=NULL){
09580 
09581                 for(parent_host=strtok(this_host->parents,",");parent_host!=NULL;parent_host=strtok(NULL,",")){
09582                         strip(parent_host);
09583                         new_hostsmember=add_parent_host_to_host(new_host,parent_host);
09584                         if(new_hostsmember==NULL){
09585                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add parent host '%s' to host (config file '%s', starting on line %d)\n",parent_host,xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
09586                                 return ERROR;
09587                                 }
09588                         }
09589                 }
09590 
09591         /* add all contact groups to the host */
09592         if(this_host->contact_groups!=NULL){
09593 
09594                 for(contact_group=strtok(this_host->contact_groups,",");contact_group!=NULL;contact_group=strtok(NULL,",")){
09595 
09596                         strip(contact_group);
09597                         new_contactgroupsmember=add_contactgroup_to_host(new_host,contact_group);
09598                         if(new_contactgroupsmember==NULL){
09599                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to host (config file '%s', starting on line %d)\n",contact_group,xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
09600                                 return ERROR;
09601                                 }
09602                         }
09603                 }
09604 
09605         /* add all contacts to the host */
09606         if(this_host->contacts!=NULL){
09607 
09608                 for(contact_name=strtok(this_host->contacts,",");contact_name!=NULL;contact_name=strtok(NULL,",")){
09609 
09610                         strip(contact_name);
09611                         new_contactsmember=add_contact_to_host(new_host,contact_name);
09612                         if(new_contactsmember==NULL){
09613                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to host (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
09614                                 return ERROR;
09615                                 }
09616                         }
09617                 }
09618 
09619         /* add all custom variables */
09620         for(temp_customvariablesmember=this_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
09621                 if((add_custom_variable_to_host(new_host,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value))==NULL){
09622                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not custom variable to host (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_host->_config_file),this_host->_start_line);
09623                         return ERROR;
09624                         }
09625                 }
09626 
09627         return OK;
09628         }
09629 
09630 
09631 
09632 /* registers a service definition */
09633 int xodtemplate_register_service(xodtemplate_service *this_service){
09634         service *new_service=NULL;
09635         contactsmember *new_contactsmember=NULL;
09636         contactgroupsmember *new_contactgroupsmember=NULL;
09637         char *contact_name=NULL;
09638         char *contact_group=NULL;
09639         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
09640 
09641         /* bail out if we shouldn't register this object */
09642         if(this_service->register_object==FALSE)
09643                 return OK;
09644 
09645         /* add the service */
09646         new_service=add_service(this_service->host_name,this_service->service_description,this_service->display_name,this_service->check_period,this_service->initial_state,this_service->max_check_attempts,this_service->parallelize_check,this_service->passive_checks_enabled,this_service->check_interval,this_service->retry_interval,this_service->notification_interval,this_service->first_notification_delay,this_service->notification_period,this_service->notify_on_recovery,this_service->notify_on_unknown,this_service->notify_on_warning,this_service->notify_on_critical,this_service->notify_on_flapping,this_service->notify_on_downtime,this_service->notifications_enabled,this_service->is_volatile,this_service->event_handler,this_service->event_handler_enabled,this_service->check_command,this_service->active_checks_enabled,this_service->flap_detection_enabled,this_service->low_flap_threshold,this_service->high_flap_threshold,this_service->flap_detection_on_ok,this_service->flap_detection_on_warning,this_service->flap_detection_on_unknown,this_service->flap_detection_on_critical,this_service->stalk_on_ok,this_service->stalk_on_warning,this_service->stalk_on_unknown,this_service->stalk_on_critical,this_service->process_perf_data,this_service->failure_prediction_enabled,this_service->failure_prediction_options,this_service->check_freshness,this_service->freshness_threshold,this_service->notes,this_service->notes_url,this_service->action_url,this_service->icon_image,this_service->icon_image_alt,this_service->retain_status_information,this_service->retain_nonstatus_information,this_service->obsess_over_service);
09647 
09648         /* return with an error if we couldn't add the service */
09649         if(new_service==NULL){
09650                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register service (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_service->_config_file),this_service->_start_line);
09651                 return ERROR;
09652                 }
09653 
09654         /* add all contact groups to the service */
09655         if(this_service->contact_groups!=NULL){
09656 
09657                 for(contact_group=strtok(this_service->contact_groups,",");contact_group!=NULL;contact_group=strtok(NULL,",")){
09658 
09659                         strip(contact_group);
09660                         new_contactgroupsmember=add_contactgroup_to_service(new_service,contact_group);
09661                         if(new_contactgroupsmember==NULL){
09662                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to service (config file '%s', starting on line %d)\n",contact_group,xodtemplate_config_file_name(this_service->_config_file),this_service->_start_line);
09663                                 return ERROR;
09664                                 }
09665                         }
09666                 }
09667 
09668         /* add all the contacts to the service */
09669         if(this_service->contacts!=NULL){
09670 
09671                 for(contact_name=strtok(this_service->contacts,",");contact_name!=NULL;contact_name=strtok(NULL,",")){
09672 
09673                         /* add this contact to the service definition */
09674                         strip(contact_name);
09675                         new_contactsmember=add_contact_to_service(new_service,contact_name);
09676 
09677                         /* stop adding contacts if we ran into an error */
09678                         if(new_contactsmember==NULL){
09679                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to service (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_service->_config_file),this_service->_start_line);
09680                                 return ERROR;
09681                                 }
09682                         }
09683                 }
09684 
09685         /* add all custom variables */
09686         for(temp_customvariablesmember=this_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
09687                 if((add_custom_variable_to_service(new_service,temp_customvariablesmember->variable_name,temp_customvariablesmember->variable_value))==NULL){
09688                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not custom variable to service (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_service->_config_file),this_service->_start_line);
09689                         return ERROR;
09690                         }
09691                 }
09692 
09693         return OK;
09694         }
09695 
09696 
09697 
09698 /* registers a hostdependency definition */
09699 int xodtemplate_register_hostdependency(xodtemplate_hostdependency *this_hostdependency){
09700         hostdependency *new_hostdependency=NULL;
09701 
09702         /* bail out if we shouldn't register this object */
09703         if(this_hostdependency->register_object==FALSE)
09704                 return OK;
09705 
09706         /* add the host execution dependency */
09707         if(this_hostdependency->have_execution_dependency_options==TRUE){
09708 
09709                 new_hostdependency=add_host_dependency(this_hostdependency->dependent_host_name,this_hostdependency->host_name,EXECUTION_DEPENDENCY,this_hostdependency->inherits_parent,this_hostdependency->fail_execute_on_up,this_hostdependency->fail_execute_on_down,this_hostdependency->fail_execute_on_unreachable,this_hostdependency->fail_execute_on_pending,this_hostdependency->dependency_period);
09710 
09711                 /* return with an error if we couldn't add the hostdependency */
09712                 if(new_hostdependency==NULL){
09713                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register host execution dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_hostdependency->_config_file),this_hostdependency->_start_line);
09714                         return ERROR;
09715                         }
09716                 }
09717 
09718         /* add the host notification dependency */
09719         if(this_hostdependency->have_notification_dependency_options==TRUE){
09720 
09721                 new_hostdependency=add_host_dependency(this_hostdependency->dependent_host_name,this_hostdependency->host_name,NOTIFICATION_DEPENDENCY,this_hostdependency->inherits_parent,this_hostdependency->fail_notify_on_up,this_hostdependency->fail_notify_on_down,this_hostdependency->fail_notify_on_unreachable,this_hostdependency->fail_notify_on_pending,this_hostdependency->dependency_period);
09722 
09723                 /* return with an error if we couldn't add the hostdependency */
09724                 if(new_hostdependency==NULL){
09725                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register host notification dependency (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_hostdependency->_config_file),this_hostdependency->_start_line);
09726                         return ERROR;
09727                         }
09728                 }
09729 
09730         return OK;
09731         }
09732 
09733 
09734 
09735 /* registers a hostescalation definition */
09736 int xodtemplate_register_hostescalation(xodtemplate_hostescalation *this_hostescalation){
09737         hostescalation *new_hostescalation=NULL;
09738         contactsmember *new_contactsmember=NULL;
09739         contactgroupsmember *new_contactgroupsmember=NULL;
09740         char *contact_name=NULL;
09741         char *contact_group=NULL;
09742 
09743         /* bail out if we shouldn't register this object */
09744         if(this_hostescalation->register_object==FALSE)
09745                 return OK;
09746 
09747         /* default options if none specified */
09748         if(this_hostescalation->have_escalation_options==FALSE){
09749                 this_hostescalation->escalate_on_down=TRUE;
09750                 this_hostescalation->escalate_on_unreachable=TRUE;
09751                 this_hostescalation->escalate_on_recovery=TRUE;
09752                 }
09753 
09754         /* add the hostescalation */
09755 #ifndef USE_ST_BASED_ESCAL_RANGES
09756         new_hostescalation=add_hostescalation(this_hostescalation->host_name,this_hostescalation->first_notification,this_hostescalation->last_notification,this_hostescalation->notification_interval,this_hostescalation->escalation_period,this_hostescalation->escalate_on_down,this_hostescalation->escalate_on_unreachable,this_hostescalation->escalate_on_recovery);
09757 #else
09758         new_hostescalation=add_hostescalation(this_hostescalation->host_name,this_hostescalation->first_notification,this_hostescalation->last_notification,this_hostescalation->first_down_notification,this_hostescalation->last_down_notification,this_hostescalation->first_unreachable_notification,this_hostescalation->last_unreachable_notification,this_hostescalation->notification_interval,this_hostescalation->escalation_period,this_hostescalation->escalate_on_down,this_hostescalation->escalate_on_unreachable,this_hostescalation->escalate_on_recovery);
09759 #endif
09760 
09761         /* return with an error if we couldn't add the hostescalation */
09762         if(new_hostescalation==NULL){
09763                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register host escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_hostescalation->_config_file),this_hostescalation->_start_line);
09764                 return ERROR;
09765                 }
09766 
09767         /* add all contact groups */
09768         if(this_hostescalation->contact_groups!=NULL){
09769 
09770                 for(contact_group=strtok(this_hostescalation->contact_groups,",");contact_group!=NULL;contact_group=strtok(NULL,",")){
09771 
09772                         strip(contact_group);
09773                         new_contactgroupsmember=add_contactgroup_to_hostescalation(new_hostescalation,contact_group);
09774                         if(new_contactgroupsmember==NULL){
09775                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to host escalation (config file '%s', starting on line %d)\n",contact_group,xodtemplate_config_file_name(this_hostescalation->_config_file),this_hostescalation->_start_line);
09776                                 return ERROR;
09777                                 }
09778                         }
09779                 }
09780 
09781         /* add the contacts */
09782         if(this_hostescalation->contacts!=NULL){
09783 
09784                 for(contact_name=strtok(this_hostescalation->contacts,",");contact_name!=NULL;contact_name=strtok(NULL,", ")){
09785 
09786                         strip(contact_name);
09787                         new_contactsmember=add_contact_to_hostescalation(new_hostescalation,contact_name);
09788                         if(new_contactsmember==NULL){
09789                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to host escalation (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_hostescalation->_config_file),this_hostescalation->_start_line);
09790                                 return ERROR;
09791                                 }
09792                         }
09793                 }
09794  
09795         /* add conditions */
09796         new_hostescalation->condition=NULL;
09797         if(this_hostescalation->condition!=NULL){
09798                 escalation_condition *last_condition=NULL;
09799                 xodtemplate_escalation_condition *temp_condition=this_hostescalation->condition;
09800                 while(temp_condition!=NULL){
09801                                 last_condition=add_hostescalation_condition(new_hostescalation, last_condition, 
09802                                         temp_condition->host_name,
09803                                         temp_condition->service_description,
09804                                         temp_condition->connector,
09805                                         temp_condition->escalate_on_down,
09806                                         temp_condition->escalate_on_unreachable,
09807                                         temp_condition->escalate_on_warning,
09808                                         temp_condition->escalate_on_unknown,
09809                                         temp_condition->escalate_on_critical,
09810                                         temp_condition->escalate_on_ok);
09811                        
09812                         temp_condition=temp_condition->next;
09813                        
09814                         if(last_condition==NULL){
09815                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add condition to host escalation (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_hostescalation->_config_file),this_hostescalation->_start_line);
09816                                 return ERROR;
09817                         }
09818                 }
09819         }                       
09820 
09821         return OK;
09822         }
09823 
09824 
09825 /* registers a module definition */
09826 int xodtemplate_register_module(xodtemplate_module *this_module){
09827         module *new_module=NULL;
09828 
09829         /* bail out if we shouldn't register this object */
09830         if(this_module->register_object==FALSE)
09831                 return OK;
09832 
09833         /* add the module */
09834         new_module=add_module(this_module->module_name,this_module->module_type,this_module->path,this_module->args);
09835 
09836         /* return with an error if we couldn't add the module */
09837         if(new_module==NULL){
09838                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not register module (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(this_module->_config_file),this_module->_start_line);
09839                 return ERROR;
09840                 }
09841 
09842         return OK;
09843         }
09844 
09845 
09846 /******************************************************************/
09847 /********************** SORTING FUNCTIONS *************************/
09848 /******************************************************************/
09849 
09850 #ifdef NSCORE
09851 
09852 /* sorts all objects by name */
09853 int xodtemplate_sort_objects(void){
09854 
09855         /* NOTE: with skiplists, we no longer need to sort things manually... */
09856         return OK;
09857 
09858         /* sort timeperiods */
09859         if(xodtemplate_sort_timeperiods()==ERROR)
09860                 return ERROR;
09861 
09862         /* sort commands */
09863         if(xodtemplate_sort_commands()==ERROR)
09864                 return ERROR;
09865 
09866         /* sort contactgroups */
09867         if(xodtemplate_sort_contactgroups()==ERROR)
09868                 return ERROR;
09869 
09870         /* sort hostgroups */
09871         if(xodtemplate_sort_hostgroups()==ERROR)
09872                 return ERROR;
09873 
09874         /* sort servicegroups */
09875         if(xodtemplate_sort_servicegroups()==ERROR)
09876                 return ERROR;
09877 
09878         /* sort contacts */
09879         if(xodtemplate_sort_contacts()==ERROR)
09880                 return ERROR;
09881 
09882         /* sort hosts */
09883         if(xodtemplate_sort_hosts()==ERROR)
09884                 return ERROR;
09885 
09886         /* sort services */
09887         if(xodtemplate_sort_services()==ERROR)
09888                 return ERROR;
09889 
09890         /* sort service dependencies */
09891         if(xodtemplate_sort_servicedependencies()==ERROR)
09892                 return ERROR;
09893 
09894         /* sort service escalations */
09895         if(xodtemplate_sort_serviceescalations()==ERROR)
09896                 return ERROR;
09897 
09898         /* sort host dependencies */
09899         if(xodtemplate_sort_hostdependencies()==ERROR)
09900                 return ERROR;
09901 
09902         /* sort hostescalations */
09903         if(xodtemplate_sort_hostescalations()==ERROR)
09904                 return ERROR;
09905 
09906         /* sort modules */
09907         if(xodtemplate_sort_modules()==ERROR)
09908                 return ERROR;
09909 
09910         /* sort host extended info */
09911         /* NOT NEEDED */
09912 
09913         /* sort service extended info */
09914         /* NOT NEEDED */
09915 
09916         return OK;
09917         }
09918 
09919 
09920 /* used to compare two strings (object names) */
09921 int xodtemplate_compare_strings1(char *string1, char *string2){
09922         
09923         if(string1==NULL && string2==NULL)
09924                 return 0;
09925         else if(string1==NULL)
09926                 return -1;
09927         else if(string2==NULL)
09928                 return 1;
09929         else
09930                 return strcmp(string1,string2);
09931         }
09932 
09933 
09934 /* used to compare two sets of strings (dually-named objects, i.e. services) */
09935 int xodtemplate_compare_strings2(char *string1a, char *string1b, char *string2a, char *string2b){
09936         int result;
09937 
09938         if((result=xodtemplate_compare_strings1(string1a,string2a))==0)
09939                 result=xodtemplate_compare_strings1(string1b,string2b);
09940 
09941         return result;
09942         }
09943 
09944 
09945 /* sort timeperiods by name */
09946 int xodtemplate_sort_timeperiods(){
09947         xodtemplate_timeperiod *new_timeperiod_list=NULL;
09948         xodtemplate_timeperiod *temp_timeperiod=NULL;
09949         xodtemplate_timeperiod *last_timeperiod=NULL;
09950         xodtemplate_timeperiod *temp_timeperiod_orig=NULL;
09951         xodtemplate_timeperiod *next_timeperiod_orig=NULL;
09952 
09953         /* sort all existing timeperiods */
09954         for(temp_timeperiod_orig=xodtemplate_timeperiod_list;temp_timeperiod_orig!=NULL;temp_timeperiod_orig=next_timeperiod_orig){
09955 
09956                 next_timeperiod_orig=temp_timeperiod_orig->next;
09957 
09958                 /* add timeperiod to new list, sorted by timeperiod name */
09959                 last_timeperiod=new_timeperiod_list;
09960                 for(temp_timeperiod=new_timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){
09961 
09962                         if(xodtemplate_compare_strings1(temp_timeperiod_orig->timeperiod_name,temp_timeperiod->timeperiod_name)<=0)
09963                                 break;
09964                         else
09965                                 last_timeperiod=temp_timeperiod;
09966                         }
09967 
09968                 /* first item added to new sorted list */
09969                 if(new_timeperiod_list==NULL){
09970                         temp_timeperiod_orig->next=NULL;
09971                         new_timeperiod_list=temp_timeperiod_orig;
09972                         }
09973 
09974                 /* item goes at head of new sorted list */
09975                 else if(temp_timeperiod==new_timeperiod_list){
09976                         temp_timeperiod_orig->next=new_timeperiod_list;
09977                         new_timeperiod_list=temp_timeperiod_orig;
09978                         }
09979 
09980                 /* item goes in middle or at end of new sorted list */
09981                 else{
09982                         temp_timeperiod_orig->next=temp_timeperiod;
09983                         last_timeperiod->next=temp_timeperiod_orig;
09984                         }
09985                 }
09986 
09987         /* list is now sorted */
09988         xodtemplate_timeperiod_list=new_timeperiod_list;
09989 
09990         return OK;
09991         }
09992 
09993 
09994 /* sort commands by name */
09995 int xodtemplate_sort_commands(){
09996         xodtemplate_command *new_command_list=NULL;
09997         xodtemplate_command *temp_command=NULL;
09998         xodtemplate_command *last_command=NULL;
09999         xodtemplate_command *temp_command_orig=NULL;
10000         xodtemplate_command *next_command_orig=NULL;
10001 
10002         /* sort all existing commands */
10003         for(temp_command_orig=xodtemplate_command_list;temp_command_orig!=NULL;temp_command_orig=next_command_orig){
10004 
10005                 next_command_orig=temp_command_orig->next;
10006 
10007                 /* add command to new list, sorted by command name */
10008                 last_command=new_command_list;
10009                 for(temp_command=new_command_list;temp_command!=NULL;temp_command=temp_command->next){
10010 
10011                         if(xodtemplate_compare_strings1(temp_command_orig->command_name,temp_command->command_name)<=0)
10012                                 break;
10013                         else
10014                                 last_command=temp_command;
10015                         }
10016 
10017                 /* first item added to new sorted list */
10018                 if(new_command_list==NULL){
10019                         temp_command_orig->next=NULL;
10020                         new_command_list=temp_command_orig;
10021                         }
10022 
10023                 /* item goes at head of new sorted list */
10024                 else if(temp_command==new_command_list){
10025                         temp_command_orig->next=new_command_list;
10026                         new_command_list=temp_command_orig;
10027                         }
10028 
10029                 /* item goes in middle or at end of new sorted list */
10030                 else{
10031                         temp_command_orig->next=temp_command;
10032                         last_command->next=temp_command_orig;
10033                         }
10034                 }
10035 
10036         /* list is now sorted */
10037         xodtemplate_command_list=new_command_list;
10038 
10039         return OK;
10040         }
10041 
10042 
10043 /* sort contactgroups by name */
10044 int xodtemplate_sort_contactgroups(){
10045         xodtemplate_contactgroup *new_contactgroup_list=NULL;
10046         xodtemplate_contactgroup *temp_contactgroup=NULL;
10047         xodtemplate_contactgroup *last_contactgroup=NULL;
10048         xodtemplate_contactgroup *temp_contactgroup_orig=NULL;
10049         xodtemplate_contactgroup *next_contactgroup_orig=NULL;
10050 
10051         /* sort all existing contactgroups */
10052         for(temp_contactgroup_orig=xodtemplate_contactgroup_list;temp_contactgroup_orig!=NULL;temp_contactgroup_orig=next_contactgroup_orig){
10053 
10054                 next_contactgroup_orig=temp_contactgroup_orig->next;
10055 
10056                 /* add contactgroup to new list, sorted by contactgroup name */
10057                 last_contactgroup=new_contactgroup_list;
10058                 for(temp_contactgroup=new_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
10059 
10060                         if(xodtemplate_compare_strings1(temp_contactgroup_orig->contactgroup_name,temp_contactgroup->contactgroup_name)<=0)
10061                                 break;
10062                         else
10063                                 last_contactgroup=temp_contactgroup;
10064                         }
10065 
10066                 /* first item added to new sorted list */
10067                 if(new_contactgroup_list==NULL){
10068                         temp_contactgroup_orig->next=NULL;
10069                         new_contactgroup_list=temp_contactgroup_orig;
10070                         }
10071 
10072                 /* item goes at head of new sorted list */
10073                 else if(temp_contactgroup==new_contactgroup_list){
10074                         temp_contactgroup_orig->next=new_contactgroup_list;
10075                         new_contactgroup_list=temp_contactgroup_orig;
10076                         }
10077 
10078                 /* item goes in middle or at end of new sorted list */
10079                 else{
10080                         temp_contactgroup_orig->next=temp_contactgroup;
10081                         last_contactgroup->next=temp_contactgroup_orig;
10082                         }
10083                 }
10084 
10085         /* list is now sorted */
10086         xodtemplate_contactgroup_list=new_contactgroup_list;
10087 
10088         return OK;
10089         }
10090 
10091 
10092 /* sort hostgroups by name */
10093 int xodtemplate_sort_hostgroups(){
10094         xodtemplate_hostgroup *new_hostgroup_list=NULL;
10095         xodtemplate_hostgroup *temp_hostgroup=NULL;
10096         xodtemplate_hostgroup *last_hostgroup=NULL;
10097         xodtemplate_hostgroup *temp_hostgroup_orig=NULL;
10098         xodtemplate_hostgroup *next_hostgroup_orig=NULL;
10099 
10100         /* sort all existing hostgroups */
10101         for(temp_hostgroup_orig=xodtemplate_hostgroup_list;temp_hostgroup_orig!=NULL;temp_hostgroup_orig=next_hostgroup_orig){
10102 
10103                 next_hostgroup_orig=temp_hostgroup_orig->next;
10104 
10105                 /* add hostgroup to new list, sorted by hostgroup name */
10106                 last_hostgroup=new_hostgroup_list;
10107                 for(temp_hostgroup=new_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
10108 
10109                         if(xodtemplate_compare_strings1(temp_hostgroup_orig->hostgroup_name,temp_hostgroup->hostgroup_name)<=0)
10110                                 break;
10111                         else
10112                                 last_hostgroup=temp_hostgroup;
10113                         }
10114 
10115                 /* first item added to new sorted list */
10116                 if(new_hostgroup_list==NULL){
10117                         temp_hostgroup_orig->next=NULL;
10118                         new_hostgroup_list=temp_hostgroup_orig;
10119                         }
10120 
10121                 /* item goes at head of new sorted list */
10122                 else if(temp_hostgroup==new_hostgroup_list){
10123                         temp_hostgroup_orig->next=new_hostgroup_list;
10124                         new_hostgroup_list=temp_hostgroup_orig;
10125                         }
10126 
10127                 /* item goes in middle or at end of new sorted list */
10128                 else{
10129                         temp_hostgroup_orig->next=temp_hostgroup;
10130                         last_hostgroup->next=temp_hostgroup_orig;
10131                         }
10132                 }
10133 
10134         /* list is now sorted */
10135         xodtemplate_hostgroup_list=new_hostgroup_list;
10136 
10137         return OK;
10138         }
10139 
10140 
10141 /* sort servicegroups by name */
10142 int xodtemplate_sort_servicegroups(){
10143         xodtemplate_servicegroup *new_servicegroup_list=NULL;
10144         xodtemplate_servicegroup *temp_servicegroup=NULL;
10145         xodtemplate_servicegroup *last_servicegroup=NULL;
10146         xodtemplate_servicegroup *temp_servicegroup_orig=NULL;
10147         xodtemplate_servicegroup *next_servicegroup_orig=NULL;
10148 
10149         /* sort all existing servicegroups */
10150         for(temp_servicegroup_orig=xodtemplate_servicegroup_list;temp_servicegroup_orig!=NULL;temp_servicegroup_orig=next_servicegroup_orig){
10151 
10152                 next_servicegroup_orig=temp_servicegroup_orig->next;
10153 
10154                 /* add servicegroup to new list, sorted by servicegroup name */
10155                 last_servicegroup=new_servicegroup_list;
10156                 for(temp_servicegroup=new_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
10157 
10158                         if(xodtemplate_compare_strings1(temp_servicegroup_orig->servicegroup_name,temp_servicegroup->servicegroup_name)<=0)
10159                                 break;
10160                         else
10161                                 last_servicegroup=temp_servicegroup;
10162                         }
10163 
10164                 /* first item added to new sorted list */
10165                 if(new_servicegroup_list==NULL){
10166                         temp_servicegroup_orig->next=NULL;
10167                         new_servicegroup_list=temp_servicegroup_orig;
10168                         }
10169 
10170                 /* item goes at head of new sorted list */
10171                 else if(temp_servicegroup==new_servicegroup_list){
10172                         temp_servicegroup_orig->next=new_servicegroup_list;
10173                         new_servicegroup_list=temp_servicegroup_orig;
10174                         }
10175 
10176                 /* item goes in middle or at end of new sorted list */
10177                 else{
10178                         temp_servicegroup_orig->next=temp_servicegroup;
10179                         last_servicegroup->next=temp_servicegroup_orig;
10180                         }
10181                 }
10182 
10183         /* list is now sorted */
10184         xodtemplate_servicegroup_list=new_servicegroup_list;
10185 
10186         return OK;
10187         }
10188 
10189 
10190 /* sort contacts by name */
10191 int xodtemplate_sort_contacts(){
10192         xodtemplate_contact *new_contact_list=NULL;
10193         xodtemplate_contact *temp_contact=NULL;
10194         xodtemplate_contact *last_contact=NULL;
10195         xodtemplate_contact *temp_contact_orig=NULL;
10196         xodtemplate_contact *next_contact_orig=NULL;
10197 
10198         /* sort all existing contacts */
10199         for(temp_contact_orig=xodtemplate_contact_list;temp_contact_orig!=NULL;temp_contact_orig=next_contact_orig){
10200 
10201                 next_contact_orig=temp_contact_orig->next;
10202 
10203                 /* add contact to new list, sorted by contact name */
10204                 last_contact=new_contact_list;
10205                 for(temp_contact=new_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
10206 
10207                         if(xodtemplate_compare_strings1(temp_contact_orig->contact_name,temp_contact->contact_name)<=0)
10208                                 break;
10209                         else
10210                                 last_contact=temp_contact;
10211                         }
10212 
10213                 /* first item added to new sorted list */
10214                 if(new_contact_list==NULL){
10215                         temp_contact_orig->next=NULL;
10216                         new_contact_list=temp_contact_orig;
10217                         }
10218 
10219                 /* item goes at head of new sorted list */
10220                 else if(temp_contact==new_contact_list){
10221                         temp_contact_orig->next=new_contact_list;
10222                         new_contact_list=temp_contact_orig;
10223                         }
10224 
10225                 /* item goes in middle or at end of new sorted list */
10226                 else{
10227                         temp_contact_orig->next=temp_contact;
10228                         last_contact->next=temp_contact_orig;
10229                         }
10230                 }
10231 
10232         /* list is now sorted */
10233         xodtemplate_contact_list=new_contact_list;
10234 
10235         return OK;
10236         }
10237 
10238 
10239 int xodtemplate_compare_host(void *arg1, void *arg2){
10240         xodtemplate_host *h1=NULL;
10241         xodtemplate_host *h2=NULL;
10242         int x=0;
10243 
10244         h1=(xodtemplate_host *)arg1;
10245         h2=(xodtemplate_host *)arg2;
10246 
10247         if(h1==NULL && h2==NULL)
10248                 return 0;
10249         if(h1==NULL)
10250                 return 1;
10251         if(h2==NULL)
10252                 return -1;
10253 
10254         x=strcmp((h1->host_name==NULL)?"":h1->host_name,(h2->host_name==NULL)?"":h2->host_name);
10255 
10256         return x;
10257         }
10258 
10259 
10260 
10261 /* sort hosts by name */
10262 int xodtemplate_sort_hosts(){
10263 #ifdef NEWSTUFF
10264         xodtemplate_host *temp_host=NULL;
10265         
10266         /* initialize a new skip list */
10267         if((xodtemplate_host_skiplist=skiplist_new(15,0.5,FALSE,xodtemplate_compare_host))==NULL)
10268                 return ERROR;
10269 
10270         /* add all hosts to skip list */
10271         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next)
10272                 skiplist_insert(xodtemplate_host_skiplist,temp_host);
10273         /*printf("SKIPLIST ITEMS: %lu\n",xodtemplate_host_skiplist->items);*/
10274 
10275         /* now move items from skiplist to linked list... */
10276         /* TODO */
10277 #endif
10278 
10279         xodtemplate_host *new_host_list=NULL;
10280         xodtemplate_host *temp_host=NULL;
10281         xodtemplate_host *last_host=NULL;
10282         xodtemplate_host *temp_host_orig=NULL;
10283         xodtemplate_host *next_host_orig=NULL;
10284 
10285         /* sort all existing hosts */
10286         for(temp_host_orig=xodtemplate_host_list;temp_host_orig!=NULL;temp_host_orig=next_host_orig){
10287 
10288                 next_host_orig=temp_host_orig->next;
10289 
10290                 /* add host to new list, sorted by host name */
10291                 last_host=new_host_list;
10292                 for(temp_host=new_host_list;temp_host!=NULL;temp_host=temp_host->next){
10293 
10294                         if(xodtemplate_compare_strings1(temp_host_orig->host_name,temp_host->host_name)<=0)
10295                                 break;
10296                         else
10297                                 last_host=temp_host;
10298                         }
10299 
10300                 /* first item added to new sorted list */
10301                 if(new_host_list==NULL){
10302                         temp_host_orig->next=NULL;
10303                         new_host_list=temp_host_orig;
10304                         }
10305 
10306                 /* item goes at head of new sorted list */
10307                 else if(temp_host==new_host_list){
10308                         temp_host_orig->next=new_host_list;
10309                         new_host_list=temp_host_orig;
10310                         }
10311 
10312                 /* item goes in middle or at end of new sorted list */
10313                 else{
10314                         temp_host_orig->next=temp_host;
10315                         last_host->next=temp_host_orig;
10316                         }
10317                 }
10318 
10319         /* list is now sorted */
10320         xodtemplate_host_list=new_host_list;
10321 
10322         return OK;
10323         }
10324 
10325 
10326 int xodtemplate_compare_service(void *arg1, void *arg2){
10327         xodtemplate_service *s1=NULL;
10328         xodtemplate_service *s2=NULL;
10329         int x=0;
10330 
10331         s1=(xodtemplate_service *)arg1;
10332         s2=(xodtemplate_service *)arg2;
10333 
10334         if(s1==NULL && s2==NULL)
10335                 return 0;
10336         if(s1==NULL)
10337                 return 1;
10338         if(s2==NULL)
10339                 return -1;
10340 
10341         x=strcmp((s1->host_name==NULL)?"":s1->host_name,(s2->host_name==NULL)?"":s2->host_name);
10342         if(x==0)
10343                 x=strcmp((s1->service_description==NULL)?"":s1->service_description,(s2->service_description==NULL)?"":s2->service_description);
10344 
10345         return x;
10346         }
10347 
10348 
10349 /* sort services by name */
10350 int xodtemplate_sort_services(){
10351 #ifdef NEWSTUFF
10352         xodtemplate_service *temp_service=NULL;
10353         
10354         /* initialize a new skip list */
10355         if((xodtemplate_service_skiplist=skiplist_new(15,0.5,FALSE,xodtemplate_compare_service))==NULL)
10356                 return ERROR;
10357 
10358         /* add all services to skip list */
10359         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next)
10360                 skiplist_insert(xodtemplate_service_skiplist,temp_service);
10361         /*printf("SKIPLIST ITEMS: %lu\n",xodtemplate_service_skiplist->items);*/
10362 
10363         /* now move items to linked list... */
10364         /* TODO */
10365 #endif
10366 
10367         xodtemplate_service *new_service_list=NULL;
10368         xodtemplate_service *temp_service=NULL;
10369         xodtemplate_service *last_service=NULL;
10370         xodtemplate_service *temp_service_orig=NULL;
10371         xodtemplate_service *next_service_orig=NULL;
10372 
10373         /* sort all existing services */
10374         for(temp_service_orig=xodtemplate_service_list;temp_service_orig!=NULL;temp_service_orig=next_service_orig){
10375 
10376                 next_service_orig=temp_service_orig->next;
10377 
10378                 /* add service to new list, sorted by host name then service description */
10379                 last_service=new_service_list;
10380                 for(temp_service=new_service_list;temp_service!=NULL;temp_service=temp_service->next){
10381 
10382                         if(xodtemplate_compare_strings2(temp_service_orig->host_name,temp_service_orig->service_description,temp_service->host_name,temp_service->service_description)<=0)
10383                                 break;
10384                         else
10385                                 last_service=temp_service;
10386                         }
10387 
10388                 /* first item added to new sorted list */
10389                 if(new_service_list==NULL){
10390                         temp_service_orig->next=NULL;
10391                         new_service_list=temp_service_orig;
10392                         }
10393 
10394                 /* item goes at head of new sorted list */
10395                 else if(temp_service==new_service_list){
10396                         temp_service_orig->next=new_service_list;
10397                         new_service_list=temp_service_orig;
10398                         }
10399 
10400                 /* item goes in middle or at end of new sorted list */
10401                 else{
10402                         temp_service_orig->next=temp_service;
10403                         last_service->next=temp_service_orig;
10404                         }
10405                 }
10406 
10407         /* list is now sorted */
10408         xodtemplate_service_list=new_service_list;
10409 
10410         return OK;
10411         }
10412 
10413 
10414 /* sort servicedependencies by name */
10415 int xodtemplate_sort_servicedependencies(){
10416         xodtemplate_servicedependency *new_servicedependency_list=NULL;
10417         xodtemplate_servicedependency *temp_servicedependency=NULL;
10418         xodtemplate_servicedependency *last_servicedependency=NULL;
10419         xodtemplate_servicedependency *temp_servicedependency_orig=NULL;
10420         xodtemplate_servicedependency *next_servicedependency_orig=NULL;
10421 
10422         /* sort all existing servicedependencies */
10423         for(temp_servicedependency_orig=xodtemplate_servicedependency_list;temp_servicedependency_orig!=NULL;temp_servicedependency_orig=next_servicedependency_orig){
10424 
10425                 next_servicedependency_orig=temp_servicedependency_orig->next;
10426 
10427                 /* add servicedependency to new list, sorted by host name then service description */
10428                 last_servicedependency=new_servicedependency_list;
10429                 for(temp_servicedependency=new_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
10430 
10431                         if(xodtemplate_compare_strings2(temp_servicedependency_orig->host_name,temp_servicedependency_orig->service_description,temp_servicedependency->host_name,temp_servicedependency->service_description)<=0)
10432                                 break;
10433                         else
10434                                 last_servicedependency=temp_servicedependency;
10435                         }
10436 
10437                 /* first item added to new sorted list */
10438                 if(new_servicedependency_list==NULL){
10439                         temp_servicedependency_orig->next=NULL;
10440                         new_servicedependency_list=temp_servicedependency_orig;
10441                         }
10442 
10443                 /* item goes at head of new sorted list */
10444                 else if(temp_servicedependency==new_servicedependency_list){
10445                         temp_servicedependency_orig->next=new_servicedependency_list;
10446                         new_servicedependency_list=temp_servicedependency_orig;
10447                         }
10448 
10449                 /* item goes in middle or at end of new sorted list */
10450                 else{
10451                         temp_servicedependency_orig->next=temp_servicedependency;
10452                         last_servicedependency->next=temp_servicedependency_orig;
10453                         }
10454                 }
10455 
10456         /* list is now sorted */
10457         xodtemplate_servicedependency_list=new_servicedependency_list;
10458 
10459         return OK;
10460         }
10461 
10462 
10463 /* sort serviceescalations by name */
10464 int xodtemplate_sort_serviceescalations(){
10465         xodtemplate_serviceescalation *new_serviceescalation_list=NULL;
10466         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
10467         xodtemplate_serviceescalation *last_serviceescalation=NULL;
10468         xodtemplate_serviceescalation *temp_serviceescalation_orig=NULL;
10469         xodtemplate_serviceescalation *next_serviceescalation_orig=NULL;
10470 
10471         /* sort all existing serviceescalations */
10472         for(temp_serviceescalation_orig=xodtemplate_serviceescalation_list;temp_serviceescalation_orig!=NULL;temp_serviceescalation_orig=next_serviceescalation_orig){
10473 
10474                 next_serviceescalation_orig=temp_serviceescalation_orig->next;
10475 
10476                 /* add serviceescalation to new list, sorted by host name then service description */
10477                 last_serviceescalation=new_serviceescalation_list;
10478                 for(temp_serviceescalation=new_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
10479 
10480                         if(xodtemplate_compare_strings2(temp_serviceescalation_orig->host_name,temp_serviceescalation_orig->service_description,temp_serviceescalation->host_name,temp_serviceescalation->service_description)<=0)
10481                                 break;
10482                         else
10483                                 last_serviceescalation=temp_serviceescalation;
10484                         }
10485 
10486                 /* first item added to new sorted list */
10487                 if(new_serviceescalation_list==NULL){
10488                         temp_serviceescalation_orig->next=NULL;
10489                         new_serviceescalation_list=temp_serviceescalation_orig;
10490                         }
10491 
10492                 /* item goes at head of new sorted list */
10493                 else if(temp_serviceescalation==new_serviceescalation_list){
10494                         temp_serviceescalation_orig->next=new_serviceescalation_list;
10495                         new_serviceescalation_list=temp_serviceescalation_orig;
10496                         }
10497 
10498                 /* item goes in middle or at end of new sorted list */
10499                 else{
10500                         temp_serviceescalation_orig->next=temp_serviceescalation;
10501                         last_serviceescalation->next=temp_serviceescalation_orig;
10502                         }
10503                 }
10504 
10505         /* list is now sorted */
10506         xodtemplate_serviceescalation_list=new_serviceescalation_list;
10507 
10508         return OK;
10509         }
10510 
10511 
10512 /* sort hostescalations by name */
10513 int xodtemplate_sort_hostescalations(){
10514         xodtemplate_hostescalation *new_hostescalation_list=NULL;
10515         xodtemplate_hostescalation *temp_hostescalation=NULL;
10516         xodtemplate_hostescalation *last_hostescalation=NULL;
10517         xodtemplate_hostescalation *temp_hostescalation_orig=NULL;
10518         xodtemplate_hostescalation *next_hostescalation_orig=NULL;
10519 
10520         /* sort all existing hostescalations */
10521         for(temp_hostescalation_orig=xodtemplate_hostescalation_list;temp_hostescalation_orig!=NULL;temp_hostescalation_orig=next_hostescalation_orig){
10522 
10523                 next_hostescalation_orig=temp_hostescalation_orig->next;
10524 
10525                 /* add hostescalation to new list, sorted by host name then hostescalation description */
10526                 last_hostescalation=new_hostescalation_list;
10527                 for(temp_hostescalation=new_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
10528 
10529                         if(xodtemplate_compare_strings1(temp_hostescalation_orig->host_name,temp_hostescalation->host_name)<=0)
10530                                 break;
10531                         else
10532                                 last_hostescalation=temp_hostescalation;
10533                         }
10534 
10535                 /* first item added to new sorted list */
10536                 if(new_hostescalation_list==NULL){
10537                         temp_hostescalation_orig->next=NULL;
10538                         new_hostescalation_list=temp_hostescalation_orig;
10539                         }
10540 
10541                 /* item goes at head of new sorted list */
10542                 else if(temp_hostescalation==new_hostescalation_list){
10543                         temp_hostescalation_orig->next=new_hostescalation_list;
10544                         new_hostescalation_list=temp_hostescalation_orig;
10545                         }
10546 
10547                 /* item goes in middle or at end of new sorted list */
10548                 else{
10549                         temp_hostescalation_orig->next=temp_hostescalation;
10550                         last_hostescalation->next=temp_hostescalation_orig;
10551                         }
10552                 }
10553 
10554         /* list is now sorted */
10555         xodtemplate_hostescalation_list=new_hostescalation_list;
10556 
10557         return OK;
10558         }
10559 
10560 
10561 /* sort hostdependencies by name */
10562 int xodtemplate_sort_hostdependencies(){
10563         xodtemplate_hostdependency *new_hostdependency_list=NULL;
10564         xodtemplate_hostdependency *temp_hostdependency=NULL;
10565         xodtemplate_hostdependency *last_hostdependency=NULL;
10566         xodtemplate_hostdependency *temp_hostdependency_orig=NULL;
10567         xodtemplate_hostdependency *next_hostdependency_orig=NULL;
10568 
10569         /* sort all existing hostdependencys */
10570         for(temp_hostdependency_orig=xodtemplate_hostdependency_list;temp_hostdependency_orig!=NULL;temp_hostdependency_orig=next_hostdependency_orig){
10571 
10572                 next_hostdependency_orig=temp_hostdependency_orig->next;
10573 
10574                 /* add hostdependency to new list, sorted by host name then hostdependency description */
10575                 last_hostdependency=new_hostdependency_list;
10576                 for(temp_hostdependency=new_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
10577 
10578                         if(xodtemplate_compare_strings1(temp_hostdependency_orig->host_name,temp_hostdependency->host_name)<=0)
10579                                 break;
10580                         else
10581                                 last_hostdependency=temp_hostdependency;
10582                         }
10583 
10584                 /* first item added to new sorted list */
10585                 if(new_hostdependency_list==NULL){
10586                         temp_hostdependency_orig->next=NULL;
10587                         new_hostdependency_list=temp_hostdependency_orig;
10588                         }
10589 
10590                 /* item goes at head of new sorted list */
10591                 else if(temp_hostdependency==new_hostdependency_list){
10592                         temp_hostdependency_orig->next=new_hostdependency_list;
10593                         new_hostdependency_list=temp_hostdependency_orig;
10594                         }
10595 
10596                 /* item goes in middle or at end of new sorted list */
10597                 else{
10598                         temp_hostdependency_orig->next=temp_hostdependency;
10599                         last_hostdependency->next=temp_hostdependency_orig;
10600                         }
10601                 }
10602 
10603         /* list is now sorted */
10604         xodtemplate_hostdependency_list=new_hostdependency_list;
10605 
10606         return OK;
10607         }
10608 
10609 
10610 /* sort modules by name */
10611 int xodtemplate_sort_modules(){
10612         xodtemplate_module *new_module_list=NULL;
10613         xodtemplate_module *temp_module=NULL;
10614         xodtemplate_module *last_module=NULL;
10615         xodtemplate_module *temp_module_orig=NULL;
10616         xodtemplate_module *next_module_orig=NULL;
10617 
10618         /* sort all existing modules */
10619         for(temp_module_orig=xodtemplate_module_list;temp_module_orig!=NULL;temp_module_orig=next_module_orig){
10620 
10621                 next_module_orig=temp_module_orig->next;
10622 
10623                 /* add module to new list, sorted by module name */
10624                 last_module=new_module_list;
10625                 for(temp_module=new_module_list;temp_module!=NULL;temp_module=temp_module->next){
10626 
10627                         if(xodtemplate_compare_strings1(temp_module_orig->module_name,temp_module->module_name)<=0)
10628                                 break;
10629                         else
10630                                 last_module=temp_module;
10631                         }
10632 
10633                 /* first item added to new sorted list */
10634                 if(new_module_list==NULL){
10635                         temp_module_orig->next=NULL;
10636                         new_module_list=temp_module_orig;
10637                         }
10638 
10639                 /* item goes at head of new sorted list */
10640                 else if(temp_module==new_module_list){
10641                         temp_module_orig->next=new_module_list;
10642                         new_module_list=temp_module_orig;
10643                         }
10644 
10645                 /* item goes in middle or at end of new sorted list */
10646                 else{
10647                         temp_module_orig->next=temp_module;
10648                         last_module->next=temp_module_orig;
10649                         }
10650                 }
10651 
10652         /* list is now sorted */
10653         xodtemplate_module_list=new_module_list;
10654 
10655         return OK;
10656         }
10657 
10658 
10659 #endif
10660 
10661 
10662 
10663 
10664 /******************************************************************/
10665 /*********************** MERGE FUNCTIONS **************************/
10666 /******************************************************************/
10667 
10668 #ifdef NSCORE
10669 
10670 /* merge extinfo definitions */
10671 int xodtemplate_merge_extinfo_ojects(void){
10672         xodtemplate_hostextinfo *temp_hostextinfo=NULL;
10673         xodtemplate_serviceextinfo *temp_serviceextinfo=NULL;
10674         xodtemplate_host *temp_host=NULL;
10675         xodtemplate_service *temp_service=NULL;
10676 
10677         /* merge service extinfo definitions */
10678         for(temp_serviceextinfo=xodtemplate_serviceextinfo_list;temp_serviceextinfo!=NULL;temp_serviceextinfo=temp_serviceextinfo->next){
10679 
10680                 /* make sure we have everything */
10681                 if(temp_serviceextinfo->host_name==NULL || temp_serviceextinfo->service_description==NULL)
10682                         continue;
10683 
10684                 /* find the service */
10685                 if((temp_service=xodtemplate_find_real_service(temp_serviceextinfo->host_name,temp_serviceextinfo->service_description))==NULL)
10686                         continue;
10687 
10688                 /* merge the definitions */
10689                 xodtemplate_merge_service_extinfo_object(temp_service,temp_serviceextinfo);
10690                 }
10691 
10692         /* merge host extinfo definitions */
10693         for(temp_hostextinfo=xodtemplate_hostextinfo_list;temp_hostextinfo!=NULL;temp_hostextinfo=temp_hostextinfo->next){
10694 
10695                 /* make sure we have everything */
10696                 if(temp_hostextinfo->host_name==NULL)
10697                         continue;
10698 
10699                 /* find the host */
10700                 if((temp_host=xodtemplate_find_real_host(temp_hostextinfo->host_name))==NULL)
10701                         continue;
10702 
10703                 /* merge the definitions */
10704                 xodtemplate_merge_host_extinfo_object(temp_host,temp_hostextinfo);
10705                 }
10706 
10707         return OK;
10708         }
10709 
10710 
10711 /* merges a service extinfo definition */
10712 int xodtemplate_merge_service_extinfo_object(xodtemplate_service *this_service, xodtemplate_serviceextinfo *this_serviceextinfo){
10713 
10714         if(this_service==NULL || this_serviceextinfo==NULL)
10715                 return ERROR;
10716 
10717         if(this_service->notes==NULL && this_serviceextinfo->notes!=NULL)
10718                 this_service->notes=strdup(this_serviceextinfo->notes);
10719         if(this_service->notes_url==NULL && this_serviceextinfo->notes_url!=NULL)
10720                 this_service->notes_url=strdup(this_serviceextinfo->notes_url);
10721         if(this_service->action_url==NULL && this_serviceextinfo->action_url!=NULL)
10722                 this_service->action_url=strdup(this_serviceextinfo->action_url);
10723         if(this_service->icon_image==NULL && this_serviceextinfo->icon_image!=NULL)
10724                 this_service->icon_image=strdup(this_serviceextinfo->icon_image);
10725         if(this_service->icon_image_alt==NULL && this_serviceextinfo->icon_image_alt!=NULL)
10726                 this_service->icon_image_alt=strdup(this_serviceextinfo->icon_image_alt);
10727 
10728         return OK;
10729         }
10730 
10731 
10732 /* merges a host extinfo definition */
10733 int xodtemplate_merge_host_extinfo_object(xodtemplate_host *this_host, xodtemplate_hostextinfo *this_hostextinfo){
10734 
10735         if(this_host==NULL || this_hostextinfo==NULL)
10736                 return ERROR;
10737 
10738         if(this_host->notes==NULL && this_hostextinfo->notes!=NULL)
10739                 this_host->notes=strdup(this_hostextinfo->notes);
10740         if(this_host->notes_url==NULL && this_hostextinfo->notes_url!=NULL)
10741                 this_host->notes_url=strdup(this_hostextinfo->notes_url);
10742         if(this_host->action_url==NULL && this_hostextinfo->action_url!=NULL)
10743                 this_host->action_url=strdup(this_hostextinfo->action_url);
10744         if(this_host->icon_image==NULL && this_hostextinfo->icon_image!=NULL)
10745                 this_host->icon_image=strdup(this_hostextinfo->icon_image);
10746         if(this_host->icon_image_alt==NULL && this_hostextinfo->icon_image_alt!=NULL)
10747                 this_host->icon_image_alt=strdup(this_hostextinfo->icon_image_alt);
10748         if(this_host->vrml_image==NULL && this_hostextinfo->vrml_image!=NULL)
10749                 this_host->vrml_image=strdup(this_hostextinfo->vrml_image);
10750         if(this_host->statusmap_image==NULL && this_hostextinfo->statusmap_image!=NULL)
10751                 this_host->statusmap_image=strdup(this_hostextinfo->statusmap_image);
10752 
10753         if(this_host->have_2d_coords==FALSE && this_hostextinfo->have_2d_coords==TRUE){
10754                 this_host->x_2d=this_hostextinfo->x_2d;
10755                 this_host->y_2d=this_hostextinfo->y_2d;
10756                 this_host->have_2d_coords=TRUE;
10757                 }
10758         if(this_host->have_3d_coords==FALSE && this_hostextinfo->have_3d_coords==TRUE){
10759                 this_host->x_3d=this_hostextinfo->x_3d;
10760                 this_host->y_3d=this_hostextinfo->y_3d;
10761                 this_host->z_3d=this_hostextinfo->z_3d;
10762                 this_host->have_3d_coords=TRUE;
10763                 }
10764 
10765         return OK;
10766         }
10767 
10768 #endif
10769 
10770 
10771 
10772 /******************************************************************/
10773 /*********************** CACHE FUNCTIONS **************************/
10774 /******************************************************************/
10775 
10776 #ifdef NSCORE
10777 
10778 /* writes cached object definitions for use by web interface */
10779 int xodtemplate_cache_objects(char *cache_file){
10780         FILE *fp=NULL;
10781         register int x=0;
10782         char *days[7]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
10783         char *months[12]={"january","february","march","april","may","june","july","august","september","october","november","december"};
10784         xodtemplate_timeperiod *temp_timeperiod=NULL;
10785         xodtemplate_daterange *temp_daterange=NULL;
10786         xodtemplate_command *temp_command=NULL;
10787         xodtemplate_contactgroup *temp_contactgroup=NULL;
10788         xodtemplate_hostgroup *temp_hostgroup=NULL;
10789         xodtemplate_servicegroup *temp_servicegroup=NULL;
10790         xodtemplate_contact *temp_contact=NULL;
10791         xodtemplate_host *temp_host=NULL;
10792         xodtemplate_service *temp_service=NULL;
10793         xodtemplate_servicedependency *temp_servicedependency=NULL;
10794         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
10795         xodtemplate_hostdependency *temp_hostdependency=NULL;
10796         xodtemplate_hostescalation *temp_hostescalation=NULL;
10797         xodtemplate_customvariablesmember *temp_customvariablesmember=NULL;
10798         xodtemplate_module *temp_module=NULL;
10799         time_t current_time=0L;
10800         void *ptr=NULL;
10801 
10802 
10803         time(&current_time);
10804 
10805         /* open the cache file for writing */
10806         fp=fopen(cache_file,"w");
10807         if(fp==NULL){
10808                 logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Could not open object cache file '%s' for writing!\n",cache_file);
10809                 return ERROR;
10810                 }
10811 
10812         /* write header to cache file */
10813         fprintf(fp,"########################################\n");
10814         fprintf(fp,"#       %s OBJECT CACHE FILE\n", PROGRAM_NAME_UC);
10815         fprintf(fp,"#\n");
10816         fprintf(fp,"# THIS FILE IS AUTOMATICALLY GENERATED\n");
10817         fprintf(fp,"# BY %s.  DO NOT MODIFY THIS FILE!\n", PROGRAM_NAME_UC);
10818         fprintf(fp,"#\n");
10819         fprintf(fp,"# Created: %s",ctime(&current_time));
10820         fprintf(fp,"########################################\n\n");
10821 
10822 
10823         /* cache timeperiods */
10824         /*for(temp_timeperiod=xodtemplate_timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){*/
10825         ptr=NULL;
10826         for(temp_timeperiod=(xodtemplate_timeperiod *)skiplist_get_first(xobject_skiplists[X_TIMEPERIOD_SKIPLIST],&ptr);temp_timeperiod!=NULL;temp_timeperiod=(xodtemplate_timeperiod *)skiplist_get_next(&ptr)){
10827 
10828                 if(temp_timeperiod->register_object==FALSE)
10829                         continue;
10830                 fprintf(fp,"define timeperiod {\n");
10831                 if(temp_timeperiod->timeperiod_name)
10832                         fprintf(fp,"\ttimeperiod_name\t%s\n",temp_timeperiod->timeperiod_name);
10833                 if(temp_timeperiod->alias)
10834                         fprintf(fp,"\talias\t%s\n",temp_timeperiod->alias);
10835                 for(x=0;x<DATERANGE_TYPES;x++){
10836                         for(temp_daterange=temp_timeperiod->exceptions[x];temp_daterange!=NULL;temp_daterange=temp_daterange->next){
10837 
10838                                 /* skip null entries */
10839                                 if(temp_daterange->timeranges==NULL || !strcmp(temp_daterange->timeranges,XODTEMPLATE_NULL))
10840                                         continue;
10841 
10842                                 switch(temp_daterange->type){
10843                                 case DATERANGE_CALENDAR_DATE:
10844                                         fprintf(fp,"\t%d-%02d-%02d",temp_daterange->syear,temp_daterange->smon+1,temp_daterange->smday);
10845                                         if((temp_daterange->smday!=temp_daterange->emday) || (temp_daterange->smon!=temp_daterange->emon) || (temp_daterange->syear!=temp_daterange->eyear))
10846                                                 fprintf(fp," - %d-%02d-%02d",temp_daterange->eyear,temp_daterange->emon+1,temp_daterange->emday);
10847                                         if(temp_daterange->skip_interval>1)
10848                                                 fprintf(fp," / %d",temp_daterange->skip_interval);
10849                                         break;
10850                                 case DATERANGE_MONTH_DATE:
10851                                         fprintf(fp,"\t%s %d",months[temp_daterange->smon],temp_daterange->smday);
10852                                         if((temp_daterange->smon!=temp_daterange->emon) || (temp_daterange->smday!=temp_daterange->emday)){
10853                                                 fprintf(fp," - %s %d",months[temp_daterange->emon],temp_daterange->emday);
10854                                                 if(temp_daterange->skip_interval>1)
10855                                                         fprintf(fp," / %d",temp_daterange->skip_interval);
10856                                                 }
10857                                         break;
10858                                 case DATERANGE_MONTH_DAY:
10859                                         fprintf(fp,"\tday %d",temp_daterange->smday);
10860                                         if(temp_daterange->smday!=temp_daterange->emday){
10861                                                 fprintf(fp," - %d",temp_daterange->emday);
10862                                                 if(temp_daterange->skip_interval>1)
10863                                                         fprintf(fp," / %d",temp_daterange->skip_interval);
10864                                                 }
10865                                         break;
10866                                 case DATERANGE_MONTH_WEEK_DAY:
10867                                         fprintf(fp,"\t%s %d %s",days[temp_daterange->swday],temp_daterange->swday_offset,months[temp_daterange->smon]);
10868                                         if((temp_daterange->smon!=temp_daterange->emon) || (temp_daterange->swday!=temp_daterange->ewday) || (temp_daterange->swday_offset!=temp_daterange->ewday_offset)){
10869                                                 fprintf(fp," - %s %d %s",days[temp_daterange->ewday],temp_daterange->ewday_offset,months[temp_daterange->emon]);
10870                                                 if(temp_daterange->skip_interval>1)
10871                                                         fprintf(fp," / %d",temp_daterange->skip_interval);
10872                                                 }
10873                                         break;
10874                                 case DATERANGE_WEEK_DAY:
10875                                         fprintf(fp,"\t%s %d",days[temp_daterange->swday],temp_daterange->swday_offset);
10876                                         if((temp_daterange->swday!=temp_daterange->ewday) || (temp_daterange->swday_offset!=temp_daterange->ewday_offset)){
10877                                                 fprintf(fp," - %s %d",days[temp_daterange->ewday],temp_daterange->ewday_offset);
10878                                                 if(temp_daterange->skip_interval>1)
10879                                                         fprintf(fp," / %d",temp_daterange->skip_interval);
10880                                                 }
10881                                         break;
10882                                 default:
10883                                         break;
10884                                         }
10885 
10886                                 fprintf(fp,"\t%s\n",temp_daterange->timeranges);
10887                                 }
10888                         }
10889                 for(x=0;x<7;x++){
10890                         /* skip null entries */
10891                         if(temp_timeperiod->timeranges[x]==NULL  || !strcmp(temp_timeperiod->timeranges[x],XODTEMPLATE_NULL))
10892                                 continue;
10893 
10894                         fprintf(fp,"\t%s\t%s\n",days[x],temp_timeperiod->timeranges[x]);
10895                         }
10896                 if(temp_timeperiod->exclusions)
10897                         fprintf(fp,"\texclude\t%s\n",temp_timeperiod->exclusions);
10898                 fprintf(fp,"\t}\n\n");
10899                 }
10900 
10901         /* cache commands */
10902         /*for(temp_command=xodtemplate_command_list;temp_command!=NULL;temp_command=temp_command->next){*/
10903         ptr=NULL;
10904         for(temp_command=(xodtemplate_command *)skiplist_get_first(xobject_skiplists[X_COMMAND_SKIPLIST],&ptr);temp_command!=NULL;temp_command=(xodtemplate_command *)skiplist_get_next(&ptr)){
10905                 if(temp_command->register_object==FALSE)
10906                         continue;
10907                 fprintf(fp,"define command {\n");
10908                 if(temp_command->command_name)
10909                         fprintf(fp,"\tcommand_name\t%s\n",temp_command->command_name);
10910                 if(temp_command->command_line)
10911                         fprintf(fp,"\tcommand_line\t%s\n",temp_command->command_line);
10912                 fprintf(fp,"\t}\n\n");
10913                 }
10914 
10915         /* cache contactgroups */
10916         /*for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){*/
10917         ptr=NULL;
10918         for(temp_contactgroup=(xodtemplate_contactgroup *)skiplist_get_first(xobject_skiplists[X_CONTACTGROUP_SKIPLIST],&ptr);temp_contactgroup!=NULL;temp_contactgroup=(xodtemplate_contactgroup *)skiplist_get_next(&ptr)){
10919                 if(temp_contactgroup->register_object==FALSE)
10920                         continue;
10921                 fprintf(fp,"define contactgroup {\n");
10922                 if(temp_contactgroup->contactgroup_name)
10923                         fprintf(fp,"\tcontactgroup_name\t%s\n",temp_contactgroup->contactgroup_name);
10924                 if(temp_contactgroup->alias)
10925                         fprintf(fp,"\talias\t%s\n",temp_contactgroup->alias);
10926                 if(temp_contactgroup->members)
10927                         fprintf(fp,"\tmembers\t%s\n",temp_contactgroup->members);
10928                 fprintf(fp,"\t}\n\n");
10929                 }
10930 
10931         /* cache hostgroups */
10932         /*for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){*/
10933         ptr=NULL;
10934         for(temp_hostgroup=(xodtemplate_hostgroup *)skiplist_get_first(xobject_skiplists[X_HOSTGROUP_SKIPLIST],&ptr);temp_hostgroup!=NULL;temp_hostgroup=(xodtemplate_hostgroup *)skiplist_get_next(&ptr)){
10935                 if(temp_hostgroup->register_object==FALSE)
10936                         continue;
10937                 fprintf(fp,"define hostgroup {\n");
10938                 if(temp_hostgroup->hostgroup_name)
10939                         fprintf(fp,"\thostgroup_name\t%s\n",temp_hostgroup->hostgroup_name);
10940                 if(temp_hostgroup->alias)
10941                         fprintf(fp,"\talias\t%s\n",temp_hostgroup->alias);
10942                 if(temp_hostgroup->members)
10943                         fprintf(fp,"\tmembers\t%s\n",temp_hostgroup->members);
10944                 if(temp_hostgroup->notes)
10945                         fprintf(fp,"\tnotes\t%s\n",temp_hostgroup->notes);
10946                 if(temp_hostgroup->notes_url)
10947                         fprintf(fp,"\tnotes_url\t%s\n",temp_hostgroup->notes_url);
10948                 if(temp_hostgroup->action_url)
10949                         fprintf(fp,"\taction_url\t%s\n",temp_hostgroup->action_url);
10950                 fprintf(fp,"\t}\n\n");
10951                 }
10952 
10953         /* cache servicegroups */
10954         /*for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){*/
10955         ptr=NULL;
10956         for(temp_servicegroup=(xodtemplate_servicegroup *)skiplist_get_first(xobject_skiplists[X_SERVICEGROUP_SKIPLIST],&ptr);temp_servicegroup!=NULL;temp_servicegroup=(xodtemplate_servicegroup *)skiplist_get_next(&ptr)){
10957                 if(temp_servicegroup->register_object==FALSE)
10958                         continue;
10959                 fprintf(fp,"define servicegroup {\n");
10960                 if(temp_servicegroup->servicegroup_name)
10961                         fprintf(fp,"\tservicegroup_name\t%s\n",temp_servicegroup->servicegroup_name);
10962                 if(temp_servicegroup->alias)
10963                         fprintf(fp,"\talias\t%s\n",temp_servicegroup->alias);
10964                 if(temp_servicegroup->members)
10965                         fprintf(fp,"\tmembers\t%s\n",temp_servicegroup->members);
10966                 if(temp_servicegroup->notes)
10967                         fprintf(fp,"\tnotes\t%s\n",temp_servicegroup->notes);
10968                 if(temp_servicegroup->notes_url)
10969                         fprintf(fp,"\tnotes_url\t%s\n",temp_servicegroup->notes_url);
10970                 if(temp_servicegroup->action_url)
10971                         fprintf(fp,"\taction_url\t%s\n",temp_servicegroup->action_url);
10972                 fprintf(fp,"\t}\n\n");
10973                 }
10974 
10975         /* cache contacts */
10976         /*for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){*/
10977         ptr=NULL;
10978         for(temp_contact=(xodtemplate_contact *)skiplist_get_first(xobject_skiplists[X_CONTACT_SKIPLIST],&ptr);temp_contact!=NULL;temp_contact=(xodtemplate_contact *)skiplist_get_next(&ptr)){
10979                 if(temp_contact->register_object==FALSE)
10980                         continue;
10981                 fprintf(fp,"define contact {\n");
10982                 if(temp_contact->contact_name)
10983                         fprintf(fp,"\tcontact_name\t%s\n",temp_contact->contact_name);
10984                 if(temp_contact->alias)
10985                         fprintf(fp,"\talias\t%s\n",temp_contact->alias);
10986                 if(temp_contact->service_notification_period)
10987                         fprintf(fp,"\tservice_notification_period\t%s\n",temp_contact->service_notification_period);
10988                 if(temp_contact->host_notification_period)
10989                         fprintf(fp,"\thost_notification_period\t%s\n",temp_contact->host_notification_period);
10990                 fprintf(fp,"\tservice_notification_options\t");
10991                 x=0;
10992                 if(temp_contact->notify_on_service_warning==TRUE)
10993                         fprintf(fp,"%sw",(x++>0)?",":"");
10994                 if(temp_contact->notify_on_service_unknown==TRUE)
10995                         fprintf(fp,"%su",(x++>0)?",":"");
10996                 if(temp_contact->notify_on_service_critical==TRUE)
10997                         fprintf(fp,"%sc",(x++>0)?",":"");
10998                 if(temp_contact->notify_on_service_recovery==TRUE)
10999                         fprintf(fp,"%sr",(x++>0)?",":"");
11000                 if(temp_contact->notify_on_service_flapping==TRUE)
11001                         fprintf(fp,"%sf",(x++>0)?",":"");
11002                 if(temp_contact->notify_on_service_downtime==TRUE)
11003                         fprintf(fp,"%ss",(x++>0)?",":"");
11004                 if(x==0)
11005                         fprintf(fp,"n");
11006                 fprintf(fp,"\n");
11007                 fprintf(fp,"\thost_notification_options\t");
11008                 x=0;
11009                 if(temp_contact->notify_on_host_down==TRUE)
11010                         fprintf(fp,"%sd",(x++>0)?",":"");
11011                 if(temp_contact->notify_on_host_unreachable==TRUE)
11012                         fprintf(fp,"%su",(x++>0)?",":"");
11013                 if(temp_contact->notify_on_host_recovery==TRUE)
11014                         fprintf(fp,"%sr",(x++>0)?",":"");
11015                 if(temp_contact->notify_on_host_flapping==TRUE)
11016                         fprintf(fp,"%sf",(x++>0)?",":"");
11017                 if(temp_contact->notify_on_host_downtime==TRUE)
11018                         fprintf(fp,"%ss",(x++>0)?",":"");
11019                 if(x==0)
11020                         fprintf(fp,"n");
11021                 fprintf(fp,"\n");
11022                 if(temp_contact->service_notification_commands)
11023                         fprintf(fp,"\tservice_notification_commands\t%s\n",temp_contact->service_notification_commands);
11024                 if(temp_contact->host_notification_commands)
11025                         fprintf(fp,"\thost_notification_commands\t%s\n",temp_contact->host_notification_commands);
11026                 if(temp_contact->email)
11027                         fprintf(fp,"\temail\t%s\n",temp_contact->email);
11028                 if(temp_contact->pager)
11029                         fprintf(fp,"\tpager\t%s\n",temp_contact->pager);
11030                 for(x=0;x<MAX_XODTEMPLATE_CONTACT_ADDRESSES;x++){
11031                         if(temp_contact->address[x])
11032                                 fprintf(fp,"\taddress%d\t%s\n",x+1,temp_contact->address[x]);
11033                         }
11034                 fprintf(fp,"\thost_notifications_enabled\t%d\n",temp_contact->host_notifications_enabled);
11035                 fprintf(fp,"\tservice_notifications_enabled\t%d\n",temp_contact->service_notifications_enabled);
11036                 fprintf(fp,"\tcan_submit_commands\t%d\n",temp_contact->can_submit_commands);
11037                 fprintf(fp,"\tretain_status_information\t%d\n",temp_contact->retain_status_information);
11038                 fprintf(fp,"\tretain_nonstatus_information\t%d\n",temp_contact->retain_nonstatus_information);
11039 
11040                 /* custom variables */
11041                 for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
11042                         if(temp_customvariablesmember->variable_name)
11043                                 fprintf(fp,"\t_%s\t%s\n",temp_customvariablesmember->variable_name,(temp_customvariablesmember->variable_value==NULL)?XODTEMPLATE_NULL:temp_customvariablesmember->variable_value);
11044                         }
11045 
11046 
11047                 fprintf(fp,"\t}\n\n");
11048                 }
11049 
11050         /* cache hosts */
11051         /*for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){*/
11052         ptr=NULL;
11053         for(temp_host=(xodtemplate_host *)skiplist_get_first(xobject_skiplists[X_HOST_SKIPLIST],&ptr);temp_host!=NULL;temp_host=(xodtemplate_host *)skiplist_get_next(&ptr)){
11054                 if(temp_host->register_object==FALSE)
11055                         continue;
11056                 fprintf(fp,"define host {\n");
11057                 if(temp_host->host_name)
11058                         fprintf(fp,"\thost_name\t%s\n",temp_host->host_name);
11059                 if(temp_host->display_name)
11060                         fprintf(fp,"\tdisplay_name\t%s\n",temp_host->display_name);
11061                 if(temp_host->alias)
11062                         fprintf(fp,"\talias\t%s\n",temp_host->alias);
11063                 if(temp_host->address)
11064                         fprintf(fp,"\taddress\t%s\n",temp_host->address);
11065                 if(temp_host->address6)
11066                         fprintf(fp,"\taddress6\t%s\n",temp_host->address6);
11067                 if(temp_host->parents)
11068                         fprintf(fp,"\tparents\t%s\n",temp_host->parents);
11069                 if(temp_host->check_period)
11070                         fprintf(fp,"\tcheck_period\t%s\n",temp_host->check_period);
11071                 if(temp_host->check_command)
11072                         fprintf(fp,"\tcheck_command\t%s\n",temp_host->check_command);
11073                 if(temp_host->event_handler)
11074                         fprintf(fp,"\tevent_handler\t%s\n",temp_host->event_handler);
11075                 if(temp_host->contacts)
11076                         fprintf(fp,"\tcontacts\t%s\n",temp_host->contacts);
11077                 if(temp_host->contact_groups)
11078                         fprintf(fp,"\tcontact_groups\t%s\n",temp_host->contact_groups);
11079                 if(temp_host->notification_period)
11080                         fprintf(fp,"\tnotification_period\t%s\n",temp_host->notification_period);
11081                 if(temp_host->failure_prediction_options)
11082                         fprintf(fp,"\tfailure_prediction_options\t%s\n",temp_host->failure_prediction_options);
11083                 fprintf(fp,"\tinitial_state\t");
11084                 if(temp_host->initial_state==HOST_DOWN)
11085                         fprintf(fp,"d\n");
11086                 else if(temp_host->initial_state==HOST_UNREACHABLE)
11087                         fprintf(fp,"u\n");
11088                 else 
11089                         fprintf(fp,"o\n");
11090                 fprintf(fp,"\tcheck_interval\t%f\n",temp_host->check_interval);
11091                 fprintf(fp,"\tretry_interval\t%f\n",temp_host->retry_interval);
11092                 fprintf(fp,"\tmax_check_attempts\t%d\n",temp_host->max_check_attempts);
11093                 fprintf(fp,"\tactive_checks_enabled\t%d\n",temp_host->active_checks_enabled);
11094                 fprintf(fp,"\tpassive_checks_enabled\t%d\n",temp_host->passive_checks_enabled);
11095                 fprintf(fp,"\tobsess_over_host\t%d\n",temp_host->obsess_over_host);
11096                 fprintf(fp,"\tevent_handler_enabled\t%d\n",temp_host->event_handler_enabled);
11097                 fprintf(fp,"\tlow_flap_threshold\t%f\n",temp_host->low_flap_threshold);
11098                 fprintf(fp,"\thigh_flap_threshold\t%f\n",temp_host->high_flap_threshold);
11099                 fprintf(fp,"\tflap_detection_enabled\t%d\n",temp_host->flap_detection_enabled);
11100                 fprintf(fp,"\tflap_detection_options\t");
11101                 x=0;
11102                 if(temp_host->flap_detection_on_up==TRUE)
11103                         fprintf(fp,"%so",(x++>0)?",":"");
11104                 if(temp_host->flap_detection_on_down==TRUE)
11105                         fprintf(fp,"%sd",(x++>0)?",":"");
11106                 if(temp_host->flap_detection_on_unreachable==TRUE)
11107                         fprintf(fp,"%su",(x++>0)?",":"");
11108                 if(x==0)
11109                         fprintf(fp,"n");
11110                 fprintf(fp,"\n");
11111                 fprintf(fp,"\tfreshness_threshold\t%d\n",temp_host->freshness_threshold);
11112                 fprintf(fp,"\tcheck_freshness\t%d\n",temp_host->check_freshness);
11113                 fprintf(fp,"\tnotification_options\t");
11114                 x=0;
11115                 if(temp_host->notify_on_down==TRUE)
11116                         fprintf(fp,"%sd",(x++>0)?",":"");
11117                 if(temp_host->notify_on_unreachable==TRUE)
11118                         fprintf(fp,"%su",(x++>0)?",":"");
11119                 if(temp_host->notify_on_recovery==TRUE)
11120                         fprintf(fp,"%sr",(x++>0)?",":"");
11121                 if(temp_host->notify_on_flapping==TRUE)
11122                         fprintf(fp,"%sf",(x++>0)?",":"");
11123                 if(temp_host->notify_on_downtime==TRUE)
11124                         fprintf(fp,"%ss",(x++>0)?",":"");
11125                 if(x==0)
11126                         fprintf(fp,"n");
11127                 fprintf(fp,"\n");
11128                 fprintf(fp,"\tnotifications_enabled\t%d\n",temp_host->notifications_enabled);
11129                 fprintf(fp,"\tnotification_interval\t%f\n",temp_host->notification_interval);
11130                 fprintf(fp,"\tfirst_notification_delay\t%f\n",temp_host->first_notification_delay);
11131                 fprintf(fp,"\tstalking_options\t");
11132                 x=0;
11133                 if(temp_host->stalk_on_up==TRUE)
11134                         fprintf(fp,"%so",(x++>0)?",":"");
11135                 if(temp_host->stalk_on_down==TRUE)
11136                         fprintf(fp,"%sd",(x++>0)?",":"");
11137                 if(temp_host->stalk_on_unreachable==TRUE)
11138                         fprintf(fp,"%su",(x++>0)?",":"");
11139                 if(x==0)
11140                         fprintf(fp,"n");
11141                 fprintf(fp,"\n");
11142                 fprintf(fp,"\tprocess_perf_data\t%d\n",temp_host->process_perf_data);
11143                 fprintf(fp,"\tfailure_prediction_enabled\t%d\n",temp_host->failure_prediction_enabled);
11144                 if(temp_host->icon_image)
11145                         fprintf(fp,"\ticon_image\t%s\n",temp_host->icon_image);
11146                 if(temp_host->icon_image_alt)
11147                         fprintf(fp,"\ticon_image_alt\t%s\n",temp_host->icon_image_alt);
11148                 if(temp_host->vrml_image)
11149                         fprintf(fp,"\tvrml_image\t%s\n",temp_host->vrml_image);
11150                 if(temp_host->statusmap_image)
11151                         fprintf(fp,"\tstatusmap_image\t%s\n",temp_host->statusmap_image);
11152                 if(temp_host->have_2d_coords==TRUE)
11153                         fprintf(fp,"\t2d_coords\t%d,%d\n",temp_host->x_2d,temp_host->y_2d);
11154                 if(temp_host->have_3d_coords==TRUE)
11155                         fprintf(fp,"\t3d_coords\t%f,%f,%f\n",temp_host->x_3d,temp_host->y_3d,temp_host->z_3d);
11156                 if(temp_host->notes)
11157                         fprintf(fp,"\tnotes\t%s\n",temp_host->notes);
11158                 if(temp_host->notes_url)
11159                         fprintf(fp,"\tnotes_url\t%s\n",temp_host->notes_url);
11160                 if(temp_host->action_url)
11161                         fprintf(fp,"\taction_url\t%s\n",temp_host->action_url);
11162                 fprintf(fp,"\tretain_status_information\t%d\n",temp_host->retain_status_information);
11163                 fprintf(fp,"\tretain_nonstatus_information\t%d\n",temp_host->retain_nonstatus_information);
11164 
11165                 /* custom variables */
11166                 for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
11167                         if(temp_customvariablesmember->variable_name)
11168                                 fprintf(fp,"\t_%s\t%s\n",temp_customvariablesmember->variable_name,(temp_customvariablesmember->variable_value==NULL)?XODTEMPLATE_NULL:temp_customvariablesmember->variable_value);
11169                         }
11170 
11171 
11172                 fprintf(fp,"\t}\n\n");
11173                 }
11174 
11175         /* cache services */
11176         /*for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){*/
11177         ptr=NULL;
11178         for(temp_service=(xodtemplate_service *)skiplist_get_first(xobject_skiplists[X_SERVICE_SKIPLIST],&ptr);temp_service!=NULL;temp_service=(xodtemplate_service *)skiplist_get_next(&ptr)){
11179                 if(temp_service->register_object==FALSE)
11180                         continue;
11181                 fprintf(fp,"define service {\n");
11182                 if(temp_service->host_name)
11183                         fprintf(fp,"\thost_name\t%s\n",temp_service->host_name);
11184                 if(temp_service->service_description)
11185                         fprintf(fp,"\tservice_description\t%s\n",temp_service->service_description);
11186                 if(temp_service->display_name)
11187                         fprintf(fp,"\tdisplay_name\t%s\n",temp_service->display_name);
11188                 if(temp_service->check_period)
11189                         fprintf(fp,"\tcheck_period\t%s\n",temp_service->check_period);
11190                 if(temp_service->check_command)
11191                         fprintf(fp,"\tcheck_command\t%s\n",temp_service->check_command);
11192                 if(temp_service->event_handler)
11193                         fprintf(fp,"\tevent_handler\t%s\n",temp_service->event_handler);
11194                 if(temp_service->contacts)
11195                         fprintf(fp,"\tcontacts\t%s\n",temp_service->contacts);
11196                 if(temp_service->contact_groups)
11197                         fprintf(fp,"\tcontact_groups\t%s\n",temp_service->contact_groups);
11198                 if(temp_service->notification_period)
11199                         fprintf(fp,"\tnotification_period\t%s\n",temp_service->notification_period);
11200                 if(temp_service->failure_prediction_options)
11201                         fprintf(fp,"\tfailure_prediction_options\t%s\n",temp_service->failure_prediction_options);
11202                 fprintf(fp,"\tinitial_state\t");
11203                 if(temp_service->initial_state==STATE_WARNING)
11204                         fprintf(fp,"w\n");
11205                 else if(temp_service->initial_state==STATE_UNKNOWN)
11206                         fprintf(fp,"u\n");
11207                 else if(temp_service->initial_state==STATE_CRITICAL)
11208                         fprintf(fp,"c\n");
11209                 else 
11210                         fprintf(fp,"o\n");
11211                 fprintf(fp,"\tcheck_interval\t%f\n",temp_service->check_interval);
11212                 fprintf(fp,"\tretry_interval\t%f\n",temp_service->retry_interval);
11213                 fprintf(fp,"\tmax_check_attempts\t%d\n",temp_service->max_check_attempts);
11214                 fprintf(fp,"\tis_volatile\t%d\n",temp_service->is_volatile);
11215                 fprintf(fp,"\tparallelize_check\t%d\n",temp_service->parallelize_check);
11216                 fprintf(fp,"\tactive_checks_enabled\t%d\n",temp_service->active_checks_enabled);
11217                 fprintf(fp,"\tpassive_checks_enabled\t%d\n",temp_service->passive_checks_enabled);
11218                 fprintf(fp,"\tobsess_over_service\t%d\n",temp_service->obsess_over_service);
11219                 fprintf(fp,"\tevent_handler_enabled\t%d\n",temp_service->event_handler_enabled);
11220                 fprintf(fp,"\tlow_flap_threshold\t%f\n",temp_service->low_flap_threshold);
11221                 fprintf(fp,"\thigh_flap_threshold\t%f\n",temp_service->high_flap_threshold);
11222                 fprintf(fp,"\tflap_detection_enabled\t%d\n",temp_service->flap_detection_enabled);
11223                 fprintf(fp,"\tflap_detection_options\t");
11224                 x=0;
11225                 if(temp_service->flap_detection_on_ok==TRUE)
11226                         fprintf(fp,"%so",(x++>0)?",":"");
11227                 if(temp_service->flap_detection_on_warning==TRUE)
11228                         fprintf(fp,"%sw",(x++>0)?",":"");
11229                 if(temp_service->flap_detection_on_unknown==TRUE)
11230                         fprintf(fp,"%su",(x++>0)?",":"");
11231                 if(temp_service->flap_detection_on_critical==TRUE)
11232                         fprintf(fp,"%sc",(x++>0)?",":"");
11233                 if(x==0)
11234                         fprintf(fp,"n");
11235                 fprintf(fp,"\n");
11236                 fprintf(fp,"\tfreshness_threshold\t%d\n",temp_service->freshness_threshold);
11237                 fprintf(fp,"\tcheck_freshness\t%d\n",temp_service->check_freshness);
11238                 fprintf(fp,"\tnotification_options\t");
11239                 x=0;
11240                 if(temp_service->notify_on_unknown==TRUE)
11241                         fprintf(fp,"%su",(x++>0)?",":"");
11242                 if(temp_service->notify_on_warning==TRUE)
11243                         fprintf(fp,"%sw",(x++>0)?",":"");
11244                 if(temp_service->notify_on_critical==TRUE)
11245                         fprintf(fp,"%sc",(x++>0)?",":"");
11246                 if(temp_service->notify_on_recovery==TRUE)
11247                         fprintf(fp,"%sr",(x++>0)?",":"");
11248                 if(temp_service->notify_on_flapping==TRUE)
11249                         fprintf(fp,"%sf",(x++>0)?",":"");
11250                 if(temp_service->notify_on_downtime==TRUE)
11251                         fprintf(fp,"%ss",(x++>0)?",":"");
11252                 if(x==0)
11253                         fprintf(fp,"n");
11254                 fprintf(fp,"\n");
11255                 fprintf(fp,"\tnotifications_enabled\t%d\n",temp_service->notifications_enabled);
11256                 fprintf(fp,"\tnotification_interval\t%f\n",temp_service->notification_interval);
11257                 fprintf(fp,"\tfirst_notification_delay\t%f\n",temp_service->first_notification_delay);
11258                 fprintf(fp,"\tstalking_options\t");
11259                 x=0;
11260                 if(temp_service->stalk_on_ok==TRUE)
11261                         fprintf(fp,"%so",(x++>0)?",":"");
11262                 if(temp_service->stalk_on_unknown==TRUE)
11263                         fprintf(fp,"%su",(x++>0)?",":"");
11264                 if(temp_service->stalk_on_warning==TRUE)
11265                         fprintf(fp,"%sw",(x++>0)?",":"");
11266                 if(temp_service->stalk_on_critical==TRUE)
11267                         fprintf(fp,"%sc",(x++>0)?",":"");
11268                 if(x==0)
11269                         fprintf(fp,"n");
11270                 fprintf(fp,"\n");
11271                 fprintf(fp,"\tprocess_perf_data\t%d\n",temp_service->process_perf_data);
11272                 fprintf(fp,"\tfailure_prediction_enabled\t%d\n",temp_service->failure_prediction_enabled);
11273                 if(temp_service->icon_image)
11274                         fprintf(fp,"\ticon_image\t%s\n",temp_service->icon_image);
11275                 if(temp_service->icon_image_alt)
11276                         fprintf(fp,"\ticon_image_alt\t%s\n",temp_service->icon_image_alt);
11277                 if(temp_service->notes)
11278                         fprintf(fp,"\tnotes\t%s\n",temp_service->notes);
11279                 if(temp_service->notes_url)
11280                         fprintf(fp,"\tnotes_url\t%s\n",temp_service->notes_url);
11281                 if(temp_service->action_url)
11282                         fprintf(fp,"\taction_url\t%s\n",temp_service->action_url);
11283                 fprintf(fp,"\tretain_status_information\t%d\n",temp_service->retain_status_information);
11284                 fprintf(fp,"\tretain_nonstatus_information\t%d\n",temp_service->retain_nonstatus_information);
11285 
11286                 /* custom variables */
11287                 for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
11288                         if(temp_customvariablesmember->variable_name)
11289                                 fprintf(fp,"\t_%s\t%s\n",temp_customvariablesmember->variable_name,(temp_customvariablesmember->variable_value==NULL)?XODTEMPLATE_NULL:temp_customvariablesmember->variable_value);
11290                         }
11291 
11292                 fprintf(fp,"\t}\n\n");
11293                 }
11294 
11295         /* cache service dependencies */
11296         /*for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){*/
11297         ptr=NULL;
11298         for(temp_servicedependency=(xodtemplate_servicedependency *)skiplist_get_first(xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST],&ptr);temp_servicedependency!=NULL;temp_servicedependency=(xodtemplate_servicedependency *)skiplist_get_next(&ptr)){
11299                 if(temp_servicedependency->register_object==FALSE)
11300                         continue;
11301                 fprintf(fp,"define servicedependency {\n");
11302                 if(temp_servicedependency->host_name)
11303                         fprintf(fp,"\thost_name\t%s\n",temp_servicedependency->host_name);
11304                 if(temp_servicedependency->service_description)
11305                         fprintf(fp,"\tservice_description\t%s\n",temp_servicedependency->service_description);
11306                 if(temp_servicedependency->dependent_host_name)
11307                         fprintf(fp,"\tdependent_host_name\t%s\n",temp_servicedependency->dependent_host_name);
11308                 if(temp_servicedependency->dependent_service_description)
11309                         fprintf(fp,"\tdependent_service_description\t%s\n",temp_servicedependency->dependent_service_description);
11310                 if(temp_servicedependency->dependency_period)
11311                         fprintf(fp,"\tdependency_period\t%s\n",temp_servicedependency->dependency_period);
11312                 fprintf(fp,"\tinherits_parent\t%d\n",temp_servicedependency->inherits_parent);
11313                 if(temp_servicedependency->have_notification_dependency_options==TRUE){
11314                         fprintf(fp,"\tnotification_failure_options\t");
11315                         x=0;
11316                         if(temp_servicedependency->fail_notify_on_ok==TRUE)
11317                                 fprintf(fp,"%so",(x++>0)?",":"");
11318                         if(temp_servicedependency->fail_notify_on_unknown==TRUE)
11319                                 fprintf(fp,"%su",(x++>0)?",":"");
11320                         if(temp_servicedependency->fail_notify_on_warning==TRUE)
11321                                 fprintf(fp,"%sw",(x++>0)?",":"");
11322                         if(temp_servicedependency->fail_notify_on_critical==TRUE)
11323                                 fprintf(fp,"%sc",(x++>0)?",":"");
11324                         if(temp_servicedependency->fail_notify_on_pending==TRUE)
11325                                 fprintf(fp,"%sp",(x++>0)?",":"");
11326                         if(x==0)
11327                                 fprintf(fp,"n");
11328                         fprintf(fp,"\n");
11329                         }
11330                 if(temp_servicedependency->have_execution_dependency_options==TRUE){
11331                         fprintf(fp,"\texecution_failure_options\t");
11332                         x=0;
11333                         if(temp_servicedependency->fail_execute_on_ok==TRUE)
11334                                 fprintf(fp,"%so",(x++>0)?",":"");
11335                         if(temp_servicedependency->fail_execute_on_unknown==TRUE)
11336                                 fprintf(fp,"%su",(x++>0)?",":"");
11337                         if(temp_servicedependency->fail_execute_on_warning==TRUE)
11338                                 fprintf(fp,"%sw",(x++>0)?",":"");
11339                         if(temp_servicedependency->fail_execute_on_critical==TRUE)
11340                                 fprintf(fp,"%sc",(x++>0)?",":"");
11341                         if(temp_servicedependency->fail_execute_on_pending==TRUE)
11342                                 fprintf(fp,"%sp",(x++>0)?",":"");
11343                         if(x==0)
11344                                 fprintf(fp,"n");
11345                         fprintf(fp,"\n");
11346                         }
11347                 fprintf(fp,"\t}\n\n");
11348                 }
11349 
11350         /* cache service escalations */
11351         /*for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){*/
11352         ptr=NULL;
11353         for(temp_serviceescalation=(xodtemplate_serviceescalation *)skiplist_get_first(xobject_skiplists[X_SERVICEESCALATION_SKIPLIST],&ptr);temp_serviceescalation!=NULL;temp_serviceescalation=(xodtemplate_serviceescalation *)skiplist_get_next(&ptr)){
11354                 if(temp_serviceescalation->register_object==FALSE)
11355                         continue;
11356                 fprintf(fp,"define serviceescalation {\n");
11357                 if(temp_serviceescalation->host_name)
11358                         fprintf(fp,"\thost_name\t%s\n",temp_serviceescalation->host_name);
11359                 if(temp_serviceescalation->service_description)
11360                         fprintf(fp,"\tservice_description\t%s\n",temp_serviceescalation->service_description);
11361                 fprintf(fp,"\tfirst_notification\t%d\n",temp_serviceescalation->first_notification);
11362                 fprintf(fp,"\tlast_notification\t%d\n",temp_serviceescalation->last_notification);
11363 #ifdef USE_ST_BASED_ESCAL_RANGES
11364                 fprintf(fp,"\tfirst_warning_notification\t%d\n",temp_serviceescalation->first_warning_notification);
11365                 fprintf(fp,"\tlast_warning_notification\t%d\n",temp_serviceescalation->last_warning_notification);
11366                 fprintf(fp,"\tfirst_critical_notification\t%d\n",temp_serviceescalation->first_critical_notification);
11367                 fprintf(fp,"\tlast_critical_notification\t%d\n",temp_serviceescalation->last_critical_notification);
11368                 fprintf(fp,"\tfirst_unknown_notification\t%d\n",temp_serviceescalation->first_unknown_notification);
11369                 fprintf(fp,"\tlast_unknown_notification\t%d\n",temp_serviceescalation->last_unknown_notification);
11370 #endif
11371                 fprintf(fp,"\tnotification_interval\t%f\n",temp_serviceescalation->notification_interval);
11372                 if(temp_serviceescalation->escalation_period)
11373                         fprintf(fp,"\tescalation_period\t%s\n",temp_serviceescalation->escalation_period);
11374                 if(temp_serviceescalation->have_escalation_options==TRUE){
11375                         fprintf(fp,"\tescalation_options\t");
11376                         x=0;
11377                         if(temp_serviceescalation->escalate_on_warning==TRUE)
11378                                 fprintf(fp,"%sw",(x++>0)?",":"");
11379                         if(temp_serviceescalation->escalate_on_unknown==TRUE)
11380                                 fprintf(fp,"%su",(x++>0)?",":"");
11381                         if(temp_serviceescalation->escalate_on_critical==TRUE)
11382                                 fprintf(fp,"%sc",(x++>0)?",":"");
11383                         if(temp_serviceescalation->escalate_on_recovery==TRUE)
11384                                 fprintf(fp,"%sr",(x++>0)?",":"");
11385                         if(x==0)
11386                                 fprintf(fp,"n");
11387                         fprintf(fp,"\n");
11388                         }
11389                 if(temp_serviceescalation->contacts)
11390                         fprintf(fp,"\tcontacts\t%s\n",temp_serviceescalation->contacts);
11391                 if(temp_serviceescalation->contact_groups)
11392                         fprintf(fp,"\tcontact_groups\t%s\n",temp_serviceescalation->contact_groups);
11393                 fprintf(fp,"\t}\n\n");
11394                 }
11395 
11396         /* cache host dependencies */
11397         /*for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){*/
11398         ptr=NULL;
11399         for(temp_hostdependency=(xodtemplate_hostdependency *)skiplist_get_first(xobject_skiplists[X_HOSTDEPENDENCY_SKIPLIST],&ptr);temp_hostdependency!=NULL;temp_hostdependency=(xodtemplate_hostdependency *)skiplist_get_next(&ptr)){
11400                 if(temp_hostdependency->register_object==FALSE)
11401                         continue;
11402                 fprintf(fp,"define hostdependency {\n");
11403                 if(temp_hostdependency->host_name)
11404                         fprintf(fp,"\thost_name\t%s\n",temp_hostdependency->host_name);
11405                 if(temp_hostdependency->dependent_host_name)
11406                         fprintf(fp,"\tdependent_host_name\t%s\n",temp_hostdependency->dependent_host_name);
11407                 if(temp_hostdependency->dependency_period)
11408                         fprintf(fp,"\tdependency_period\t%s\n",temp_hostdependency->dependency_period);
11409                 fprintf(fp,"\tinherits_parent\t%d\n",temp_hostdependency->inherits_parent);
11410                 if(temp_hostdependency->have_notification_dependency_options==TRUE){
11411                         fprintf(fp,"\tnotification_failure_options\t");
11412                         x=0;
11413                         if(temp_hostdependency->fail_notify_on_up==TRUE)
11414                                 fprintf(fp,"%so",(x++>0)?",":"");
11415                         if(temp_hostdependency->fail_notify_on_down==TRUE)
11416                                 fprintf(fp,"%sd",(x++>0)?",":"");
11417                         if(temp_hostdependency->fail_notify_on_unreachable==TRUE)
11418                                 fprintf(fp,"%su",(x++>0)?",":"");
11419                         if(temp_hostdependency->fail_notify_on_pending==TRUE)
11420                                 fprintf(fp,"%sp",(x++>0)?",":"");
11421                         if(x==0)
11422                                 fprintf(fp,"n");
11423                         fprintf(fp,"\n");
11424                         }
11425                 if(temp_hostdependency->have_execution_dependency_options==TRUE){
11426                         fprintf(fp,"\texecution_failure_options\t");
11427                         x=0;
11428                         if(temp_hostdependency->fail_execute_on_up==TRUE)
11429                                 fprintf(fp,"%so",(x++>0)?",":"");
11430                         if(temp_hostdependency->fail_execute_on_down==TRUE)
11431                                 fprintf(fp,"%sd",(x++>0)?",":"");
11432                         if(temp_hostdependency->fail_execute_on_unreachable==TRUE)
11433                                 fprintf(fp,"%su",(x++>0)?",":"");
11434                         if(temp_hostdependency->fail_execute_on_pending==TRUE)
11435                                 fprintf(fp,"%sp",(x++>0)?",":"");
11436                         if(x==0)
11437                                 fprintf(fp,"n");
11438                         fprintf(fp,"\n");
11439                         }
11440                 fprintf(fp,"\t}\n\n");
11441                 }
11442 
11443         /* cache host escalations */
11444         /*for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){*/
11445         ptr=NULL;
11446         for(temp_hostescalation=(xodtemplate_hostescalation *)skiplist_get_first(xobject_skiplists[X_HOSTESCALATION_SKIPLIST],&ptr);temp_hostescalation!=NULL;temp_hostescalation=(xodtemplate_hostescalation *)skiplist_get_next(&ptr)){
11447                 if(temp_hostescalation->register_object==FALSE)
11448                         continue;
11449                 fprintf(fp,"define hostescalation {\n");
11450                 if(temp_hostescalation->host_name)
11451                         fprintf(fp,"\thost_name\t%s\n",temp_hostescalation->host_name);
11452                 fprintf(fp,"\tfirst_notification\t%d\n",temp_hostescalation->first_notification);
11453                 fprintf(fp,"\tlast_notification\t%d\n",temp_hostescalation->last_notification);
11454 #ifdef USE_ST_BASED_ESCAL_RANGES
11455                 fprintf(fp,"\tfirst_down_notification\t%d\n",temp_hostescalation->first_down_notification);
11456                 fprintf(fp,"\tlast_down_notification\t%d\n",temp_hostescalation->last_down_notification);
11457                 fprintf(fp,"\tfirst_unreachable_notification\t%d\n",temp_hostescalation->first_unreachable_notification);
11458                 fprintf(fp,"\tlast_unreachable_notification\t%d\n",temp_hostescalation->last_unreachable_notification);
11459 #endif
11460                 fprintf(fp,"\tnotification_interval\t%f\n",temp_hostescalation->notification_interval);
11461                 if(temp_hostescalation->escalation_period)
11462                         fprintf(fp,"\tescalation_period\t%s\n",temp_hostescalation->escalation_period);
11463                 if(temp_hostescalation->have_escalation_options==TRUE){
11464                         fprintf(fp,"\tescalation_options\t");
11465                         x=0;
11466                         if(temp_hostescalation->escalate_on_down==TRUE)
11467                                 fprintf(fp,"%sd",(x++>0)?",":"");
11468                         if(temp_hostescalation->escalate_on_unreachable==TRUE)
11469                                 fprintf(fp,"%su",(x++>0)?",":"");
11470                         if(temp_hostescalation->escalate_on_recovery==TRUE)
11471                                 fprintf(fp,"%sr",(x++>0)?",":"");
11472                         if(x==0)
11473                                 fprintf(fp,"n");
11474                         fprintf(fp,"\n");
11475                         }
11476                 if(temp_hostescalation->contacts)
11477                         fprintf(fp,"\tcontacts\t%s\n",temp_hostescalation->contacts);
11478                 if(temp_hostescalation->contact_groups)
11479                         fprintf(fp,"\tcontact_groups\t%s\n",temp_hostescalation->contact_groups);
11480                 fprintf(fp,"\t}\n\n");
11481                 }
11482 
11483         /* cache modules */
11484         /*for(temp_module=xodtemplate_module_list;temp_module!=NULL;temp_module=temp_module->next){*/
11485         ptr=NULL;
11486         for(temp_module=(xodtemplate_module *)skiplist_get_first(xobject_skiplists[X_MODULE_SKIPLIST],&ptr);temp_module!=NULL;temp_module=(xodtemplate_module *)skiplist_get_next(&ptr)){
11487                 if(temp_module->register_object==FALSE)
11488                         continue;
11489                 fprintf(fp,"define module {\n");
11490                 if(temp_module->module_name)
11491                         fprintf(fp,"\tmodule_name\t%s\n",temp_module->module_name);
11492                 if(temp_module->module_type)
11493                         fprintf(fp,"\tmodule_type\t%s\n",temp_module->module_type);
11494                 if(temp_module->path)
11495                         fprintf(fp,"\tpath\t%s\n",temp_module->path);
11496                 if(temp_module->args)
11497                         fprintf(fp,"\targs\t%s\n",temp_module->args);
11498                 fprintf(fp,"\t}\n\n");
11499                 }
11500 
11501 
11502         fclose(fp);
11503 
11504         return OK;
11505         }
11506 
11507 #endif
11508 
11509 /******************************************************************/
11510 /******************** SKIPLIST FUNCTIONS **************************/
11511 /******************************************************************/
11512 
11513 int xodtemplate_init_xobject_skiplists(void){
11514         int x=0;
11515 
11516         for(x=0;x<NUM_XOBJECT_SKIPLISTS;x++){
11517                 xobject_template_skiplists[x]=NULL;
11518                 xobject_skiplists[x]=NULL;
11519                 }
11520 
11521         xobject_template_skiplists[X_HOST_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_host_template);
11522         xobject_template_skiplists[X_SERVICE_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_service_template);
11523         xobject_template_skiplists[X_COMMAND_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_command_template);
11524         xobject_template_skiplists[X_TIMEPERIOD_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_timeperiod_template);
11525         xobject_template_skiplists[X_CONTACT_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_contact_template);
11526         xobject_template_skiplists[X_CONTACTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_contactgroup_template);
11527         xobject_template_skiplists[X_HOSTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_hostgroup_template);
11528         xobject_template_skiplists[X_SERVICEGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_servicegroup_template);
11529         xobject_template_skiplists[X_HOSTDEPENDENCY_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_hostdependency_template);
11530         xobject_template_skiplists[X_SERVICEDEPENDENCY_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_servicedependency_template);
11531         xobject_template_skiplists[X_HOSTESCALATION_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_hostescalation_template);
11532         xobject_template_skiplists[X_SERVICEESCALATION_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_serviceescalation_template);
11533         xobject_template_skiplists[X_HOSTEXTINFO_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_hostextinfo_template);
11534         xobject_template_skiplists[X_SERVICEEXTINFO_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_serviceextinfo_template);
11535         xobject_template_skiplists[X_MODULE_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_module_template);
11536 
11537         xobject_skiplists[X_HOST_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_host);
11538         xobject_skiplists[X_SERVICE_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_service);
11539         xobject_skiplists[X_COMMAND_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_command);
11540         xobject_skiplists[X_TIMEPERIOD_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_timeperiod);
11541         xobject_skiplists[X_CONTACT_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_contact);
11542         xobject_skiplists[X_CONTACTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_contactgroup);
11543         xobject_skiplists[X_HOSTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_hostgroup);
11544         xobject_skiplists[X_SERVICEGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_servicegroup);
11545         xobject_skiplists[X_MODULE_SKIPLIST]=skiplist_new(16,0.5,FALSE,FALSE,xodtemplate_skiplist_compare_module);
11546         /* allow dups in the following lists... */
11547         xobject_skiplists[X_HOSTDEPENDENCY_SKIPLIST]=skiplist_new(16,0.5,TRUE,FALSE,xodtemplate_skiplist_compare_hostdependency);
11548         xobject_skiplists[X_SERVICEDEPENDENCY_SKIPLIST]=skiplist_new(16,0.5,TRUE,FALSE,xodtemplate_skiplist_compare_servicedependency);
11549         xobject_skiplists[X_HOSTESCALATION_SKIPLIST]=skiplist_new(16,0.5,TRUE,FALSE,xodtemplate_skiplist_compare_hostescalation);
11550         xobject_skiplists[X_SERVICEESCALATION_SKIPLIST]=skiplist_new(16,0.5,TRUE,FALSE,xodtemplate_skiplist_compare_serviceescalation);
11551         /* host and service extinfo entries don't need to be added to a list... */
11552 
11553         return OK;
11554         }
11555 
11556 
11557 
11558 int xodtemplate_free_xobject_skiplists(void){
11559         int x=0;
11560 
11561         for(x=0;x<NUM_XOBJECT_SKIPLISTS;x++){
11562                 skiplist_free(&xobject_template_skiplists[x]);
11563                 skiplist_free(&xobject_skiplists[x]);
11564                 }
11565 
11566         return OK;
11567         }
11568 
11569 
11570 int xodtemplate_skiplist_compare_text(const char *val1a, const char *val1b, const char *val2a, const char *val2b){
11571         int result=0;
11572 
11573         /* check first name */
11574         if(val1a==NULL && val2a==NULL)
11575                 result=0;
11576         else if(val1a==NULL)
11577                 result=1;
11578         else if(val2a==NULL)
11579                 result=-1;
11580         else
11581                 result=strcmp(val1a,val2a);
11582 
11583         /* check second name if necessary */
11584         if(result==0){
11585                 if(val1b==NULL && val2b==NULL)
11586                         result=0;
11587                 else if(val1b==NULL)
11588                         result=1;
11589                 else if(val2b==NULL)
11590                         result=-1;
11591                 else
11592                         result=strcmp(val1b,val2b);
11593                 }
11594 
11595         return result;
11596         }
11597 
11598 
11599 
11600 int xodtemplate_skiplist_compare_host_template(void *a, void *b){
11601         xodtemplate_host *oa=NULL;
11602         xodtemplate_host *ob=NULL;
11603 
11604         oa=(xodtemplate_host *)a;
11605         ob=(xodtemplate_host *)b;
11606 
11607         if(oa==NULL && ob==NULL)
11608                 return 0;
11609         if(oa==NULL)
11610                 return 1;
11611         if(ob==NULL)
11612                 return -1;
11613 
11614         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11615         }
11616 
11617 
11618 
11619 int xodtemplate_skiplist_compare_host(void *a, void *b){
11620         xodtemplate_host *oa=NULL;
11621         xodtemplate_host *ob=NULL;
11622 
11623         oa=(xodtemplate_host *)a;
11624         ob=(xodtemplate_host *)b;
11625 
11626         if(oa==NULL && ob==NULL)
11627                 return 0;
11628         if(oa==NULL)
11629                 return 1;
11630         if(ob==NULL)
11631                 return -1;
11632 
11633         return skiplist_compare_text(oa->host_name,NULL,ob->host_name,NULL);
11634         }
11635 
11636 
11637 
11638 int xodtemplate_skiplist_compare_service_template(void *a, void *b){
11639         xodtemplate_service *oa=NULL;
11640         xodtemplate_service *ob=NULL;
11641 
11642         oa=(xodtemplate_service *)a;
11643         ob=(xodtemplate_service *)b;
11644 
11645         if(oa==NULL && ob==NULL)
11646                 return 0;
11647         if(oa==NULL)
11648                 return 1;
11649         if(ob==NULL)
11650                 return -1;
11651 
11652         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11653         }
11654 
11655 
11656 
11657 int xodtemplate_skiplist_compare_service(void *a, void *b){
11658         xodtemplate_service *oa=NULL;
11659         xodtemplate_service *ob=NULL;
11660 
11661         oa=(xodtemplate_service *)a;
11662         ob=(xodtemplate_service *)b;
11663 
11664         if(oa==NULL && ob==NULL)
11665                 return 0;
11666         if(oa==NULL)
11667                 return 1;
11668         if(ob==NULL)
11669                 return -1;
11670 
11671         return skiplist_compare_text(oa->host_name,oa->service_description,ob->host_name,ob->service_description);
11672         }
11673 
11674 
11675 
11676 int xodtemplate_skiplist_compare_timeperiod_template(void *a, void *b){
11677         xodtemplate_timeperiod *oa=NULL;
11678         xodtemplate_timeperiod *ob=NULL;
11679 
11680         oa=(xodtemplate_timeperiod *)a;
11681         ob=(xodtemplate_timeperiod *)b;
11682 
11683         if(oa==NULL && ob==NULL)
11684                 return 0;
11685         if(oa==NULL)
11686                 return 1;
11687         if(ob==NULL)
11688                 return -1;
11689 
11690         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11691         }
11692 
11693 
11694 
11695 int xodtemplate_skiplist_compare_timeperiod(void *a, void *b){
11696         xodtemplate_timeperiod *oa=NULL;
11697         xodtemplate_timeperiod *ob=NULL;
11698 
11699         oa=(xodtemplate_timeperiod *)a;
11700         ob=(xodtemplate_timeperiod *)b;
11701 
11702         if(oa==NULL && ob==NULL)
11703                 return 0;
11704         if(oa==NULL)
11705                 return 1;
11706         if(ob==NULL)
11707                 return -1;
11708 
11709         return skiplist_compare_text(oa->timeperiod_name,NULL,ob->timeperiod_name,NULL);
11710         }
11711 
11712 
11713 
11714 int xodtemplate_skiplist_compare_command_template(void *a, void *b){
11715         xodtemplate_command *oa=NULL;
11716         xodtemplate_command *ob=NULL;
11717 
11718         oa=(xodtemplate_command *)a;
11719         ob=(xodtemplate_command *)b;
11720 
11721         if(oa==NULL && ob==NULL)
11722                 return 0;
11723         if(oa==NULL)
11724                 return 1;
11725         if(ob==NULL)
11726                 return -1;
11727 
11728         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11729         }
11730 
11731 
11732 
11733 int xodtemplate_skiplist_compare_command(void *a, void *b){
11734         xodtemplate_command *oa=NULL;
11735         xodtemplate_command *ob=NULL;
11736 
11737         oa=(xodtemplate_command *)a;
11738         ob=(xodtemplate_command *)b;
11739 
11740         if(oa==NULL && ob==NULL)
11741                 return 0;
11742         if(oa==NULL)
11743                 return 1;
11744         if(ob==NULL)
11745                 return -1;
11746 
11747         return skiplist_compare_text(oa->command_name,NULL,ob->command_name,NULL);
11748         }
11749 
11750 
11751 
11752 int xodtemplate_skiplist_compare_contact_template(void *a, void *b){
11753         xodtemplate_contact *oa=NULL;
11754         xodtemplate_contact *ob=NULL;
11755 
11756         oa=(xodtemplate_contact *)a;
11757         ob=(xodtemplate_contact *)b;
11758 
11759         if(oa==NULL && ob==NULL)
11760                 return 0;
11761         if(oa==NULL)
11762                 return 1;
11763         if(ob==NULL)
11764                 return -1;
11765 
11766         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11767         }
11768 
11769 
11770 
11771 int xodtemplate_skiplist_compare_contact(void *a, void *b){
11772         xodtemplate_contact *oa=NULL;
11773         xodtemplate_contact *ob=NULL;
11774 
11775         oa=(xodtemplate_contact *)a;
11776         ob=(xodtemplate_contact *)b;
11777 
11778         if(oa==NULL && ob==NULL)
11779                 return 0;
11780         if(oa==NULL)
11781                 return 1;
11782         if(ob==NULL)
11783                 return -1;
11784 
11785         return skiplist_compare_text(oa->contact_name,NULL,ob->contact_name,NULL);
11786         }
11787 
11788 
11789 
11790 int xodtemplate_skiplist_compare_contactgroup_template(void *a, void *b){
11791         xodtemplate_contactgroup *oa=NULL;
11792         xodtemplate_contactgroup *ob=NULL;
11793 
11794         oa=(xodtemplate_contactgroup *)a;
11795         ob=(xodtemplate_contactgroup *)b;
11796 
11797         if(oa==NULL && ob==NULL)
11798                 return 0;
11799         if(oa==NULL)
11800                 return 1;
11801         if(ob==NULL)
11802                 return -1;
11803 
11804         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11805         }
11806 
11807 
11808 
11809 int xodtemplate_skiplist_compare_contactgroup(void *a, void *b){
11810         xodtemplate_contactgroup *oa=NULL;
11811         xodtemplate_contactgroup *ob=NULL;
11812 
11813         oa=(xodtemplate_contactgroup *)a;
11814         ob=(xodtemplate_contactgroup *)b;
11815 
11816         if(oa==NULL && ob==NULL)
11817                 return 0;
11818         if(oa==NULL)
11819                 return 1;
11820         if(ob==NULL)
11821                 return -1;
11822 
11823         return skiplist_compare_text(oa->contactgroup_name,NULL,ob->contactgroup_name,NULL);
11824         }
11825 
11826 
11827 
11828 int xodtemplate_skiplist_compare_hostgroup_template(void *a, void *b){
11829         xodtemplate_hostgroup *oa=NULL;
11830         xodtemplate_hostgroup *ob=NULL;
11831 
11832         oa=(xodtemplate_hostgroup *)a;
11833         ob=(xodtemplate_hostgroup *)b;
11834 
11835         if(oa==NULL && ob==NULL)
11836                 return 0;
11837         if(oa==NULL)
11838                 return 1;
11839         if(ob==NULL)
11840                 return -1;
11841 
11842         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11843         }
11844 
11845 
11846 
11847 int xodtemplate_skiplist_compare_hostgroup(void *a, void *b){
11848         xodtemplate_hostgroup *oa=NULL;
11849         xodtemplate_hostgroup *ob=NULL;
11850 
11851         oa=(xodtemplate_hostgroup *)a;
11852         ob=(xodtemplate_hostgroup *)b;
11853 
11854         if(oa==NULL && ob==NULL)
11855                 return 0;
11856         if(oa==NULL)
11857                 return 1;
11858         if(ob==NULL)
11859                 return -1;
11860 
11861         return skiplist_compare_text(oa->hostgroup_name,NULL,ob->hostgroup_name,NULL);
11862         }
11863 
11864 
11865 
11866 int xodtemplate_skiplist_compare_servicegroup_template(void *a, void *b){
11867         xodtemplate_servicegroup *oa=NULL;
11868         xodtemplate_servicegroup *ob=NULL;
11869 
11870         oa=(xodtemplate_servicegroup *)a;
11871         ob=(xodtemplate_servicegroup *)b;
11872 
11873         if(oa==NULL && ob==NULL)
11874                 return 0;
11875         if(oa==NULL)
11876                 return 1;
11877         if(ob==NULL)
11878                 return -1;
11879 
11880         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11881         }
11882 
11883 
11884 
11885 int xodtemplate_skiplist_compare_servicegroup(void *a, void *b){
11886         xodtemplate_servicegroup *oa=NULL;
11887         xodtemplate_servicegroup *ob=NULL;
11888 
11889         oa=(xodtemplate_servicegroup *)a;
11890         ob=(xodtemplate_servicegroup *)b;
11891 
11892         if(oa==NULL && ob==NULL)
11893                 return 0;
11894         if(oa==NULL)
11895                 return 1;
11896         if(ob==NULL)
11897                 return -1;
11898 
11899         return skiplist_compare_text(oa->servicegroup_name,NULL,ob->servicegroup_name,NULL);
11900         }
11901 
11902 
11903 
11904 int xodtemplate_skiplist_compare_hostdependency_template(void *a, void *b){
11905         xodtemplate_hostdependency *oa=NULL;
11906         xodtemplate_hostdependency *ob=NULL;
11907 
11908         oa=(xodtemplate_hostdependency *)a;
11909         ob=(xodtemplate_hostdependency *)b;
11910 
11911         if(oa==NULL && ob==NULL)
11912                 return 0;
11913         if(oa==NULL)
11914                 return 1;
11915         if(ob==NULL)
11916                 return -1;
11917 
11918         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11919         }
11920 
11921 
11922 
11923 int xodtemplate_skiplist_compare_hostdependency(void *a, void *b){
11924         xodtemplate_hostdependency *oa=NULL;
11925         xodtemplate_hostdependency *ob=NULL;
11926 
11927         oa=(xodtemplate_hostdependency *)a;
11928         ob=(xodtemplate_hostdependency *)b;
11929 
11930         if(oa==NULL && ob==NULL)
11931                 return 0;
11932         if(oa==NULL)
11933                 return 1;
11934         if(ob==NULL)
11935                 return -1;
11936 
11937         return skiplist_compare_text(oa->dependent_host_name,NULL,ob->dependent_host_name,NULL);
11938         }
11939 
11940 
11941 
11942 int xodtemplate_skiplist_compare_servicedependency_template(void *a, void *b){
11943         xodtemplate_servicedependency *oa=NULL;
11944         xodtemplate_servicedependency *ob=NULL;
11945 
11946         oa=(xodtemplate_servicedependency *)a;
11947         ob=(xodtemplate_servicedependency *)b;
11948 
11949         if(oa==NULL && ob==NULL)
11950                 return 0;
11951         if(oa==NULL)
11952                 return 1;
11953         if(ob==NULL)
11954                 return -1;
11955 
11956         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11957         }
11958 
11959 
11960 
11961 int xodtemplate_skiplist_compare_servicedependency(void *a, void *b){
11962         xodtemplate_servicedependency *oa=NULL;
11963         xodtemplate_servicedependency *ob=NULL;
11964 
11965         oa=(xodtemplate_servicedependency *)a;
11966         ob=(xodtemplate_servicedependency *)b;
11967 
11968         if(oa==NULL && ob==NULL)
11969                 return 0;
11970         if(oa==NULL)
11971                 return 1;
11972         if(ob==NULL)
11973                 return -1;
11974 
11975         return skiplist_compare_text(oa->dependent_host_name,oa->dependent_service_description,ob->dependent_host_name,ob->dependent_service_description);
11976         }
11977 
11978 
11979 
11980 int xodtemplate_skiplist_compare_hostescalation_template(void *a, void *b){
11981         xodtemplate_hostescalation *oa=NULL;
11982         xodtemplate_hostescalation *ob=NULL;
11983 
11984         oa=(xodtemplate_hostescalation *)a;
11985         ob=(xodtemplate_hostescalation *)b;
11986 
11987         if(oa==NULL && ob==NULL)
11988                 return 0;
11989         if(oa==NULL)
11990                 return 1;
11991         if(ob==NULL)
11992                 return -1;
11993 
11994         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
11995         }
11996 
11997 
11998 
11999 int xodtemplate_skiplist_compare_hostescalation(void *a, void *b){
12000         xodtemplate_hostescalation *oa=NULL;
12001         xodtemplate_hostescalation *ob=NULL;
12002 
12003         oa=(xodtemplate_hostescalation *)a;
12004         ob=(xodtemplate_hostescalation *)b;
12005 
12006         if(oa==NULL && ob==NULL)
12007                 return 0;
12008         if(oa==NULL)
12009                 return 1;
12010         if(ob==NULL)
12011                 return -1;
12012 
12013         return skiplist_compare_text(oa->host_name,NULL,ob->host_name,NULL);
12014         }
12015 
12016 
12017 
12018 int xodtemplate_skiplist_compare_serviceescalation_template(void *a, void *b){
12019         xodtemplate_serviceescalation *oa=NULL;
12020         xodtemplate_serviceescalation *ob=NULL;
12021 
12022         oa=(xodtemplate_serviceescalation *)a;
12023         ob=(xodtemplate_serviceescalation *)b;
12024 
12025         if(oa==NULL && ob==NULL)
12026                 return 0;
12027         if(oa==NULL)
12028                 return 1;
12029         if(ob==NULL)
12030                 return -1;
12031 
12032         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
12033         }
12034 
12035 
12036 
12037 int xodtemplate_skiplist_compare_serviceescalation(void *a, void *b){
12038         xodtemplate_serviceescalation *oa=NULL;
12039         xodtemplate_serviceescalation *ob=NULL;
12040 
12041         oa=(xodtemplate_serviceescalation *)a;
12042         ob=(xodtemplate_serviceescalation *)b;
12043 
12044         if(oa==NULL && ob==NULL)
12045                 return 0;
12046         if(oa==NULL)
12047                 return 1;
12048         if(ob==NULL)
12049                 return -1;
12050 
12051         return skiplist_compare_text(oa->host_name,oa->service_description,ob->host_name,ob->service_description);
12052         }
12053 
12054 
12055 
12056 int xodtemplate_skiplist_compare_hostextinfo_template(void *a, void *b){
12057         xodtemplate_hostextinfo *oa=NULL;
12058         xodtemplate_hostextinfo *ob=NULL;
12059 
12060         oa=(xodtemplate_hostextinfo *)a;
12061         ob=(xodtemplate_hostextinfo *)b;
12062 
12063         if(oa==NULL && ob==NULL)
12064                 return 0;
12065         if(oa==NULL)
12066                 return 1;
12067         if(ob==NULL)
12068                 return -1;
12069 
12070         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
12071         }
12072 
12073 
12074 
12075 int xodtemplate_skiplist_compare_serviceextinfo_template(void *a, void *b){
12076         xodtemplate_serviceextinfo *oa=NULL;
12077         xodtemplate_serviceextinfo *ob=NULL;
12078 
12079         oa=(xodtemplate_serviceextinfo *)a;
12080         ob=(xodtemplate_serviceextinfo *)b;
12081 
12082         if(oa==NULL && ob==NULL)
12083                 return 0;
12084         if(oa==NULL)
12085                 return 1;
12086         if(ob==NULL)
12087                 return -1;
12088 
12089         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
12090         }
12091 
12092 
12093 int xodtemplate_skiplist_compare_module(void *a, void *b){
12094         xodtemplate_module *oa=NULL;
12095         xodtemplate_module *ob=NULL;
12096 
12097         oa=(xodtemplate_module *)a;
12098         ob=(xodtemplate_module *)b;
12099 
12100         if(oa==NULL && ob==NULL)
12101                 return 0;
12102         if(oa==NULL)
12103                 return 1;
12104         if(ob==NULL)
12105                 return -1;
12106 
12107         return skiplist_compare_text(oa->module_name,NULL,ob->module_name,NULL);
12108         }
12109 
12110 
12111 int xodtemplate_skiplist_compare_module_template(void *a, void *b){
12112         xodtemplate_module *oa=NULL;
12113         xodtemplate_module *ob=NULL;
12114 
12115         oa=(xodtemplate_module *)a;
12116         ob=(xodtemplate_module *)b;
12117 
12118         if(oa==NULL && ob==NULL)
12119                 return 0;
12120         if(oa==NULL)
12121                 return 1;
12122         if(ob==NULL)
12123                 return -1;
12124 
12125         return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
12126         }
12127 
12128 
12129 
12130 /******************************************************************/
12131 /********************** CLEANUP FUNCTIONS *************************/
12132 /******************************************************************/
12133 
12134 /* frees memory */
12135 int xodtemplate_free_memory(void){
12136         xodtemplate_timeperiod *this_timeperiod=NULL;
12137         xodtemplate_timeperiod *next_timeperiod=NULL;
12138         xodtemplate_daterange *this_daterange=NULL;
12139         xodtemplate_daterange *next_daterange=NULL;
12140         xodtemplate_command *this_command=NULL;
12141         xodtemplate_command *next_command=NULL;
12142         xodtemplate_contactgroup *this_contactgroup=NULL;
12143         xodtemplate_contactgroup *next_contactgroup=NULL;
12144         xodtemplate_hostgroup *this_hostgroup=NULL;
12145         xodtemplate_hostgroup *next_hostgroup=NULL;
12146         xodtemplate_servicegroup *this_servicegroup=NULL;
12147         xodtemplate_servicegroup *next_servicegroup=NULL;
12148         xodtemplate_servicedependency *this_servicedependency=NULL;
12149         xodtemplate_servicedependency *next_servicedependency=NULL;
12150         xodtemplate_serviceescalation *this_serviceescalation=NULL;
12151         xodtemplate_serviceescalation *next_serviceescalation=NULL;
12152         xodtemplate_contact *this_contact=NULL;
12153         xodtemplate_contact *next_contact=NULL;
12154         xodtemplate_host *this_host=NULL;
12155         xodtemplate_host *next_host=NULL;
12156         xodtemplate_service *this_service=NULL;
12157         xodtemplate_service *next_service=NULL;
12158         xodtemplate_hostdependency *this_hostdependency=NULL;
12159         xodtemplate_hostdependency *next_hostdependency=NULL;
12160         xodtemplate_hostescalation *this_hostescalation=NULL;
12161         xodtemplate_hostescalation *next_hostescalation=NULL;
12162         xodtemplate_hostextinfo *this_hostextinfo=NULL;
12163         xodtemplate_hostextinfo *next_hostextinfo=NULL;
12164         xodtemplate_serviceextinfo *this_serviceextinfo=NULL;
12165         xodtemplate_serviceextinfo *next_serviceextinfo=NULL;
12166         xodtemplate_customvariablesmember *this_customvariablesmember=NULL;
12167         xodtemplate_customvariablesmember *next_customvariablesmember=NULL;
12168         xodtemplate_escalation_condition *this_escalation_condition=NULL;
12169         xodtemplate_escalation_condition *next_escalation_condition=NULL;
12170         xodtemplate_module *this_module=NULL;
12171         xodtemplate_module *next_module=NULL;
12172         register int x=0;
12173 
12174 
12175         /* free memory allocated to timeperiod list */
12176         for(this_timeperiod=xodtemplate_timeperiod_list;this_timeperiod!=NULL;this_timeperiod=next_timeperiod){
12177                 next_timeperiod=this_timeperiod->next;
12178                 my_free(this_timeperiod->template);
12179                 my_free(this_timeperiod->name);
12180                 my_free(this_timeperiod->timeperiod_name);
12181                 my_free(this_timeperiod->alias);
12182                 for(x=0;x<7;x++)
12183                         my_free(this_timeperiod->timeranges[x]);
12184                 for(x=0;x<DATERANGE_TYPES;x++){
12185                         for(this_daterange=this_timeperiod->exceptions[x];this_daterange!=NULL;this_daterange=next_daterange){
12186                                 next_daterange=this_daterange->next;
12187                                 my_free(this_daterange->timeranges);
12188                                 my_free(this_daterange);
12189                                 }
12190                         }
12191                 my_free(this_timeperiod->exclusions);
12192                 my_free(this_timeperiod);
12193                 }
12194         xodtemplate_timeperiod_list=NULL;
12195         xodtemplate_timeperiod_list_tail=NULL;
12196 
12197         /* free memory allocated to command list */
12198         for(this_command=xodtemplate_command_list;this_command!=NULL;this_command=next_command){
12199                 next_command=this_command->next;
12200                 my_free(this_command->template);
12201                 my_free(this_command->name);
12202                 my_free(this_command->command_name);
12203                 my_free(this_command->command_line);
12204                 my_free(this_command);
12205                 }
12206         xodtemplate_command_list=NULL;
12207         xodtemplate_command_list_tail=NULL;
12208 
12209         /* free memory allocated to contactgroup list */
12210         for(this_contactgroup=xodtemplate_contactgroup_list;this_contactgroup!=NULL;this_contactgroup=next_contactgroup){
12211                 next_contactgroup=this_contactgroup->next;
12212                 my_free(this_contactgroup->template);
12213                 my_free(this_contactgroup->name);
12214                 my_free(this_contactgroup->contactgroup_name);
12215                 my_free(this_contactgroup->alias);
12216                 my_free(this_contactgroup->members);
12217                 my_free(this_contactgroup->contactgroup_members);
12218                 my_free(this_contactgroup);
12219                 }
12220         xodtemplate_contactgroup_list=NULL;
12221         xodtemplate_contactgroup_list_tail=NULL;
12222 
12223         /* free memory allocated to hostgroup list */
12224         for(this_hostgroup=xodtemplate_hostgroup_list;this_hostgroup!=NULL;this_hostgroup=next_hostgroup){
12225                 next_hostgroup=this_hostgroup->next;
12226                 my_free(this_hostgroup->template);
12227                 my_free(this_hostgroup->name);
12228                 my_free(this_hostgroup->hostgroup_name);
12229                 my_free(this_hostgroup->alias);
12230                 my_free(this_hostgroup->members);
12231                 my_free(this_hostgroup->hostgroup_members);
12232                 my_free(this_hostgroup->notes);
12233                 my_free(this_hostgroup->notes_url);
12234                 my_free(this_hostgroup->action_url);
12235                 my_free(this_hostgroup);
12236                 }
12237         xodtemplate_hostgroup_list=NULL;
12238         xodtemplate_hostgroup_list_tail=NULL;
12239 
12240         /* free memory allocated to servicegroup list */
12241         for(this_servicegroup=xodtemplate_servicegroup_list;this_servicegroup!=NULL;this_servicegroup=next_servicegroup){
12242                 next_servicegroup=this_servicegroup->next;
12243                 my_free(this_servicegroup->template);
12244                 my_free(this_servicegroup->name);
12245                 my_free(this_servicegroup->servicegroup_name);
12246                 my_free(this_servicegroup->alias);
12247                 my_free(this_servicegroup->members);
12248                 my_free(this_servicegroup->servicegroup_members);
12249                 my_free(this_servicegroup->notes);
12250                 my_free(this_servicegroup->notes_url);
12251                 my_free(this_servicegroup->action_url);
12252                 my_free(this_servicegroup);
12253                 }
12254         xodtemplate_servicegroup_list=NULL;
12255         xodtemplate_servicegroup_list_tail=NULL;
12256 
12257         /* free memory allocated to servicedependency list */
12258         for(this_servicedependency=xodtemplate_servicedependency_list;this_servicedependency!=NULL;this_servicedependency=next_servicedependency){
12259                 next_servicedependency=this_servicedependency->next;
12260                 my_free(this_servicedependency->template);
12261                 my_free(this_servicedependency->name);
12262                 my_free(this_servicedependency->servicegroup_name);
12263                 my_free(this_servicedependency->hostgroup_name);
12264                 my_free(this_servicedependency->host_name);
12265                 my_free(this_servicedependency->service_description);
12266                 my_free(this_servicedependency->dependent_servicegroup_name);
12267                 my_free(this_servicedependency->dependent_hostgroup_name);
12268                 my_free(this_servicedependency->dependent_host_name);
12269                 my_free(this_servicedependency->dependent_service_description);
12270                 my_free(this_servicedependency->dependency_period);
12271                 my_free(this_servicedependency);
12272                 }
12273         xodtemplate_servicedependency_list=NULL;
12274         xodtemplate_servicedependency_list_tail=NULL;
12275 
12276         /* free memory allocated to serviceescalation list */
12277         for(this_serviceescalation=xodtemplate_serviceescalation_list;this_serviceescalation!=NULL;this_serviceescalation=next_serviceescalation){
12278                 next_serviceescalation=this_serviceescalation->next;
12279                 for(this_escalation_condition=this_serviceescalation->condition;this_escalation_condition!=NULL;this_escalation_condition=next_escalation_condition){
12280                         next_escalation_condition=this_escalation_condition->next;
12281                         my_free(this_escalation_condition->host_name);
12282                         my_free(this_escalation_condition->service_description);
12283                         my_free(this_escalation_condition);
12284                 }
12285                 my_free(this_serviceescalation->template);
12286                 my_free(this_serviceescalation->name);
12287                 my_free(this_serviceescalation->servicegroup_name);
12288                 my_free(this_serviceescalation->hostgroup_name);
12289                 my_free(this_serviceescalation->host_name);
12290                 my_free(this_serviceescalation->service_description);
12291                 my_free(this_serviceescalation->escalation_period);
12292                 my_free(this_serviceescalation->contact_groups);
12293                 my_free(this_serviceescalation->contacts);
12294                 my_free(this_serviceescalation);
12295                 }
12296         xodtemplate_serviceescalation_list=NULL;
12297         xodtemplate_serviceescalation_list_tail=NULL;
12298 
12299         /* free memory allocated to contact list */
12300         for(this_contact=xodtemplate_contact_list;this_contact!=NULL;this_contact=next_contact){
12301 
12302                 /* free custom variables */
12303                 this_customvariablesmember=this_contact->custom_variables;
12304                 while(this_customvariablesmember!=NULL){
12305                         next_customvariablesmember=this_customvariablesmember->next;
12306                         my_free(this_customvariablesmember->variable_name);
12307                         my_free(this_customvariablesmember->variable_value);
12308                         my_free(this_customvariablesmember);
12309                         this_customvariablesmember=next_customvariablesmember;
12310                         }
12311 
12312                 next_contact=this_contact->next;
12313                 my_free(this_contact->template);
12314                 my_free(this_contact->name);
12315                 my_free(this_contact->contact_name);
12316                 my_free(this_contact->alias);
12317                 my_free(this_contact->contact_groups);
12318                 my_free(this_contact->email);
12319                 my_free(this_contact->pager);
12320                 for(x=0;x<MAX_XODTEMPLATE_CONTACT_ADDRESSES;x++)
12321                         my_free(this_contact->address[x]);
12322                 my_free(this_contact->service_notification_period);
12323                 my_free(this_contact->service_notification_commands);
12324                 my_free(this_contact->host_notification_period);
12325                 my_free(this_contact->host_notification_commands);
12326                 my_free(this_contact);
12327                 }
12328         xodtemplate_contact_list=NULL;
12329         xodtemplate_contact_list_tail=NULL;
12330 
12331         /* free memory allocated to host list */
12332         for(this_host=xodtemplate_host_list;this_host!=NULL;this_host=next_host){
12333 
12334                 /* free custom variables */
12335                 this_customvariablesmember=this_host->custom_variables;
12336                 while(this_customvariablesmember!=NULL){
12337                         next_customvariablesmember=this_customvariablesmember->next;
12338                         my_free(this_customvariablesmember->variable_name);
12339                         my_free(this_customvariablesmember->variable_value);
12340                         my_free(this_customvariablesmember);
12341                         this_customvariablesmember=next_customvariablesmember;
12342                         }
12343 
12344                 next_host=this_host->next;
12345                 my_free(this_host->template);
12346                 my_free(this_host->name);
12347                 my_free(this_host->host_name);
12348                 my_free(this_host->alias);
12349                 my_free(this_host->address);
12350                 my_free(this_host->address6);
12351                 my_free(this_host->parents);
12352                 my_free(this_host->host_groups);
12353                 my_free(this_host->check_command);
12354                 my_free(this_host->check_period);
12355                 my_free(this_host->event_handler);
12356                 my_free(this_host->contact_groups);
12357                 my_free(this_host->contacts);
12358                 my_free(this_host->notification_period);
12359                 my_free(this_host->failure_prediction_options);
12360                 my_free(this_host->notes);
12361                 my_free(this_host->notes_url);
12362                 my_free(this_host->action_url);
12363                 my_free(this_host->icon_image);
12364                 my_free(this_host->icon_image_alt);
12365                 my_free(this_host->vrml_image);
12366                 my_free(this_host->statusmap_image);
12367                 my_free(this_host);
12368                 }
12369         xodtemplate_host_list=NULL;
12370         xodtemplate_host_list_tail=NULL;
12371 
12372         /* free memory allocated to service list */
12373         for(this_service=xodtemplate_service_list;this_service!=NULL;this_service=next_service){
12374 
12375                 /* free custom variables */
12376                 this_customvariablesmember=this_service->custom_variables;
12377                 while(this_customvariablesmember!=NULL){
12378                         next_customvariablesmember=this_customvariablesmember->next;
12379                         my_free(this_customvariablesmember->variable_name);
12380                         my_free(this_customvariablesmember->variable_value);
12381                         my_free(this_customvariablesmember);
12382                         this_customvariablesmember=next_customvariablesmember;
12383                         }
12384 
12385                 next_service=this_service->next;
12386                 my_free(this_service->template);
12387                 my_free(this_service->name);
12388                 my_free(this_service->hostgroup_name);
12389                 my_free(this_service->host_name);
12390                 my_free(this_service->service_description);
12391                 my_free(this_service->service_groups);
12392                 my_free(this_service->check_command);
12393                 my_free(this_service->check_period);
12394                 my_free(this_service->event_handler);
12395                 my_free(this_service->notification_period);
12396                 my_free(this_service->contact_groups);
12397                 my_free(this_service->contacts);
12398                 my_free(this_service->failure_prediction_options);
12399                 my_free(this_service->notes);
12400                 my_free(this_service->notes_url);
12401                 my_free(this_service->action_url);
12402                 my_free(this_service->icon_image);
12403                 my_free(this_service->icon_image_alt);
12404                 my_free(this_service);
12405                 }
12406         xodtemplate_service_list=NULL;
12407         xodtemplate_service_list_tail=NULL;
12408 
12409         /* free memory allocated to hostdependency list */
12410         for(this_hostdependency=xodtemplate_hostdependency_list;this_hostdependency!=NULL;this_hostdependency=next_hostdependency){
12411                 next_hostdependency=this_hostdependency->next;
12412                 my_free(this_hostdependency->template);
12413                 my_free(this_hostdependency->name);
12414                 my_free(this_hostdependency->hostgroup_name);
12415                 my_free(this_hostdependency->dependent_hostgroup_name);
12416                 my_free(this_hostdependency->host_name);
12417                 my_free(this_hostdependency->dependent_host_name);
12418                 my_free(this_hostdependency->dependency_period);
12419                 my_free(this_hostdependency);
12420                 }
12421         xodtemplate_hostdependency_list=NULL;
12422         xodtemplate_hostdependency_list_tail=NULL;
12423 
12424         /* free memory allocated to hostescalation list */
12425         for(this_hostescalation=xodtemplate_hostescalation_list;this_hostescalation!=NULL;this_hostescalation=next_hostescalation){
12426                 next_hostescalation=this_hostescalation->next;
12427                 for(this_escalation_condition=this_hostescalation->condition;this_escalation_condition!=NULL;this_escalation_condition=next_escalation_condition){
12428                         next_escalation_condition=this_escalation_condition->next;
12429                         my_free(this_escalation_condition->host_name);
12430                         my_free(this_escalation_condition->service_description);
12431                         my_free(this_escalation_condition);
12432                 }
12433                 my_free(this_hostescalation->template);
12434                 my_free(this_hostescalation->name);
12435                 my_free(this_hostescalation->hostgroup_name);
12436                 my_free(this_hostescalation->host_name);
12437                 my_free(this_hostescalation->escalation_period);
12438                 my_free(this_hostescalation->contact_groups);
12439                 my_free(this_hostescalation->contacts);
12440                 my_free(this_hostescalation);
12441                 }
12442         xodtemplate_hostescalation_list=NULL;
12443         xodtemplate_hostescalation_list_tail=NULL;
12444 
12445         /* free memory allocated to hostextinfo list */
12446         for(this_hostextinfo=xodtemplate_hostextinfo_list;this_hostextinfo!=NULL;this_hostextinfo=next_hostextinfo){
12447                 next_hostextinfo=this_hostextinfo->next;
12448                 my_free(this_hostextinfo->template);
12449                 my_free(this_hostextinfo->name);
12450                 my_free(this_hostextinfo->host_name);
12451                 my_free(this_hostextinfo->hostgroup_name);
12452                 my_free(this_hostextinfo->notes);
12453                 my_free(this_hostextinfo->notes_url);
12454                 my_free(this_hostextinfo->action_url);
12455                 my_free(this_hostextinfo->icon_image);
12456                 my_free(this_hostextinfo->icon_image_alt);
12457                 my_free(this_hostextinfo->vrml_image);
12458                 my_free(this_hostextinfo->statusmap_image);
12459                 my_free(this_hostextinfo);
12460                 }
12461         xodtemplate_hostextinfo_list=NULL;
12462         xodtemplate_hostextinfo_list_tail=NULL;
12463 
12464         /* free memory allocated to serviceextinfo list */
12465         for(this_serviceextinfo=xodtemplate_serviceextinfo_list;this_serviceextinfo!=NULL;this_serviceextinfo=next_serviceextinfo){
12466                 next_serviceextinfo=this_serviceextinfo->next;
12467                 my_free(this_serviceextinfo->template);
12468                 my_free(this_serviceextinfo->name);
12469                 my_free(this_serviceextinfo->host_name);
12470                 my_free(this_serviceextinfo->hostgroup_name);
12471                 my_free(this_serviceextinfo->service_description);
12472                 my_free(this_serviceextinfo->notes);
12473                 my_free(this_serviceextinfo->notes_url);
12474                 my_free(this_serviceextinfo->action_url);
12475                 my_free(this_serviceextinfo->icon_image);
12476                 my_free(this_serviceextinfo->icon_image_alt);
12477                 my_free(this_serviceextinfo);
12478                 }
12479         xodtemplate_serviceextinfo_list=NULL;
12480         xodtemplate_serviceextinfo_list_tail=NULL;
12481 
12482         /* free memory for the config file names */
12483         for(x=0;x<xodtemplate_current_config_file;x++)
12484                 my_free(xodtemplate_config_files[x]);
12485         my_free(xodtemplate_config_files);
12486         xodtemplate_current_config_file=0;
12487 
12488         /* free memory allocated to module list */
12489         for(this_module=xodtemplate_module_list;this_module!=NULL;this_module=next_module){
12490                 next_module=this_module->next;
12491                 my_free(this_module->template);
12492                 my_free(this_module->name);
12493                 my_free(this_module->module_name);
12494                 my_free(this_module->module_type);
12495                 my_free(this_module->path);
12496                 my_free(this_module->args);
12497                 my_free(this_module);
12498                 }
12499         xodtemplate_module_list=NULL;
12500         xodtemplate_module_list_tail=NULL;
12501 
12502 
12503         /* free skiplists */
12504         xodtemplate_free_xobject_skiplists();
12505 
12506         return OK;
12507         }
12508 
12509 
12510 
12511 
12512 #ifdef NSCORE
12513 /* adds a member to a list */
12514 int xodtemplate_add_member_to_memberlist(xodtemplate_memberlist **list, char *name1, char *name2){
12515         xodtemplate_memberlist *temp_item=NULL;
12516         xodtemplate_memberlist *new_item=NULL;
12517         int error=FALSE;
12518 
12519         if(list==NULL)
12520                 return ERROR;
12521         if(name1==NULL)
12522                 return ERROR;
12523 
12524         /* skip this member if its already in the list */
12525         for(temp_item=*list;temp_item;temp_item=temp_item->next){
12526                 if(!strcmp(temp_item->name1,name1)){
12527                         if(temp_item->name2==NULL){
12528                                 if(name2==NULL)
12529                                         break;
12530                                 }
12531                         else if(name2!=NULL && !strcmp(temp_item->name2,name2))
12532                                 break;
12533                         }
12534                 }
12535         if(temp_item)
12536                 return OK;
12537 
12538         /* allocate memory for a new list item */
12539         if((new_item=(xodtemplate_memberlist *)malloc(sizeof(xodtemplate_memberlist)))==NULL)
12540                 return ERROR;
12541 
12542         /* save the member name(s) */
12543         new_item->name1=NULL;
12544         new_item->name2=NULL;
12545         if(name1){
12546                 if((new_item->name1=(char *)strdup(name1))==NULL)
12547                         error=TRUE;
12548                 }
12549         if(name2){
12550                 if((new_item->name2=(char *)strdup(name2))==NULL)
12551                         error=TRUE;
12552                 }
12553 
12554         if(error==TRUE){
12555                 my_free(new_item->name1);
12556                 my_free(new_item->name2);
12557                 my_free(new_item);
12558                 return ERROR;
12559                 }
12560 
12561         /* add new item to head of list */
12562         new_item->next=*list;
12563         *list=new_item;
12564 
12565         return OK;
12566         }
12567 
12568 
12569 /* frees memory allocated to a temporary member list */
12570 int xodtemplate_free_memberlist(xodtemplate_memberlist **temp_list){
12571         xodtemplate_memberlist *this_memberlist=NULL;
12572         xodtemplate_memberlist *next_memberlist=NULL;
12573 
12574         /* free memory allocated to member name list */
12575         for(this_memberlist=*temp_list;this_memberlist!=NULL;this_memberlist=next_memberlist){
12576                 next_memberlist=this_memberlist->next;
12577                 my_free(this_memberlist->name1);
12578                 my_free(this_memberlist->name2);
12579                 my_free(this_memberlist);
12580                 }
12581 
12582         *temp_list=NULL;
12583 
12584         return OK;
12585         }
12586 
12587 
12588 /* remove an entry from the member list */
12589 void xodtemplate_remove_memberlist_item(xodtemplate_memberlist *item,xodtemplate_memberlist **list){
12590         xodtemplate_memberlist *temp_item=NULL;
12591 
12592         if(item==NULL || list==NULL)
12593                 return;
12594 
12595         if(*list==NULL)
12596                 return;
12597 
12598         if(*list==item)
12599                 *list=item->next;
12600 
12601         else{
12602 
12603                 for(temp_item=*list;temp_item!=NULL;temp_item=temp_item->next){
12604                         if(temp_item->next==item){
12605                                 temp_item->next=item->next;
12606                                 break;
12607                                 }
12608                         }
12609                 }
12610 
12611         my_free(item->name1);
12612         my_free(item->name2);
12613         my_free(item);
12614 
12615         return;
12616         }
12617 #endif
12618 
12619 
12620 /******************************************************************/
12621 /********************** UTILITY FUNCTIONS *************************/
12622 /******************************************************************/
12623 
12624 #ifdef NSCORE
12625 
12626 /* expands a comma-delimited list of contactgroups and/or contacts to member contact names */
12627 xodtemplate_memberlist *xodtemplate_expand_contactgroups_and_contacts(char *contactgroups, char *contacts, int _config_file, int _start_line){
12628         xodtemplate_memberlist *temp_list=NULL;
12629         xodtemplate_memberlist *reject_list=NULL;
12630         xodtemplate_memberlist *list_ptr=NULL;
12631         xodtemplate_memberlist *reject_ptr=NULL;
12632         int result=OK;
12633 
12634         /* process list of contactgroups... */
12635         if(contactgroups!=NULL){
12636 
12637                 /* expand contactgroups */
12638                 result=xodtemplate_expand_contactgroups(&temp_list,&reject_list,contactgroups,_config_file,_start_line);
12639                 if(result!=OK){
12640                         xodtemplate_free_memberlist(&temp_list);
12641                         xodtemplate_free_memberlist(&reject_list);
12642                         return NULL;
12643                         }
12644                 }
12645 
12646         /* process contact names */
12647         if(contacts!=NULL){
12648 
12649                 /* expand contacts */
12650                 result=xodtemplate_expand_contacts(&temp_list,&reject_list,contacts,_config_file,_start_line);
12651                 if(result!=OK){
12652                         xodtemplate_free_memberlist(&temp_list);
12653                         xodtemplate_free_memberlist(&reject_list);
12654                         return NULL;
12655                         }
12656                 }
12657 
12658         /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
12659         /* NOTE: rejects from this list also affect contacts generated from processing contactgroup names (see above) */
12660         for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
12661                 for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
12662                         if(!strcmp(reject_ptr->name1,list_ptr->name1)){
12663                                 xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
12664                                 break;
12665                                 }
12666                         }
12667                 }
12668         xodtemplate_free_memberlist(&reject_list);
12669         reject_list=NULL;
12670 
12671         return temp_list;
12672         }
12673 
12674 
12675 
12676 /* expands contactgroups */
12677 int xodtemplate_expand_contactgroups(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *contactgroups, int _config_file, int _start_line){
12678         char *contactgroup_names=NULL;
12679         char *temp_ptr=NULL;
12680         xodtemplate_contactgroup *temp_contactgroup=NULL;
12681         regex_t preg;
12682         int found_match=TRUE;
12683         int reject_item=FALSE;
12684         int use_regexp=FALSE;
12685 
12686         if(list==NULL || contactgroups==NULL)
12687                 return ERROR;
12688 
12689         /* allocate memory for contactgroup name list */
12690         if((contactgroup_names=(char *)strdup(contactgroups))==NULL)
12691                 return ERROR;
12692 
12693         for(temp_ptr=strtok(contactgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
12694 
12695                 found_match=FALSE;
12696                 reject_item=FALSE;
12697                 
12698                 /* strip trailing spaces */
12699                 strip(temp_ptr);
12700 
12701                 /* should we use regular expression matching? */
12702                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
12703                         use_regexp=TRUE;
12704                 else
12705                         use_regexp=FALSE;
12706 
12707                 /* use regular expression matching */
12708                 if(use_regexp==TRUE){
12709 
12710                         /* compile regular expression */
12711                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
12712                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding contact group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
12713                                 my_free(contactgroup_names);
12714                                 return ERROR;
12715                                 }
12716                         
12717                         /* test match against all contactgroup names */
12718                         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
12719 
12720                                 if(temp_contactgroup->contactgroup_name==NULL)
12721                                         continue;
12722 
12723                                 /* skip this contactgroup if it did not match the expression */
12724                                 if(regexec(&preg,temp_contactgroup->contactgroup_name,0,NULL,0))
12725                                         continue;
12726 
12727                                 found_match=TRUE;
12728 
12729                                 /* dont' add contactgroups that shouldn't be registered */
12730                                 if(temp_contactgroup->register_object==FALSE)
12731                                         continue;
12732 
12733                                 /* add contactgroup members to list */
12734                                 xodtemplate_add_contactgroup_members_to_memberlist(list,temp_contactgroup,_config_file,_start_line);
12735                                 } 
12736 
12737                         /* free memory allocated to compiled regexp */
12738                         regfree(&preg);
12739                         }
12740                 
12741                 /* use standard matching... */
12742                 else{
12743 
12744                         /* return a list of all contactgroups */
12745                         if(!strcmp(temp_ptr,"*")){
12746 
12747                                 found_match=TRUE;
12748 
12749                                 for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){ 
12750 
12751                                         /* dont' add contactgroups that shouldn't be registered */
12752                                         if(temp_contactgroup->register_object==FALSE)
12753                                                 continue;
12754 
12755                                         /* add contactgroup to list */
12756                                         xodtemplate_add_contactgroup_members_to_memberlist(list,temp_contactgroup,_config_file,_start_line);
12757                                         }
12758                                 }
12759 
12760                         /* else this is just a single contactgroup... */
12761                         else{
12762                         
12763                                 /* this contactgroup should be excluded (rejected) */
12764                                 if(temp_ptr[0]=='!'){
12765                                         reject_item=TRUE;
12766                                         temp_ptr++;
12767                                         }
12768 
12769                                 /* find the contactgroup */
12770                                 temp_contactgroup=xodtemplate_find_real_contactgroup(temp_ptr);
12771                                 if(temp_contactgroup!=NULL){
12772 
12773                                         found_match=TRUE;
12774 
12775                                         /* add contactgroup members to proper list */
12776                                         xodtemplate_add_contactgroup_members_to_memberlist((reject_item==TRUE)?reject_list:list,temp_contactgroup,_config_file,_start_line);
12777                                         }
12778                                 }
12779                         }
12780 
12781                 if(found_match==FALSE){
12782                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any contactgroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
12783                         break;
12784                         }
12785                 }
12786 
12787         /* free memory */
12788         my_free(contactgroup_names);
12789 
12790         if(found_match==FALSE)
12791                 return ERROR;
12792 
12793         return OK;
12794         }
12795 
12796 
12797 
12798 /* expands contacts */
12799 int xodtemplate_expand_contacts(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *contacts, int _config_file, int _start_line){
12800         char *contact_names=NULL;
12801         char *temp_ptr=NULL;
12802         xodtemplate_contact *temp_contact=NULL;
12803         regex_t preg;
12804         int found_match=TRUE;
12805         int reject_item=FALSE;
12806         int use_regexp=FALSE;
12807 
12808         if(list==NULL || contacts==NULL)
12809                 return ERROR;
12810 
12811         if((contact_names=(char *)strdup(contacts))==NULL)
12812                 return ERROR;
12813 
12814         /* expand each contact name */
12815         for(temp_ptr=strtok(contact_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
12816 
12817                 found_match=FALSE;
12818                 reject_item=FALSE;
12819 
12820                 /* strip trailing spaces */
12821                 strip(temp_ptr);
12822 
12823                 /* should we use regular expression matching? */
12824                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
12825                         use_regexp=TRUE;
12826 
12827                 /* use regular expression matching */
12828                 if(use_regexp==TRUE){
12829 
12830                         /* compile regular expression */
12831                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
12832                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding contact names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
12833                                 my_free(contact_names);
12834                                 return ERROR;
12835                                 }
12836                         
12837                         /* test match against all contacts */
12838                         for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
12839 
12840                                 if(temp_contact->contact_name==NULL)
12841                                         continue;
12842 
12843                                 /* skip this contact if it did not match the expression */
12844                                 if(regexec(&preg,temp_contact->contact_name,0,NULL,0))
12845                                         continue;
12846 
12847                                 found_match=TRUE;
12848 
12849                                 /* dont' add contacts that shouldn't be registered */
12850                                 if(temp_contact->register_object==FALSE)
12851                                         continue;
12852 
12853                                 /* add contact to list */
12854                                 xodtemplate_add_member_to_memberlist(list,temp_contact->contact_name,NULL);
12855                                 } 
12856 
12857                         /* free memory allocated to compiled regexp */
12858                         regfree(&preg);
12859                         }
12860                 
12861                 /* use standard matching... */
12862                 else{
12863 
12864                         /* return a list of all contacts */
12865                         if(!strcmp(temp_ptr,"*")){
12866 
12867                                 found_match=TRUE;
12868 
12869                                 for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
12870 
12871                                         if(temp_contact->contact_name==NULL)
12872                                                 continue;
12873 
12874                                         /* dont' add contacts that shouldn't be registered */
12875                                         if(temp_contact->register_object==FALSE)
12876                                                 continue;
12877 
12878                                         /* add contact to list */
12879                                         xodtemplate_add_member_to_memberlist(list,temp_contact->contact_name,NULL);
12880                                         }
12881                                 }
12882 
12883                         /* else this is just a single contact... */
12884                         else{
12885 
12886                                 /* this contact should be excluded (rejected) */
12887                                 if(temp_ptr[0]=='!'){
12888                                         reject_item=TRUE;
12889                                         temp_ptr++;
12890                                         }
12891 
12892                                 /* find the contact */
12893                                 temp_contact=xodtemplate_find_real_contact(temp_ptr);
12894                                 if(temp_contact!=NULL){
12895 
12896                                         found_match=TRUE;
12897 
12898                                         /* add contact to list */
12899                                         xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_ptr,NULL);
12900                                         }
12901                                 }
12902                         }
12903 
12904                 if(found_match==FALSE){
12905                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any contact matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
12906                         break;
12907                         }
12908                 }
12909 
12910         /* free memory */
12911         my_free(contact_names);
12912 
12913         if(found_match==FALSE)
12914                 return ERROR;
12915 
12916         return OK;
12917         }
12918 
12919 
12920 
12921 /* adds members of a contactgroups to the list of expanded (accepted) or rejected contacts */
12922 int xodtemplate_add_contactgroup_members_to_memberlist(xodtemplate_memberlist **list, xodtemplate_contactgroup *temp_contactgroup,int _config_file, int _start_line){
12923         char *group_members=NULL;
12924         char *member_name=NULL;
12925         char *member_ptr=NULL;
12926 
12927         if(list==NULL || temp_contactgroup==NULL)
12928                 return ERROR;
12929 
12930         /* if we have no members, just return. Empty contactgroups are ok */
12931         if(temp_contactgroup->members==NULL){
12932                 return OK;
12933                 }
12934 
12935         /* save a copy of the members */
12936         if((group_members=(char *)strdup(temp_contactgroup->members))==NULL)
12937                 return ERROR;
12938 
12939         /* process all contacts that belong to the contactgroup */
12940         /* NOTE: members of the group have already have been expanded by xodtemplate_recombobulate_contactgroups(), so we don't need to do it here */
12941         member_ptr=group_members;
12942         for(member_name=my_strsep(&member_ptr,",");member_name!=NULL;member_name=my_strsep(&member_ptr,",")){
12943 
12944                 /* strip trailing spaces from member name */
12945                 strip(member_name);
12946 
12947                 /* add contact to the list */
12948                 xodtemplate_add_member_to_memberlist(list,member_name,NULL);
12949                 }
12950 
12951         my_free(group_members);
12952 
12953         return OK;
12954         }
12955 
12956 
12957 
12958 /* expands a comma-delimited list of hostgroups and/or hosts to member host names */
12959 xodtemplate_memberlist *xodtemplate_expand_hostgroups_and_hosts(char *hostgroups, char *hosts, int _config_file, int _start_line){
12960         xodtemplate_memberlist *temp_list=NULL;
12961         xodtemplate_memberlist *reject_list=NULL;
12962         xodtemplate_memberlist *list_ptr=NULL;
12963         xodtemplate_memberlist *reject_ptr=NULL;
12964         int result=OK;
12965 
12966         /* process list of hostgroups... */
12967         if(hostgroups!=NULL){
12968 
12969                 /* expand host */
12970                 result=xodtemplate_expand_hostgroups(&temp_list,&reject_list,hostgroups,_config_file,_start_line);
12971                 if(result!=OK){
12972                         xodtemplate_free_memberlist(&temp_list);
12973                         xodtemplate_free_memberlist(&reject_list);
12974                         return NULL;
12975                         }
12976                 }
12977 
12978         /* process host names */
12979         if(hosts!=NULL){
12980 
12981                 /* expand hosts */
12982                 result=xodtemplate_expand_hosts(&temp_list,&reject_list,hosts,_config_file,_start_line);
12983                 if(result!=OK){
12984                         xodtemplate_free_memberlist(&temp_list);
12985                         xodtemplate_free_memberlist(&reject_list);
12986                         return NULL;
12987                         }
12988                 }
12989 
12990 #ifdef TESTING
12991         printf("->PRIOR TO CLEANUP\n");
12992         printf("   REJECT LIST:\n");
12993         for(list_ptr=reject_list;list_ptr!=NULL;list_ptr=list_ptr->next){
12994                 printf("      '%s'\n",list_ptr->name1);
12995                 }
12996         printf("   ACCEPT LIST:\n");
12997         for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
12998                 printf("      '%s'\n",list_ptr->name1);
12999                 }
13000 #endif
13001 
13002         /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
13003         /* NOTE: rejects from this list also affect hosts generated from processing hostgroup names (see above) */
13004         for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
13005                 for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
13006                         if(!strcmp(reject_ptr->name1,list_ptr->name1)){
13007                                 xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
13008                                 break;
13009                                 }
13010                         }
13011                 }
13012         xodtemplate_free_memberlist(&reject_list);
13013         reject_list=NULL;
13014 
13015         return temp_list;
13016         }
13017 
13018 
13019 
13020 /* expands hostgroups */
13021 int xodtemplate_expand_hostgroups(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *hostgroups, int _config_file, int _start_line){
13022         char *hostgroup_names=NULL;
13023         char *temp_ptr=NULL;
13024         xodtemplate_hostgroup *temp_hostgroup=NULL;
13025         regex_t preg;
13026         int found_match=TRUE;
13027         int reject_item=FALSE;
13028         int use_regexp=FALSE;
13029 
13030         if(list==NULL || hostgroups==NULL)
13031                 return ERROR;
13032 
13033         /* allocate memory for hostgroup name list */
13034         if((hostgroup_names=(char *)strdup(hostgroups))==NULL)
13035                 return ERROR;
13036 
13037         for(temp_ptr=strtok(hostgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13038 
13039                 found_match=FALSE;
13040                 reject_item=FALSE;
13041                 
13042                 /* strip trailing spaces */
13043                 strip(temp_ptr);
13044 
13045                 /* should we use regular expression matching? */
13046                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13047                         use_regexp=TRUE;
13048                 else
13049                         use_regexp=FALSE;
13050 
13051                 /* use regular expression matching */
13052                 if(use_regexp==TRUE){
13053 
13054                         /* compile regular expression */
13055                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13056                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding host group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13057                                 my_free(hostgroup_names);
13058                                 return ERROR;
13059                                 }
13060                         
13061                         /* test match against all hostgroup names */
13062                         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
13063 
13064                                 if(temp_hostgroup->hostgroup_name==NULL)
13065                                         continue;
13066 
13067                                 /* skip this hostgroup if it did not match the expression */
13068                                 if(regexec(&preg,temp_hostgroup->hostgroup_name,0,NULL,0))
13069                                         continue;
13070 
13071                                 found_match=TRUE;
13072 
13073                                 /* dont' add hostgroups that shouldn't be registered */
13074                                 if(temp_hostgroup->register_object==FALSE)
13075                                         continue;
13076 
13077                                 /* add hostgroup members to list */
13078                                 xodtemplate_add_hostgroup_members_to_memberlist(list,temp_hostgroup,_config_file,_start_line);
13079                                 } 
13080 
13081                         /* free memory allocated to compiled regexp */
13082                         regfree(&preg);
13083                         }
13084                 
13085                 /* use standard matching... */
13086                 else{
13087 
13088                         /* return a list of all hostgroups */
13089                         if(!strcmp(temp_ptr,"*")){
13090 
13091                                 found_match=TRUE;
13092 
13093                                 for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){        
13094 
13095                                         /* dont' add hostgroups that shouldn't be registered */
13096                                         if(temp_hostgroup->register_object==FALSE)
13097                                                 continue;
13098 
13099                                         /* add hostgroup to list */
13100                                         xodtemplate_add_hostgroup_members_to_memberlist(list,temp_hostgroup,_config_file,_start_line);
13101                                         }
13102                                 }
13103 
13104                         /* else this is just a single hostgroup... */
13105                         else{
13106                         
13107                                 /* this hostgroup should be excluded (rejected) */
13108                                 if(temp_ptr[0]=='!'){
13109                                         reject_item=TRUE;
13110                                         temp_ptr++;
13111                                         }
13112 
13113                                 /* find the hostgroup */
13114                                 temp_hostgroup=xodtemplate_find_real_hostgroup(temp_ptr);
13115                                 if(temp_hostgroup!=NULL){
13116 
13117                                         found_match=TRUE;
13118 
13119                                         /* add hostgroup members to proper list */
13120                                         xodtemplate_add_hostgroup_members_to_memberlist((reject_item==TRUE)?reject_list:list,temp_hostgroup,_config_file,_start_line);
13121                                         }
13122                                 }
13123                         }
13124 
13125                 if(found_match==FALSE){
13126                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any hostgroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
13127                         break;
13128                         }
13129                 }
13130 
13131         /* free memory */
13132         my_free(hostgroup_names);
13133 
13134         if(found_match==FALSE)
13135                 return ERROR;
13136 
13137         return OK;
13138         }
13139 
13140 
13141 
13142 /* expands hosts */
13143 int xodtemplate_expand_hosts(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *hosts, int _config_file, int _start_line){
13144         char *host_names=NULL;
13145         char *temp_ptr=NULL;
13146         xodtemplate_host *temp_host=NULL;
13147         regex_t preg;
13148         int found_match=TRUE;
13149         int reject_item=FALSE;
13150         int use_regexp=FALSE;
13151 
13152         if(list==NULL || hosts==NULL)
13153                 return ERROR;
13154 
13155         if((host_names=(char *)strdup(hosts))==NULL)
13156                 return ERROR;
13157 
13158         /* expand each host name */
13159         for(temp_ptr=strtok(host_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13160 
13161                 found_match=FALSE;
13162                 reject_item=FALSE;
13163 
13164                 /* strip trailing spaces */
13165                 strip(temp_ptr);
13166 
13167                 /* should we use regular expression matching? */
13168                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13169                         use_regexp=TRUE;
13170 
13171                 /* use regular expression matching */
13172                 if(use_regexp==TRUE){
13173 
13174                         /* compile regular expression */
13175                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13176                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding host names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13177                                 my_free(host_names);
13178                                 return ERROR;
13179                                 }
13180                         
13181                         /* test match against all hosts */
13182                         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
13183 
13184                                 if(temp_host->host_name==NULL)
13185                                         continue;
13186 
13187                                 /* skip this host if it did not match the expression */
13188                                 if(regexec(&preg,temp_host->host_name,0,NULL,0))
13189                                         continue;
13190 
13191                                 found_match=TRUE;
13192 
13193                                 /* dont' add hosts that shouldn't be registered */
13194                                 if(temp_host->register_object==FALSE)
13195                                         continue;
13196 
13197                                 /* add host to list */
13198                                 xodtemplate_add_member_to_memberlist(list,temp_host->host_name,NULL);
13199                                 } 
13200 
13201                         /* free memory allocated to compiled regexp */
13202                         regfree(&preg);
13203                         }
13204                 
13205                 /* use standard matching... */
13206                 else{
13207 
13208                         /* return a list of all hosts */
13209                         if(!strcmp(temp_ptr,"*")){
13210 
13211                                 found_match=TRUE;
13212 
13213                                 for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
13214 
13215                                         if(temp_host->host_name==NULL)
13216                                                 continue;
13217 
13218                                         /* dont' add hosts that shouldn't be registered */
13219                                         if(temp_host->register_object==FALSE)
13220                                                 continue;
13221 
13222                                         /* add host to list */
13223                                         xodtemplate_add_member_to_memberlist(list,temp_host->host_name,NULL);
13224                                         }
13225                                 }
13226 
13227                         /* else this is just a single host... */
13228                         else{
13229 
13230                                 /* this host should be excluded (rejected) */
13231                                 if(temp_ptr[0]=='!'){
13232                                         reject_item=TRUE;
13233                                         temp_ptr++;
13234                                         }
13235 
13236                                 /* find the host */
13237                                 temp_host=xodtemplate_find_real_host(temp_ptr);
13238                                 if(temp_host!=NULL){
13239 
13240                                         found_match=TRUE;
13241 
13242                                         /* add host to list */
13243                                         xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_ptr,NULL);
13244                                         }
13245                                 }
13246                         }
13247 
13248                 if(found_match==FALSE){
13249                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any host matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
13250                         break;
13251                         }
13252                 }
13253 
13254         /* free memory */
13255         my_free(host_names);
13256 
13257         if(found_match==FALSE)
13258                 return ERROR;
13259 
13260         return OK;
13261         }
13262 
13263 
13264 /* adds members of a hostgroups to the list of expanded (accepted) or rejected hosts */
13265 int xodtemplate_add_hostgroup_members_to_memberlist(xodtemplate_memberlist **list, xodtemplate_hostgroup *temp_hostgroup, int _config_file, int _start_line){
13266         char *group_members=NULL;
13267         char *member_name=NULL;
13268         char *member_ptr=NULL;
13269 
13270         if(list==NULL || temp_hostgroup==NULL)
13271                 return ERROR;
13272 
13273         /* if we have no members, just return. Empty hostgroups are ok */
13274         if(temp_hostgroup->members==NULL){
13275                 return OK;
13276                 }
13277 
13278         /* save a copy of the members */
13279         if((group_members=(char *)strdup(temp_hostgroup->members))==NULL)
13280                 return ERROR;
13281 
13282         /* process all hosts that belong to the hostgroup */
13283         /* NOTE: members of the group have already have been expanded by xodtemplate_recombobulate_hostgroups(), so we don't need to do it here */
13284         member_ptr=group_members;
13285         for(member_name=my_strsep(&member_ptr,",");member_name!=NULL;member_name=my_strsep(&member_ptr,",")){
13286 
13287                 /* strip trailing spaces from member name */
13288                 strip(member_name);
13289 
13290                 /* add host to the list */
13291                 xodtemplate_add_member_to_memberlist(list,member_name,NULL);
13292                 }
13293 
13294         my_free(group_members);
13295 
13296         return OK;
13297         }
13298 
13299 
13300 
13301 /* expands a comma-delimited list of servicegroups and/or service descriptions */
13302 xodtemplate_memberlist *xodtemplate_expand_servicegroups_and_services(char *servicegroups, char *host_name, char *services, int _config_file, int _start_line){
13303         xodtemplate_memberlist *temp_list=NULL;
13304         xodtemplate_memberlist *reject_list=NULL;
13305         xodtemplate_memberlist *list_ptr=NULL;
13306         xodtemplate_memberlist *reject_ptr=NULL;
13307         int result=OK;
13308 
13309         /* process list of servicegroups... */
13310         if(servicegroups!=NULL){
13311 
13312                 /* expand servicegroups */
13313                 result=xodtemplate_expand_servicegroups(&temp_list,&reject_list,servicegroups,_config_file,_start_line);
13314                 if(result!=OK){
13315                         xodtemplate_free_memberlist(&temp_list);
13316                         xodtemplate_free_memberlist(&reject_list);
13317                         return NULL;
13318                         }
13319                 }
13320 
13321         /* process service names */
13322         if(host_name!=NULL && services!=NULL){
13323 
13324                 /* expand services */
13325                 result=xodtemplate_expand_services(&temp_list,&reject_list,host_name,services,_config_file,_start_line);
13326                 if(result!=OK){
13327                         xodtemplate_free_memberlist(&temp_list);
13328                         xodtemplate_free_memberlist(&reject_list);
13329                         return NULL;
13330                         }
13331                 }
13332 
13333         /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
13334         /* NOTE: rejects from this list also affect hosts generated from processing hostgroup names (see above) */
13335         for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
13336                 for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
13337                         if(!strcmp(reject_ptr->name1,list_ptr->name1) && !strcmp(reject_ptr->name2,list_ptr->name2)){
13338                                 xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
13339                                 break;
13340                                 }
13341                         }
13342                 }
13343         xodtemplate_free_memberlist(&reject_list);
13344         reject_list=NULL;
13345 
13346         return temp_list;
13347         }
13348 
13349 
13350 /* expands servicegroups */
13351 int xodtemplate_expand_servicegroups(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *servicegroups, int _config_file, int _start_line){
13352         xodtemplate_servicegroup  *temp_servicegroup=NULL;
13353         regex_t preg;
13354         char *servicegroup_names=NULL;
13355         char *temp_ptr=NULL;
13356         int found_match=TRUE;
13357         int reject_item=FALSE;
13358         int use_regexp=FALSE;
13359 
13360         if(list==NULL)
13361                 return ERROR;
13362         if(servicegroups==NULL)
13363                 return OK;
13364 
13365         /* allocate memory for servicegroup name list */
13366         if((servicegroup_names=(char *)strdup(servicegroups))==NULL)
13367                 return ERROR;
13368 
13369         /* expand each servicegroup */
13370         for(temp_ptr=strtok(servicegroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13371 
13372                 found_match=FALSE;
13373                 reject_item=FALSE;
13374                 
13375                 /* strip trailing spaces */
13376                 strip(temp_ptr);
13377 
13378                 /* should we use regular expression matching? */
13379                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13380                         use_regexp=TRUE;
13381                 else
13382                         use_regexp=FALSE;
13383 
13384                 /* use regular expression matching */
13385                 if(use_regexp==TRUE){
13386 
13387                         /* compile regular expression */
13388                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13389                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding service group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13390                                 my_free(servicegroup_names);
13391                                 return ERROR;
13392                                 }
13393                         
13394                         /* test match against all servicegroup names */
13395                         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
13396 
13397                                 if(temp_servicegroup->servicegroup_name==NULL)
13398                                         continue;
13399 
13400                                 /* skip this servicegroup if it did not match the expression */
13401                                 if(regexec(&preg,temp_servicegroup->servicegroup_name,0,NULL,0))
13402                                         continue;
13403 
13404                                 found_match=TRUE;
13405 
13406                                 /* dont' add servicegroups that shouldn't be registered */
13407                                 if(temp_servicegroup->register_object==FALSE)
13408                                         continue;
13409 
13410                                 /* add servicegroup members to list */
13411                                 xodtemplate_add_servicegroup_members_to_memberlist(list,temp_servicegroup,_config_file,_start_line);
13412                                 }
13413 
13414                         /* free memory allocated to compiled regexp */
13415                         regfree(&preg);
13416                         }
13417                 
13418                 /* use standard matching... */
13419                 else{
13420 
13421                         /* return a list of all servicegroups */
13422                         if(!strcmp(temp_ptr,"*")){
13423 
13424                                 found_match=TRUE;
13425 
13426                                 for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 
13427 
13428                                         /* dont' add servicegroups that shouldn't be registered */
13429                                         if(temp_servicegroup->register_object==FALSE)
13430                                                 continue;
13431 
13432                                         /* add servicegroup to list */
13433                                         xodtemplate_add_servicegroup_members_to_memberlist(list,temp_servicegroup,_config_file,_start_line);
13434                                         }
13435                                 }
13436 
13437                         /* else this is just a single servicegroup... */
13438                         else{
13439                         
13440                                 /* this servicegroup should be excluded (rejected) */
13441                                 if(temp_ptr[0]=='!'){
13442                                         reject_item=TRUE;
13443                                         temp_ptr++;
13444                                         }
13445 
13446                                 /* find the servicegroup */
13447                                 if((temp_servicegroup=xodtemplate_find_real_servicegroup(temp_ptr))!=NULL){
13448 
13449                                         found_match=TRUE;
13450 
13451                                         /* add servicegroup members to list */
13452                                         xodtemplate_add_servicegroup_members_to_memberlist((reject_item==TRUE)?reject_list:list,temp_servicegroup,_config_file,_start_line);
13453                                         }
13454                                 }
13455                         }
13456 
13457                 /* we didn't find a matching servicegroup */
13458                 if(found_match==FALSE){
13459                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any servicegroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
13460                         break;
13461                         }
13462                 }
13463 
13464         /* free memory */
13465         my_free(servicegroup_names);
13466 
13467         if(found_match==FALSE)
13468                 return ERROR;
13469 
13470         return OK;
13471         }
13472 
13473 
13474 /* expands services and hosts as well */
13475 int xodtemplate_expand_services(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *host_name, char *services, int _config_file, int _start_line){
13476         char *service_names=NULL;
13477         char *temp_ptr=NULL;
13478         xodtemplate_host *temp_host=NULL;
13479         xodtemplate_service *temp_service=NULL;
13480         regex_t preg;
13481         regex_t preg2;
13482         int found_match=TRUE;
13483         int reject_item=FALSE;
13484         int use_regexp_host=FALSE;
13485         int use_regexp_service=FALSE;
13486 
13487         if(list==NULL)
13488                 return ERROR;
13489         if(host_name==NULL || services==NULL)
13490                 return OK;
13491 
13492         /* should we use regular expression matching for the host name? */
13493         if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(host_name,"*") || strstr(host_name,"?") || strstr(host_name,"+") || strstr(host_name,"\\.")))
13494                 use_regexp_host=TRUE;
13495 
13496         /* compile regular expression for host name */
13497         if(use_regexp_host==TRUE){
13498                 if(regcomp(&preg2,host_name,REG_EXTENDED))
13499                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding host names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", host_name, xodtemplate_config_file_name(_config_file), _start_line);
13500                         return ERROR;
13501                 }
13502 
13503         if((service_names=(char *)strdup(services))==NULL){
13504                 if(use_regexp_host==TRUE)
13505                         regfree(&preg2);
13506                 return ERROR;
13507                 }
13508 
13509         /* expand each service description */
13510         for(temp_ptr=strtok(service_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13511 
13512                 found_match=FALSE;
13513                 reject_item=FALSE;
13514 
13515                 /* strip trailing spaces */
13516                 strip(temp_ptr);
13517 
13518                 /* should we use regular expression matching for the service description? */
13519                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13520                         use_regexp_service=TRUE;
13521                 else
13522                         use_regexp_service=FALSE;
13523 
13524                 /* compile regular expression for service description */
13525                 if(use_regexp_service==TRUE){
13526                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13527                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding service names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13528                                 if(use_regexp_host==TRUE)
13529                                         regfree(&preg2);
13530                                 my_free(service_names);
13531                                 return ERROR;
13532                                 }
13533                         }
13534 
13535                 /* use regular expression matching */
13536                 if(use_regexp_host==TRUE || use_regexp_service==TRUE){
13537 
13538                         /* test match against all services */
13539                         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
13540 
13541                                 if(temp_service->host_name==NULL || temp_service->service_description==NULL)
13542                                         continue;
13543 
13544                                 /* skip this service if it doesn't match the host name expression */
13545                                 if(use_regexp_host==TRUE){
13546                                         if(regexec(&preg2,temp_service->host_name,0,NULL,0))
13547                                                 continue;
13548                                         }
13549                                 else{
13550                                         if(strcmp(temp_service->host_name,host_name))
13551                                                 continue;
13552                                         }
13553 
13554                                 /* skip this service if it doesn't match the service description expression */
13555                                 if(use_regexp_service==TRUE){
13556                                         if(regexec(&preg,temp_service->service_description,0,NULL,0))
13557                                                 continue;
13558                                         }
13559                                 else{
13560                                         if(strcmp(temp_service->service_description,temp_ptr))
13561                                                 continue;
13562                                         }
13563 
13564                                 found_match=TRUE;
13565 
13566                                 /* dont' add services that shouldn't be registered */
13567                                 if(temp_service->register_object==FALSE)
13568                                         continue;
13569 
13570                                 /* add service to the list */
13571                                 xodtemplate_add_member_to_memberlist(list,host_name,temp_service->service_description);
13572                                 }
13573 
13574                         /* free memory allocated to compiled regexp */
13575                         if(use_regexp_service==TRUE)
13576                                 regfree(&preg);
13577                         }
13578 
13579                 /* use standard matching... */
13580                 else{
13581 
13582                         /* return a list of all services on the host */
13583                         if(!strcmp(temp_ptr,"*")){
13584 
13585                                 found_match=TRUE;
13586 
13587                                 for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
13588 
13589                                         if(temp_service->host_name==NULL || temp_service->service_description==NULL)
13590                                                 continue;
13591 
13592                                         if(strcmp(temp_service->host_name,host_name))
13593                                                 continue;
13594 
13595                                         /* dont' add services that shouldn't be registered */
13596                                         if(temp_service->register_object==FALSE)
13597                                                 continue;
13598 
13599                                         /* add service to the list */
13600                                         xodtemplate_add_member_to_memberlist(list,host_name,temp_service->service_description);
13601                                         }
13602                                 }
13603 
13604                         /* else this is just a single service... */
13605                         else{
13606 
13607                                 /* this service should be excluded (rejected) */
13608                                 if(temp_ptr[0]=='!'){
13609                                         reject_item=TRUE;
13610                                         temp_ptr++;
13611                                         }
13612 
13613                                 /* excluding all hosts is not allowed */
13614                                 if(strcmp(host_name,"!*")) {
13615 
13616                                         /* test match against all hosts */
13617                                         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
13618 
13619                                                 if(temp_host->host_name==NULL)
13620                                                     continue;
13621                                                 
13622                                                 if(host_name[0]=='!'){
13623                                                         host_name++;
13624                                                         if (reject_item==FALSE)
13625                                                                 reject_item=TRUE;
13626                                                 }
13627 
13628                                                 /* if there are all hosts given or just a single host, find a service for each of them */
13629                                                 if(!strcmp(host_name,"*") || !strcmp(temp_host->host_name,host_name)){
13630 
13631                                                         /* find the service */
13632                                                         if((temp_service=xodtemplate_find_real_service(temp_host->host_name,temp_ptr))!=NULL){
13633 
13634                                                                 found_match=TRUE;
13635                                                                         
13636                                                                 /* add service to the list */
13637                                                                 xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_host->host_name,temp_service->service_description);
13638                                                         }
13639                                                 } 
13640                                         }
13641                                 }
13642                         }
13643                 }
13644 
13645                 /* we didn't find a match */
13646                 if(found_match==FALSE && reject_item==FALSE){
13647                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find a service matching host name '%s' and description '%s' (config file '%s', starting on line %d)\n",host_name,temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
13648                         break;
13649                         }
13650                 }
13651 
13652         if(use_regexp_host==TRUE)
13653                 regfree(&preg2);
13654         my_free(service_names);
13655 
13656         if(found_match==FALSE && reject_item==FALSE)
13657                 return ERROR;
13658 
13659         return OK;
13660         }
13661 
13662 
13663 /* adds members of a servicegroups to the list of expanded services */
13664 int xodtemplate_add_servicegroup_members_to_memberlist(xodtemplate_memberlist **list, xodtemplate_servicegroup *temp_servicegroup, int _config_file, int _start_line){
13665         char *group_members=NULL;
13666         char *member_name=NULL;
13667         char *host_name=NULL;
13668         char *member_ptr=NULL;
13669 
13670         if(list==NULL || temp_servicegroup==NULL)
13671                 return ERROR;
13672 
13673         /* if we have no members, just return. Empty servicegroups are ok */
13674         if(temp_servicegroup->members==NULL){
13675                 return OK;
13676                 }
13677 
13678         /* save a copy of the members */
13679         if((group_members=(char *)strdup(temp_servicegroup->members))==NULL)
13680                 return ERROR;
13681 
13682         /* process all services that belong to the servicegroup */
13683         /* NOTE: members of the group have already have been expanded by xodtemplate_recombobulate_servicegroups(), so we don't need to do it here */
13684         member_ptr=group_members;
13685         for(member_name=my_strsep(&member_ptr,",");member_name!=NULL;member_name=my_strsep(&member_ptr,",")){
13686 
13687                 /* strip trailing spaces from member name */
13688                 strip(member_name);
13689 
13690                 /* host name */
13691                 if(host_name==NULL){
13692                         if((host_name=(char *)strdup(member_name))==NULL){
13693                                 my_free(group_members);
13694                                 return ERROR;
13695                                 }
13696                         }
13697 
13698                 /* service description */
13699                 else{
13700                                 
13701                         /* add service to the list */
13702                         xodtemplate_add_member_to_memberlist(list,host_name,member_name);
13703 
13704                         my_free(host_name);
13705                         }
13706                 }
13707 
13708         my_free(group_members);
13709 
13710         return OK;
13711         }
13712 
13713 
13714 
13715 
13716 /* returns a comma-delimited list of hostgroup names */
13717 char * xodtemplate_process_hostgroup_names(char *hostgroups, int _config_file, int _start_line){
13718         xodtemplate_memberlist *temp_list=NULL;
13719         xodtemplate_memberlist *reject_list=NULL;
13720         xodtemplate_memberlist *list_ptr=NULL;
13721         xodtemplate_memberlist *reject_ptr=NULL;
13722         xodtemplate_memberlist *this_list=NULL;
13723         char *buf=NULL;
13724         int result=OK;
13725 
13726         /* process list of hostgroups... */
13727         if(hostgroups!=NULL){
13728 
13729                 /* split group names into two lists */
13730                 result=xodtemplate_get_hostgroup_names(&temp_list,&reject_list,hostgroups,_config_file,_start_line);
13731                 if(result!=OK){
13732                         xodtemplate_free_memberlist(&temp_list);
13733                         xodtemplate_free_memberlist(&reject_list);
13734                         return NULL;
13735                         }
13736 
13737                 /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
13738                 for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
13739                         for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
13740                                 if(!strcmp(reject_ptr->name1,list_ptr->name1)){
13741                                         xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
13742                                         break;
13743                                         }
13744                                 }
13745                         }
13746 
13747                 xodtemplate_free_memberlist(&reject_list);
13748                 reject_list=NULL;
13749                 }
13750 
13751         /* generate the list of group members */
13752         for(this_list=temp_list;this_list!=NULL;this_list=this_list->next){
13753                 if(buf==NULL){
13754                         buf=(char *)malloc(strlen(this_list->name1)+1);
13755                         strcpy(buf,this_list->name1);
13756                         }
13757                 else{
13758                         buf=(char *)realloc(buf,strlen(buf)+strlen(this_list->name1)+2);
13759                         strcat(buf,",");
13760                         strcat(buf,this_list->name1);
13761                         }
13762                 }
13763 
13764         xodtemplate_free_memberlist(&temp_list);
13765 
13766         return buf;
13767         }
13768 
13769 
13770 
13771 /* return a list of hostgroup names */
13772 int xodtemplate_get_hostgroup_names(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *hostgroups, int _config_file, int _start_line){
13773         char *hostgroup_names=NULL;
13774         char *temp_ptr=NULL;
13775         xodtemplate_hostgroup *temp_hostgroup=NULL;
13776         regex_t preg;
13777         int found_match=TRUE;
13778         int reject_item=FALSE;
13779         int use_regexp=FALSE;
13780 
13781         if(list==NULL || hostgroups==NULL)
13782                 return ERROR;
13783 
13784         /* allocate memory for hostgroup name list */
13785         if((hostgroup_names=(char *)strdup(hostgroups))==NULL)
13786                 return ERROR;
13787 
13788         for(temp_ptr=strtok(hostgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13789 
13790                 found_match=FALSE;
13791                 reject_item=FALSE;
13792                 
13793                 /* strip trailing spaces */
13794                 strip(temp_ptr);
13795 
13796                 /* should we use regular expression matching? */
13797                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13798                         use_regexp=TRUE;
13799                 else
13800                         use_regexp=FALSE;
13801 
13802                 /* use regular expression matching */
13803                 if(use_regexp==TRUE){
13804 
13805                         /* compile regular expression */
13806                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13807                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding host group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13808                                 my_free(hostgroup_names);
13809                                 return ERROR;
13810                                 }
13811                         
13812                         /* test match against all hostgroup names */
13813                         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
13814 
13815                                 if(temp_hostgroup->hostgroup_name==NULL)
13816                                         continue;
13817 
13818                                 /* skip this hostgroup if it did not match the expression */
13819                                 if(regexec(&preg,temp_hostgroup->hostgroup_name,0,NULL,0))
13820                                         continue;
13821 
13822                                 found_match=TRUE;
13823 
13824                                 /* dont' add hostgroups that shouldn't be registered */
13825                                 if(temp_hostgroup->register_object==FALSE)
13826                                         continue;
13827 
13828                                 /* add hostgroup to list */
13829                                 xodtemplate_add_member_to_memberlist(list,temp_hostgroup->hostgroup_name,NULL);
13830                                 } 
13831 
13832                         /* free memory allocated to compiled regexp */
13833                         regfree(&preg);
13834                         }
13835                 
13836                 /* use standard matching... */
13837                 else{
13838 
13839                         /* return a list of all hostgroups */
13840                         if(!strcmp(temp_ptr,"*")){
13841 
13842                                 found_match=TRUE;
13843 
13844                                 for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){        
13845 
13846                                         /* dont' add hostgroups that shouldn't be registered */
13847                                         if(temp_hostgroup->register_object==FALSE)
13848                                                 continue;
13849 
13850                                         /* add hostgroup to list */
13851                                         xodtemplate_add_member_to_memberlist(list,temp_hostgroup->hostgroup_name,NULL);
13852                                         }
13853                                 }
13854 
13855                         /* else this is just a single hostgroup... */
13856                         else{
13857                         
13858                                 /* this hostgroup should be excluded (rejected) */
13859                                 if(temp_ptr[0]=='!'){
13860                                         reject_item=TRUE;
13861                                         temp_ptr++;
13862                                         }
13863 
13864                                 /* find the hostgroup */
13865                                 temp_hostgroup=xodtemplate_find_real_hostgroup(temp_ptr);
13866                                 if(temp_hostgroup!=NULL){
13867 
13868                                         found_match=TRUE;
13869 
13870                                         /* add hostgroup members to proper list */
13871                                         xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_hostgroup->hostgroup_name,NULL);
13872                                         }
13873                                 }
13874                         }
13875 
13876                 if(found_match==FALSE){
13877                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any hostgroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
13878                         break;
13879                         }
13880                 }
13881 
13882         /* free memory */
13883         my_free(hostgroup_names);
13884 
13885         if(found_match==FALSE)
13886                 return ERROR;
13887 
13888         return OK;
13889         }
13890 
13891 
13892 
13893 /* returns a comma-delimited list of contactgroup names */
13894 char * xodtemplate_process_contactgroup_names(char *contactgroups, int _config_file, int _start_line){
13895         xodtemplate_memberlist *temp_list=NULL;
13896         xodtemplate_memberlist *reject_list=NULL;
13897         xodtemplate_memberlist *list_ptr=NULL;
13898         xodtemplate_memberlist *reject_ptr=NULL;
13899         xodtemplate_memberlist *this_list=NULL;
13900         char *buf=NULL;
13901         int result=OK;
13902 
13903         /* process list of contactgroups... */
13904         if(contactgroups!=NULL){
13905 
13906                 /* split group names into two lists */
13907                 result=xodtemplate_get_contactgroup_names(&temp_list,&reject_list,contactgroups,_config_file,_start_line);
13908                 if(result!=OK){
13909                         xodtemplate_free_memberlist(&temp_list);
13910                         xodtemplate_free_memberlist(&reject_list);
13911                         return NULL;
13912                         }
13913 
13914                 /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
13915                 for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
13916                         for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
13917                                 if(!strcmp(reject_ptr->name1,list_ptr->name1)){
13918                                         xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
13919                                         break;
13920                                         }
13921                                 }
13922                         }
13923 
13924                 xodtemplate_free_memberlist(&reject_list);
13925                 reject_list=NULL;
13926                 }
13927 
13928         /* generate the list of group members */
13929         for(this_list=temp_list;this_list!=NULL;this_list=this_list->next){
13930                 if(buf==NULL){
13931                         buf=(char *)malloc(strlen(this_list->name1)+1);
13932                         strcpy(buf,this_list->name1);
13933                         }
13934                 else{
13935                         buf=(char *)realloc(buf,strlen(buf)+strlen(this_list->name1)+2);
13936                         strcat(buf,",");
13937                         strcat(buf,this_list->name1);
13938                         }
13939                 }
13940 
13941         xodtemplate_free_memberlist(&temp_list);
13942 
13943         return buf;
13944         }
13945 
13946 
13947 
13948 /* return a list of contactgroup names */
13949 int xodtemplate_get_contactgroup_names(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *contactgroups, int _config_file, int _start_line){
13950         char *contactgroup_names=NULL;
13951         char *temp_ptr=NULL;
13952         xodtemplate_contactgroup *temp_contactgroup=NULL;
13953         regex_t preg;
13954         int found_match=TRUE;
13955         int reject_item=FALSE;
13956         int use_regexp=FALSE;
13957 
13958         if(list==NULL || contactgroups==NULL)
13959                 return ERROR;
13960 
13961         /* allocate memory for contactgroup name list */
13962         if((contactgroup_names=(char *)strdup(contactgroups))==NULL)
13963                 return ERROR;
13964 
13965         for(temp_ptr=strtok(contactgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
13966 
13967                 found_match=FALSE;
13968                 reject_item=FALSE;
13969                 
13970                 /* strip trailing spaces */
13971                 strip(temp_ptr);
13972 
13973                 /* should we use regular expression matching? */
13974                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
13975                         use_regexp=TRUE;
13976                 else
13977                         use_regexp=FALSE;
13978 
13979                 /* use regular expression matching */
13980                 if(use_regexp==TRUE){
13981 
13982                         /* compile regular expression */
13983                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
13984                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding contact group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
13985                                 my_free(contactgroup_names);
13986                                 return ERROR;
13987                                 }
13988                         
13989                         /* test match against all contactgroup names */
13990                         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
13991 
13992                                 if(temp_contactgroup->contactgroup_name==NULL)
13993                                         continue;
13994 
13995                                 /* skip this contactgroup if it did not match the expression */
13996                                 if(regexec(&preg,temp_contactgroup->contactgroup_name,0,NULL,0))
13997                                         continue;
13998 
13999                                 found_match=TRUE;
14000 
14001                                 /* dont' add contactgroups that shouldn't be registered */
14002                                 if(temp_contactgroup->register_object==FALSE)
14003                                         continue;
14004 
14005                                 /* add contactgroup to list */
14006                                 xodtemplate_add_member_to_memberlist(list,temp_contactgroup->contactgroup_name,NULL);
14007                                 } 
14008 
14009                         /* free memory allocated to compiled regexp */
14010                         regfree(&preg);
14011                         }
14012                 
14013                 /* use standard matching... */
14014                 else{
14015 
14016                         /* return a list of all contactgroups */
14017                         if(!strcmp(temp_ptr,"*")){
14018 
14019                                 found_match=TRUE;
14020 
14021                                 for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){ 
14022 
14023                                         /* dont' add contactgroups that shouldn't be registered */
14024                                         if(temp_contactgroup->register_object==FALSE)
14025                                                 continue;
14026 
14027                                         /* add contactgroup to list */
14028                                         xodtemplate_add_member_to_memberlist(list,temp_contactgroup->contactgroup_name,NULL);
14029                                         }
14030                                 }
14031 
14032                         /* else this is just a single contactgroup... */
14033                         else{
14034                         
14035                                 /* this contactgroup should be excluded (rejected) */
14036                                 if(temp_ptr[0]=='!'){
14037                                         reject_item=TRUE;
14038                                         temp_ptr++;
14039                                         }
14040 
14041                                 /* find the contactgroup */
14042                                 temp_contactgroup=xodtemplate_find_real_contactgroup(temp_ptr);
14043                                 if(temp_contactgroup!=NULL){
14044 
14045                                         found_match=TRUE;
14046 
14047                                         /* add contactgroup members to proper list */
14048                                         xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_contactgroup->contactgroup_name,NULL);
14049                                         }
14050                                 }
14051                         }
14052 
14053                 if(found_match==FALSE){
14054                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any contactgroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
14055                         break;
14056                         }
14057                 }
14058 
14059         /* free memory */
14060         my_free(contactgroup_names);
14061 
14062         if(found_match==FALSE)
14063                 return ERROR;
14064 
14065         return OK;
14066         }
14067 
14068 
14069 
14070 /* returns a comma-delimited list of servicegroup names */
14071 char * xodtemplate_process_servicegroup_names(char *servicegroups, int _config_file, int _start_line){
14072         xodtemplate_memberlist *temp_list=NULL;
14073         xodtemplate_memberlist *reject_list=NULL;
14074         xodtemplate_memberlist *list_ptr=NULL;
14075         xodtemplate_memberlist *reject_ptr=NULL;
14076         xodtemplate_memberlist *this_list=NULL;
14077         char *buf=NULL;
14078         int result=OK;
14079 
14080         /* process list of servicegroups... */
14081         if(servicegroups!=NULL){
14082 
14083                 /* split group names into two lists */
14084                 result=xodtemplate_get_servicegroup_names(&temp_list,&reject_list,servicegroups,_config_file,_start_line);
14085                 if(result!=OK){
14086                         xodtemplate_free_memberlist(&temp_list);
14087                         xodtemplate_free_memberlist(&reject_list);
14088                         return NULL;
14089                         }
14090 
14091                 /* remove rejects (if any) from the list (no duplicate entries exist in either list) */
14092                 for(reject_ptr=reject_list;reject_ptr!=NULL;reject_ptr=reject_ptr->next){
14093                         for(list_ptr=temp_list;list_ptr!=NULL;list_ptr=list_ptr->next){
14094                                 if(!strcmp(reject_ptr->name1,list_ptr->name1)){
14095                                         xodtemplate_remove_memberlist_item(list_ptr,&temp_list);
14096                                         break;
14097                                         }
14098                                 }
14099                         }
14100 
14101                 xodtemplate_free_memberlist(&reject_list);
14102                 reject_list=NULL;
14103                 }
14104 
14105         /* generate the list of group members */
14106         for(this_list=temp_list;this_list!=NULL;this_list=this_list->next){
14107                 if(buf==NULL){
14108                         buf=(char *)malloc(strlen(this_list->name1)+1);
14109                         strcpy(buf,this_list->name1);
14110                         }
14111                 else{
14112                         buf=(char *)realloc(buf,strlen(buf)+strlen(this_list->name1)+2);
14113                         strcat(buf,",");
14114                         strcat(buf,this_list->name1);
14115                         }
14116                 }
14117 
14118         xodtemplate_free_memberlist(&temp_list);
14119 
14120         return buf;
14121         }
14122 
14123 
14124 
14125 /* return a list of servicegroup names */
14126 int xodtemplate_get_servicegroup_names(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *servicegroups, int _config_file, int _start_line){
14127         char *servicegroup_names=NULL;
14128         char *temp_ptr=NULL;
14129         xodtemplate_servicegroup *temp_servicegroup=NULL;
14130         regex_t preg;
14131         int found_match=TRUE;
14132         int reject_item=FALSE;
14133         int use_regexp=FALSE;
14134 
14135         if(list==NULL || servicegroups==NULL)
14136                 return ERROR;
14137 
14138         /* allocate memory for servicegroup name list */
14139         if((servicegroup_names=(char *)strdup(servicegroups))==NULL)
14140                 return ERROR;
14141 
14142         for(temp_ptr=strtok(servicegroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
14143 
14144                 found_match=FALSE;
14145                 reject_item=FALSE;
14146                 
14147                 /* strip trailing spaces */
14148                 strip(temp_ptr);
14149 
14150                 /* should we use regular expression matching? */
14151                 if(use_regexp_matches==TRUE && (use_true_regexp_matching==TRUE || strstr(temp_ptr,"*") || strstr(temp_ptr,"?") || strstr(temp_ptr,"+") || strstr(temp_ptr,"\\.")))
14152                         use_regexp=TRUE;
14153                 else
14154                         use_regexp=FALSE;
14155 
14156                 /* use regular expression matching */
14157                 if(use_regexp==TRUE){
14158 
14159                         /* compile regular expression */
14160                         if(regcomp(&preg,temp_ptr,REG_EXTENDED)){
14161                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid regular expression '%s' found while expanding service group names in file '%s' starting on line %d. NOTE: regex could be inherited from a template in a different file.\n", temp_ptr, xodtemplate_config_file_name(_config_file), _start_line);
14162                                 my_free(servicegroup_names);
14163                                 return ERROR;
14164                                 }
14165                         
14166                         /* test match against all servicegroup names */
14167                         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
14168 
14169                                 if(temp_servicegroup->servicegroup_name==NULL)
14170                                         continue;
14171 
14172                                 /* skip this servicegroup if it did not match the expression */
14173                                 if(regexec(&preg,temp_servicegroup->servicegroup_name,0,NULL,0))
14174                                         continue;
14175 
14176                                 found_match=TRUE;
14177 
14178                                 /* dont' add servicegroups that shouldn't be registered */
14179                                 if(temp_servicegroup->register_object==FALSE)
14180                                         continue;
14181 
14182                                 /* add servicegroup to list */
14183                                 xodtemplate_add_member_to_memberlist(list,temp_servicegroup->servicegroup_name,NULL);
14184                                 } 
14185 
14186                         /* free memory allocated to compiled regexp */
14187                         regfree(&preg);
14188                         }
14189                 
14190                 /* use standard matching... */
14191                 else{
14192 
14193                         /* return a list of all servicegroups */
14194                         if(!strcmp(temp_ptr,"*")){
14195 
14196                                 found_match=TRUE;
14197 
14198                                 for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 
14199 
14200                                         /* dont' add servicegroups that shouldn't be registered */
14201                                         if(temp_servicegroup->register_object==FALSE)
14202                                                 continue;
14203 
14204                                         /* add servicegroup to list */
14205                                         xodtemplate_add_member_to_memberlist(list,temp_servicegroup->servicegroup_name,NULL);
14206                                         }
14207                                 }
14208 
14209                         /* else this is just a single servicegroup... */
14210                         else{
14211                         
14212                                 /* this servicegroup should be excluded (rejected) */
14213                                 if(temp_ptr[0]=='!'){
14214                                         reject_item=TRUE;
14215                                         temp_ptr++;
14216                                         }
14217 
14218                                 /* find the servicegroup */
14219                                 temp_servicegroup=xodtemplate_find_real_servicegroup(temp_ptr);
14220                                 if(temp_servicegroup!=NULL){
14221 
14222                                         found_match=TRUE;
14223 
14224                                         /* add servicegroup members to proper list */
14225                                         xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_servicegroup->servicegroup_name,NULL);
14226                                         }
14227                                 }
14228                         }
14229 
14230                 if(found_match==FALSE){
14231                         logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not find any servicegroup matching '%s' (config file '%s', starting on line %d)\n",temp_ptr,xodtemplate_config_file_name(_config_file),_start_line);
14232                         break;
14233                         }
14234                 }
14235 
14236         /* free memory */
14237         my_free(servicegroup_names);
14238 
14239         if(found_match==FALSE)
14240                 return ERROR;
14241 
14242         return OK;
14243         }
14244 
14245 
14246 
14247 #ifdef NSCORE
14248 
14249 /******************************************************************/
14250 /****************** ADDITIVE INHERITANCE STUFF ********************/
14251 /******************************************************************/
14252 
14253 /* determines the value of an inherited string */
14254 int xodtemplate_get_inherited_string(int *have_template_value, char **template_value, int *have_this_value, char **this_value){
14255         char *buf=NULL;
14256 
14257         /* template has a value we should use */
14258         if(*have_template_value==TRUE){
14259 
14260                 /* template has a non-NULL value */
14261                 if(*template_value!=NULL){
14262 
14263                         /* we have no value... */
14264                         if(*this_value==NULL){
14265 
14266                                 /* use the template value only if we need a value - otherwise stay NULL */
14267                                 if(*have_this_value==FALSE){
14268                                         /* NOTE: leave leading + sign if present, as it needed during object resolution and will get stripped later */
14269                                         *this_value=(char *)strdup(*template_value);
14270                                         }
14271                                 }
14272 
14273                         /* we already have a value... */
14274                         else{
14275                                 /* our value should be added to the template value */
14276                                 if(*this_value[0]=='+'){
14277                                         if((buf=(char *)malloc(strlen(*template_value)+strlen(*this_value)+1))){
14278                                                 strcpy(buf,*template_value);
14279                                                 strcat(buf,",");
14280                                                 strcat(buf,*this_value+1);
14281                                                 my_free(*this_value);
14282                                                 *this_value=buf;
14283                                                 }
14284                                         }
14285 
14286                                 /* otherwise our value overrides/replaces the template value */
14287                                 }
14288                         }
14289 
14290                 /* template has a NULL value.... */
14291 
14292                 *have_this_value=TRUE;
14293                 }
14294 
14295         return OK;
14296         }
14297 
14298 
14299 /* removes leading + sign from various directives */
14300 int xodtemplate_clean_additive_string(char **str){
14301         char *buf=NULL;
14302 
14303         /* remove the additive symbol if present */
14304         if(*str!=NULL && *str[0]=='+'){
14305                 buf=(char *)strdup(*str+1);
14306                 my_free(*str);
14307                 *str=buf;
14308                 }
14309 
14310         return OK;
14311         }
14312 
14313 
14314 /* cleans strings which may contain additive inheritance directives */
14315 /* NOTE: this must be done after objects are resolved */
14316 int xodtemplate_clean_additive_strings(void){
14317         xodtemplate_contactgroup *temp_contactgroup=NULL;
14318         xodtemplate_hostgroup *temp_hostgroup=NULL;
14319         xodtemplate_servicegroup *temp_servicegroup=NULL;
14320         xodtemplate_servicedependency *temp_servicedependency=NULL;
14321         xodtemplate_serviceescalation *temp_serviceescalation=NULL;
14322         xodtemplate_contact *temp_contact=NULL;
14323         xodtemplate_host *temp_host=NULL;
14324         xodtemplate_service *temp_service=NULL;
14325         xodtemplate_hostdependency *temp_hostdependency=NULL;
14326         xodtemplate_hostescalation *temp_hostescalation=NULL;
14327 
14328         /* resolve all contactgroup objects */
14329         for(temp_contactgroup=xodtemplate_contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
14330                 xodtemplate_clean_additive_string(&temp_contactgroup->members);
14331                 xodtemplate_clean_additive_string(&temp_contactgroup->contactgroup_members);
14332                 }
14333 
14334         /* resolve all hostgroup objects */
14335         for(temp_hostgroup=xodtemplate_hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
14336                 xodtemplate_clean_additive_string(&temp_hostgroup->members);
14337                 xodtemplate_clean_additive_string(&temp_hostgroup->hostgroup_members);
14338                 }
14339 
14340         /* resolve all servicegroup objects */
14341         for(temp_servicegroup=xodtemplate_servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
14342                 xodtemplate_clean_additive_string(&temp_servicegroup->members);
14343                 xodtemplate_clean_additive_string(&temp_servicegroup->servicegroup_members);
14344                 }
14345 
14346         /* resolve all servicedependency objects */
14347         for(temp_servicedependency=xodtemplate_servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
14348                 xodtemplate_clean_additive_string(&temp_servicedependency->servicegroup_name);
14349                 xodtemplate_clean_additive_string(&temp_servicedependency->hostgroup_name);
14350                 xodtemplate_clean_additive_string(&temp_servicedependency->host_name);
14351                 xodtemplate_clean_additive_string(&temp_servicedependency->service_description);
14352                 xodtemplate_clean_additive_string(&temp_servicedependency->dependent_servicegroup_name);
14353                 xodtemplate_clean_additive_string(&temp_servicedependency->dependent_hostgroup_name);
14354                 xodtemplate_clean_additive_string(&temp_servicedependency->dependent_host_name);
14355                 xodtemplate_clean_additive_string(&temp_servicedependency->dependent_service_description);
14356                 }
14357 
14358         /* resolve all serviceescalation objects */
14359         for(temp_serviceescalation=xodtemplate_serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
14360                 /* 03/05/08 some vars are now handled in xodtemplate_inherit_object_properties() */
14361                 /*
14362                 xodtemplate_clean_additive_string(&temp_serviceescalation->contact_groups);
14363                 xodtemplate_clean_additive_string(&temp_serviceescalation->contacts);
14364                 */
14365                 xodtemplate_clean_additive_string(&temp_serviceescalation->servicegroup_name);
14366                 xodtemplate_clean_additive_string(&temp_serviceescalation->hostgroup_name);
14367                 xodtemplate_clean_additive_string(&temp_serviceescalation->host_name);
14368                 xodtemplate_clean_additive_string(&temp_serviceescalation->service_description);
14369                 }
14370 
14371         /* resolve all contact objects */
14372         for(temp_contact=xodtemplate_contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
14373                 xodtemplate_clean_additive_string(&temp_contact->contact_groups);
14374                 xodtemplate_clean_additive_string(&temp_contact->host_notification_commands);
14375                 xodtemplate_clean_additive_string(&temp_contact->service_notification_commands);
14376                 }
14377 
14378         /* clean all host objects */
14379         for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
14380                 xodtemplate_clean_additive_string(&temp_host->contact_groups);
14381                 xodtemplate_clean_additive_string(&temp_host->contacts);
14382                 xodtemplate_clean_additive_string(&temp_host->parents);
14383                 xodtemplate_clean_additive_string(&temp_host->host_groups);
14384                 }
14385 
14386         /* clean all service objects */
14387         for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
14388                 xodtemplate_clean_additive_string(&temp_service->contact_groups);
14389                 xodtemplate_clean_additive_string(&temp_service->contacts);
14390                 xodtemplate_clean_additive_string(&temp_service->host_name);
14391                 xodtemplate_clean_additive_string(&temp_service->hostgroup_name);
14392                 xodtemplate_clean_additive_string(&temp_service->service_groups);
14393                 }
14394 
14395         /* resolve all hostdependency objects */
14396         for(temp_hostdependency=xodtemplate_hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
14397                 xodtemplate_clean_additive_string(&temp_hostdependency->host_name);
14398                 xodtemplate_clean_additive_string(&temp_hostdependency->dependent_host_name);
14399                 xodtemplate_clean_additive_string(&temp_hostdependency->hostgroup_name);
14400                 xodtemplate_clean_additive_string(&temp_hostdependency->dependent_hostgroup_name);
14401                 }
14402 
14403         /* resolve all hostescalation objects */
14404         for(temp_hostescalation=xodtemplate_hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
14405                 /* 03/05/08 some vars are now handled in xodtemplate_inherit_object_properties() */
14406                 /*
14407                 xodtemplate_clean_additive_string(&temp_hostescalation->contact_groups);
14408                 xodtemplate_clean_additive_string(&temp_hostescalation->contacts);
14409                 */
14410                 xodtemplate_clean_additive_string(&temp_hostescalation->host_name);
14411                 xodtemplate_clean_additive_string(&temp_hostescalation->hostgroup_name);
14412                 }
14413 
14414         return OK;
14415         }
14416 #endif
14417 
14418 #endif
14419 
14420 int xodtemplate_create_escalation_condition(char *value, xodtemplate_escalation_condition *condition_head) {
14421         int result = OK;
14422         int count = 0;
14423         char *temp_ptr;
14424         xodtemplate_escalation_condition *condition_last=NULL;
14425         
14426         /* for each condition split first token : host / service */
14427         for(temp_ptr=strtok(value," ");temp_ptr;temp_ptr=strtok(NULL," ")){
14428                 xodtemplate_escalation_condition *new_condition=NULL;
14429                 if (count==0) {
14430                         /* first condition will be the head of the condition list */
14431                         new_condition=condition_head;
14432                         count++;
14433                 } else {
14434                         /* further conditions will be appended to the tail, create new condition struct */
14435                         new_condition=(xodtemplate_escalation_condition *)malloc(sizeof(xodtemplate_escalation_condition));
14436                 }
14437                
14438                 /* set default values */
14439                 new_condition->host_name=NULL;
14440                 new_condition->service_description=NULL;
14441                
14442                
14443                 new_condition->connector=EC_CONNECTOR_NO;
14444                 new_condition->escalate_on_down=FALSE;
14445                 new_condition->escalate_on_unreachable=FALSE;
14446                 new_condition->escalate_on_warning=FALSE;
14447                 new_condition->escalate_on_unknown=FALSE;
14448                 new_condition->escalate_on_critical=FALSE;
14449                 new_condition->escalate_on_ok=FALSE;
14450                
14451                 new_condition->next=NULL;
14452                
14453                 /* if it is a host condition */
14454                 if(!strcmp(temp_ptr,"host")) {
14455                         /* split and save host_name */
14456                         if ((temp_ptr=strtok(NULL,"="))==NULL
14457                                 || (new_condition->host_name=(char *)strdup(temp_ptr))==NULL) {
14458                                         result = ERROR;
14459                         }
14460                 }
14461                
14462                 /* if it is a service condition */
14463                 else if(!strcmp(temp_ptr,"service")) {
14464                         /* split and save host_name*/
14465                         if ((temp_ptr=strtok(NULL,"."))==NULL
14466                                || (new_condition->host_name=(char *)strdup(temp_ptr))==NULL) {
14467                                         result=ERROR;
14468                         }
14469                         /* split and save service_description */
14470                         if ((temp_ptr=strtok(NULL,"="))==NULL
14471                                 || (new_condition->service_description=(char *)strdup(temp_ptr))==NULL) {
14472                                         result=ERROR;
14473                         }
14474                 }
14475                        
14476                 /* here should be options separated by comma [d,u,w,c,o] */
14477                 for(temp_ptr=strtok(NULL,", ");temp_ptr;temp_ptr=strtok(NULL,", ")){
14478                         if(!strcmp(temp_ptr,"d"))
14479                                 new_condition->escalate_on_down=TRUE;
14480                         else if(!strcmp(temp_ptr,"w"))
14481                                 new_condition->escalate_on_warning=TRUE;
14482                         else if(!strcmp(temp_ptr,"c"))
14483                                 new_condition->escalate_on_critical=TRUE;
14484                         else if(!strcmp(temp_ptr,"o"))
14485                                 new_condition->escalate_on_ok=TRUE;
14486                         else if(!strcmp(temp_ptr,"u")) {
14487                                 new_condition->escalate_on_unreachable=TRUE;
14488                                 new_condition->escalate_on_unknown=TRUE;
14489                         }
14490                         else if(!strcmp(temp_ptr,"|")) {
14491                                 new_condition->connector= EC_CONNECTOR_OR;
14492                                 break; 
14493                         }
14494                         else if(!strcmp(temp_ptr,"&")) {
14495                                 new_condition->connector= EC_CONNECTOR_AND;
14496                                 break;
14497                         }
14498                         else {  // no other chars alowed, something is wrong
14499                                 logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add escalation condition ( only d,w,c,o,u,&,| are alowed after = ).\n");
14500                                 result=ERROR;
14501                                 break;
14502                         }
14503                 }
14504                
14505                 /* handle errors */
14506                 if(result==ERROR){
14507                         my_free(new_condition->host_name);
14508                         my_free(new_condition->service_description);
14509                         my_free(new_condition);
14510                         return result;
14511                 }
14512                
14513                 /* add new condition to the tail of the condition list */
14514                 if (condition_last!=NULL)
14515                         condition_last->next=new_condition;
14516                 condition_last=new_condition;
14517         }
14518         return result;
14519 }
14520 
 All Data Structures Files Functions Variables Typedefs Defines