File: objects.c

package info (click to toggle)
icinga 1.0.2-2%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 33,952 kB
  • ctags: 13,294
  • sloc: xml: 154,821; ansic: 99,198; sh: 14,585; sql: 5,852; php: 5,126; perl: 2,838; makefile: 1,268
file content (3837 lines) | stat: -rw-r--r-- 124,906 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
/*****************************************************************************
 *
 * OBJECTS.C - Object addition and search functions for Icinga
 *
 * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
 * Copyright (c) 2009-2010 Icinga Development Team (http://www.icinga.org)
 *
 * License:
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *****************************************************************************/

#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/skiplist.h"

#ifdef NSCORE
#include "../include/icinga.h"
#endif

#ifdef NSCGI
#include "../include/cgiutils.h"
#endif

/**** IMPLEMENTATION-SPECIFIC HEADER FILES ****/

#ifdef USE_XODTEMPLATE                          /* template-based routines */
#include "../xdata/xodtemplate.h"
#endif
  

host            *host_list=NULL,*host_list_tail=NULL;
service         *service_list=NULL,*service_list_tail=NULL;
contact		*contact_list=NULL,*contact_list_tail=NULL;
contactgroup	*contactgroup_list=NULL,*contactgroup_list_tail=NULL;
hostgroup	*hostgroup_list=NULL,*hostgroup_list_tail=NULL;
servicegroup    *servicegroup_list=NULL,*servicegroup_list_tail=NULL;
command         *command_list=NULL,*command_list_tail=NULL;
timeperiod      *timeperiod_list=NULL,*timeperiod_list_tail=NULL;
serviceescalation *serviceescalation_list=NULL,*serviceescalation_list_tail=NULL;
servicedependency *servicedependency_list=NULL,*servicedependency_list_tail=NULL;
hostdependency  *hostdependency_list=NULL,*hostdependency_list_tail=NULL;
hostescalation  *hostescalation_list=NULL,*hostescalation_list_tail=NULL;

skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];


#ifdef NSCORE
/* keep this for compatibility */
int __nagios_object_structure_version=CURRENT_OBJECT_STRUCTURE_VERSION;
/* this will be used for IDOUtils, Michael Friedrich, 05-19-2010 */
int __icinga_object_structure_version=CURRENT_OBJECT_STRUCTURE_VERSION;
extern int use_precached_objects;
#endif



/******************************************************************/
/******* TOP-LEVEL HOST CONFIGURATION DATA INPUT FUNCTION *********/
/******************************************************************/


/* read all host configuration data from external source */
int read_object_config_data(char *main_config_file, int options, int cache, int precache){
	int result=OK;

	/* initialize object skiplists */
	init_object_skiplists();

	/********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
#ifdef USE_XODTEMPLATE
	/* read in data from all text host config files (template-based) */
	result=xodtemplate_read_config_data(main_config_file,options,cache,precache);
	if(result!=OK)
		return ERROR;
#endif

	return result;
        }



/******************************************************************/
/******************** SKIPLIST FUNCTIONS **************************/
/******************************************************************/

int init_object_skiplists(void){
	int x=0;

	for(x=0;x<NUM_OBJECT_SKIPLISTS;x++)
		object_skiplists[x]=NULL;

	object_skiplists[HOST_SKIPLIST]=skiplist_new(15,0.5,FALSE,FALSE,skiplist_compare_host);
	object_skiplists[SERVICE_SKIPLIST]=skiplist_new(15,0.5,FALSE,FALSE,skiplist_compare_service);

	object_skiplists[COMMAND_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_command);
	object_skiplists[TIMEPERIOD_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_timeperiod);
	object_skiplists[CONTACT_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_contact);
	object_skiplists[CONTACTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_contactgroup);
	object_skiplists[HOSTGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_hostgroup);
	object_skiplists[SERVICEGROUP_SKIPLIST]=skiplist_new(10,0.5,FALSE,FALSE,skiplist_compare_servicegroup);

	object_skiplists[HOSTESCALATION_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_hostescalation);
	object_skiplists[SERVICEESCALATION_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_serviceescalation);
	object_skiplists[HOSTDEPENDENCY_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_hostdependency);
	object_skiplists[SERVICEDEPENDENCY_SKIPLIST]=skiplist_new(15,0.5,TRUE,FALSE,skiplist_compare_servicedependency);

	return OK;
	}



int free_object_skiplists(void){
	int x=0;

	for(x=0;x<NUM_OBJECT_SKIPLISTS;x++)
		skiplist_free(&object_skiplists[x]);

	return OK;
	}


int skiplist_compare_text(const char *val1a, const char *val1b, const char *val2a, const char *val2b){
	int result=0;

	/* check first name */
	if(val1a==NULL && val2a==NULL)
		result=0;
	else if(val1a==NULL)
		result=1;
	else if(val2a==NULL)
		result=-1;
	else
		result=strcmp(val1a,val2a);

	/* check second name if necessary */
	if(result==0){
		if(val1b==NULL && val2b==NULL)
			result=0;
		else if(val1b==NULL)
			result=1;
		else if(val2b==NULL)
			result=-1;
		else
			result=strcmp(val1b,val2b);
	        }

	return result;
        }


int skiplist_compare_host(void *a, void *b){
	host *oa=NULL;
	host *ob=NULL;

	oa=(host *)a;
	ob=(host *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
	}


int skiplist_compare_service(void *a, void *b){
	service *oa=NULL;
	service *ob=NULL;

	oa=(service *)a;
	ob=(service *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->host_name,oa->description,ob->host_name,ob->description);
	}


int skiplist_compare_command(void *a, void *b){
	command *oa=NULL;
	command *ob=NULL;

	oa=(command *)a;
	ob=(command *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
	}


int skiplist_compare_timeperiod(void *a, void *b){
	timeperiod *oa=NULL;
	timeperiod *ob=NULL;

	oa=(timeperiod *)a;
	ob=(timeperiod *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
	}


int skiplist_compare_contact(void *a, void *b){
	contact *oa=NULL;
	contact *ob=NULL;

	oa=(contact *)a;
	ob=(contact *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->name,NULL,ob->name,NULL);
	}


int skiplist_compare_contactgroup(void *a, void *b){
	contactgroup *oa=NULL;
	contactgroup *ob=NULL;

	oa=(contactgroup *)a;
	ob=(contactgroup *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
	}


int skiplist_compare_hostgroup(void *a, void *b){
	hostgroup *oa=NULL;
	hostgroup *ob=NULL;

	oa=(hostgroup *)a;
	ob=(hostgroup *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
	}


int skiplist_compare_servicegroup(void *a, void *b){
	servicegroup *oa=NULL;
	servicegroup *ob=NULL;

	oa=(servicegroup *)a;
	ob=(servicegroup *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->group_name,NULL,ob->group_name,NULL);
	}


int skiplist_compare_hostescalation(void *a, void *b){
	hostescalation *oa=NULL;
	hostescalation *ob=NULL;

	oa=(hostescalation *)a;
	ob=(hostescalation *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->host_name,NULL,ob->host_name,NULL);
	}


int skiplist_compare_serviceescalation(void *a, void *b){
	serviceescalation *oa=NULL;
	serviceescalation *ob=NULL;

	oa=(serviceescalation *)a;
	ob=(serviceescalation *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->host_name,oa->description,ob->host_name,ob->description);
	}


int skiplist_compare_hostdependency(void *a, void *b){
	hostdependency *oa=NULL;
	hostdependency *ob=NULL;

	oa=(hostdependency *)a;
	ob=(hostdependency *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->dependent_host_name,NULL,ob->dependent_host_name,NULL);
	}


int skiplist_compare_servicedependency(void *a, void *b){
	servicedependency *oa=NULL;
	servicedependency *ob=NULL;

	oa=(servicedependency *)a;
	ob=(servicedependency *)b;

	if(oa==NULL && ob==NULL)
		return 0;
	if(oa==NULL)
		return 1;
	if(ob==NULL)
		return -1;

	return skiplist_compare_text(oa->dependent_host_name,oa->dependent_service_description,ob->dependent_host_name,ob->dependent_service_description);
	}


int get_host_count(void){

	if(object_skiplists[HOST_SKIPLIST])
		return object_skiplists[HOST_SKIPLIST]->items;

	return 0;
	}


int get_service_count(void){

	if(object_skiplists[SERVICE_SKIPLIST])
		return object_skiplists[SERVICE_SKIPLIST]->items;

	return 0;
	}




/******************************************************************/
/**************** OBJECT ADDITION FUNCTIONS ***********************/
/******************************************************************/



/* add a new timeperiod to the list in memory */
timeperiod *add_timeperiod(char *name,char *alias){
	timeperiod *new_timeperiod=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if((name==NULL || !strcmp(name,"")) || (alias==NULL || !strcmp(alias,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Name or alias for timeperiod is NULL\n");
		return NULL;
	        }

	/* allocate memory for the new timeperiod */
	if((new_timeperiod=calloc(1, sizeof(timeperiod)))==NULL)
		return NULL;

	/* copy string vars */
	if((new_timeperiod->name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_timeperiod->alias=(char *)strdup(alias))==NULL)
		result=ERROR;

	/* add new timeperiod to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[TIMEPERIOD_SKIPLIST],(void *)new_timeperiod);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Timeperiod '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add timeperiod '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_timeperiod->alias);
		my_free(new_timeperiod->name);
		my_free(new_timeperiod);
		return NULL;
	        }

	/* timeperiods are registered alphabetically, so add new items to tail of list */
	if(timeperiod_list==NULL){
		timeperiod_list=new_timeperiod;
		timeperiod_list_tail=timeperiod_list;
		}
	else{
		timeperiod_list_tail->next=new_timeperiod;
		timeperiod_list_tail=new_timeperiod;
		}

	return new_timeperiod;
        }




/* adds a new exclusion to a timeperiod */
timeperiodexclusion *add_exclusion_to_timeperiod(timeperiod *period, char *name){
	timeperiodexclusion *new_timeperiodexclusion=NULL;

	/* make sure we have enough data */
	if(period==NULL || name==NULL)
		return NULL;

	if((new_timeperiodexclusion=(timeperiodexclusion *)malloc(sizeof(timeperiodexclusion)))==NULL)
		return NULL;

	new_timeperiodexclusion->timeperiod_name=(char *)strdup(name);

	new_timeperiodexclusion->next=period->exclusions;
	period->exclusions=new_timeperiodexclusion;

	return new_timeperiodexclusion;
	}




/* add a new timerange to a timeperiod */
timerange *add_timerange_to_timeperiod(timeperiod *period, int day, unsigned long start_time, unsigned long end_time){
	timerange *new_timerange=NULL;

	/* make sure we have the data we need */
	if(period==NULL)
		return NULL;

	if(day<0 || day>6){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Day %d is not valid for timeperiod '%s'\n",day,period->name);
		return NULL;
	        }
	if(start_time<0 || start_time>86400){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Start time %lu on day %d is not valid for timeperiod '%s'\n",start_time,day,period->name);
		return NULL;
	        }
	if(end_time<0 || end_time>86400){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: End time %lu on day %d is not value for timeperiod '%s'\n",end_time,day,period->name);
		return NULL;
	        }

	/* allocate memory for the new time range */
	if((new_timerange=malloc(sizeof(timerange)))==NULL)
		return NULL;

	new_timerange->range_start=start_time;
	new_timerange->range_end=end_time;

	/* add the new time range to the head of the range list for this day */
	new_timerange->next=period->days[day];
	period->days[day]=new_timerange;

	return new_timerange;
        }


/* add a new exception to a timeperiod */
daterange *add_exception_to_timeperiod(timeperiod *period, int type, int syear, int smon, int smday, int swday, int swday_offset, int eyear, int emon, int emday, int ewday, int ewday_offset, int skip_interval){
	daterange *new_daterange=NULL;

	/* make sure we have the data we need */
	if(period==NULL)
		return NULL;

	/* allocate memory for the date range range */
	if((new_daterange=malloc(sizeof(daterange)))==NULL)
		return NULL;

	new_daterange->times=NULL;
	new_daterange->next=NULL;

	new_daterange->type=type;
	new_daterange->syear=syear;
	new_daterange->smon=smon;
	new_daterange->smday=smday;
	new_daterange->swday=swday;
	new_daterange->swday_offset=swday_offset;
	new_daterange->eyear=eyear;
	new_daterange->emon=emon;
	new_daterange->emday=emday;
	new_daterange->ewday=ewday;
	new_daterange->ewday_offset=ewday_offset;
	new_daterange->skip_interval=skip_interval;

	/* add the new date range to the head of the range list for this exception type */
	new_daterange->next=period->exceptions[type];
	period->exceptions[type]=new_daterange;

	return new_daterange;
        }



/* add a new timerange to a daterange */
timerange *add_timerange_to_daterange(daterange *drange, unsigned long start_time, unsigned long end_time){
	timerange *new_timerange=NULL;

	/* make sure we have the data we need */
	if(drange==NULL)
		return NULL;

	if(start_time<0 || start_time>86400){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Start time %lu is not valid for timeperiod\n",start_time);
		return NULL;
	        }
	if(end_time<0 || end_time>86400){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: End time %lu is not value for timeperiod\n",end_time);
		return NULL;
	        }

	/* allocate memory for the new time range */
	if((new_timerange=malloc(sizeof(timerange)))==NULL)
		return NULL;

	new_timerange->range_start=start_time;
	new_timerange->range_end=end_time;

	/* add the new time range to the head of the range list for this date range */
	new_timerange->next=drange->times;
	drange->times=new_timerange;

	return new_timerange;
        }



/* add a new host definition */
host *add_host(char *name, char *display_name, char *alias, char *address, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notify_up, int notify_down, int notify_unreachable, int notify_flapping, int notify_downtime, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_up, int flap_detection_on_down, int flap_detection_on_unreachable, int stalk_on_up, int stalk_on_down, int stalk_on_unreachable, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess_over_host){
	host *new_host=NULL;
	int result=OK;
#ifdef NSCORE
	int x=0;
#endif

	/* make sure we have the data we need */
	if((name==NULL || !strcmp(name,"")) || (address==NULL || !strcmp(address,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host name or address is NULL\n");
		return NULL;
	        }

	/* check values */
	if(max_attempts<=0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid max_check_attempts value for host '%s'\n",name);
		return NULL;
	        }
	if(check_interval<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid check_interval value for host '%s'\n",name);
		return NULL;
	        }
	if(notification_interval<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid notification_interval value for host '%s'\n",name);
		return NULL;
	        }
	if(first_notification_delay<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid first_notification_delay value for host '%s'\n",name);
		return NULL;
	        }
	if(freshness_threshold<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid freshness_threshold value for host '%s'\n",name);
		return NULL;
	        }

	/* allocate memory for a new host */
	if((new_host=(host *)calloc(1, sizeof(host)))==NULL)
		return NULL;

	/* duplicate string vars */
	if((new_host->name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_host->display_name=(char *)strdup((display_name==NULL)?name:display_name))==NULL)
		result=ERROR;
	if((new_host->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
		result=ERROR;
	if((new_host->address=(char *)strdup(address))==NULL)
		result=ERROR;
	if(check_period){
		if((new_host->check_period=(char *)strdup(check_period))==NULL)
			result=ERROR;
	        }
	if(notification_period){
		if((new_host->notification_period=(char *)strdup(notification_period))==NULL)
			result=ERROR;
	        }
	if(check_command){
		if((new_host->host_check_command=(char *)strdup(check_command))==NULL)
			result=ERROR;
	        }
	if(event_handler){
		if((new_host->event_handler=(char *)strdup(event_handler))==NULL)
			result=ERROR;
	        }
	if(failure_prediction_options){
		if((new_host->failure_prediction_options=(char *)strdup(failure_prediction_options))==NULL)
			result=ERROR;
	        }
	if(notes){
		if((new_host->notes=(char *)strdup(notes))==NULL)
			result=ERROR;
	        }
	if(notes_url){
		if((new_host->notes_url=(char *)strdup(notes_url))==NULL)
			result=ERROR;
	        }
	if(action_url){
		if((new_host->action_url=(char *)strdup(action_url))==NULL)
			result=ERROR;
	        }
	if(icon_image){
		if((new_host->icon_image=(char *)strdup(icon_image))==NULL)
			result=ERROR;
	        }
	if(icon_image_alt){
		if((new_host->icon_image_alt=(char *)strdup(icon_image_alt))==NULL)
			result=ERROR;
	        }
	if(vrml_image){
		if((new_host->vrml_image=(char *)strdup(vrml_image))==NULL)
			result=ERROR;
	        }
	if(statusmap_image){
		if((new_host->statusmap_image=(char *)strdup(statusmap_image))==NULL)
			result=ERROR;
	        }


	/* duplicate non-string vars */
	new_host->max_attempts=max_attempts;
	new_host->check_interval=check_interval;
	new_host->retry_interval=retry_interval;
	new_host->notification_interval=notification_interval;
	new_host->first_notification_delay=first_notification_delay;
	new_host->notify_on_recovery=(notify_up>0)?TRUE:FALSE;
	new_host->notify_on_down=(notify_down>0)?TRUE:FALSE;
	new_host->notify_on_unreachable=(notify_unreachable>0)?TRUE:FALSE;
	new_host->notify_on_flapping=(notify_flapping>0)?TRUE:FALSE;
	new_host->notify_on_downtime=(notify_downtime>0)?TRUE:FALSE;
	new_host->flap_detection_enabled=(flap_detection_enabled>0)?TRUE:FALSE;
	new_host->low_flap_threshold=low_flap_threshold;
	new_host->high_flap_threshold=high_flap_threshold;
	new_host->flap_detection_on_up=(flap_detection_on_up>0)?TRUE:FALSE;
	new_host->flap_detection_on_down=(flap_detection_on_down>0)?TRUE:FALSE;
	new_host->flap_detection_on_unreachable=(flap_detection_on_unreachable>0)?TRUE:FALSE;
	new_host->stalk_on_up=(stalk_on_up>0)?TRUE:FALSE;
	new_host->stalk_on_down=(stalk_on_down>0)?TRUE:FALSE;
	new_host->stalk_on_unreachable=(stalk_on_unreachable>0)?TRUE:FALSE;
	new_host->process_performance_data=(process_perfdata>0)?TRUE:FALSE;
	new_host->check_freshness=(check_freshness>0)?TRUE:FALSE;
	new_host->freshness_threshold=freshness_threshold;
	new_host->checks_enabled=(checks_enabled>0)?TRUE:FALSE;
	new_host->accept_passive_host_checks=(accept_passive_checks>0)?TRUE:FALSE;
	new_host->event_handler_enabled=(event_handler_enabled>0)?TRUE:FALSE;
	new_host->failure_prediction_enabled=(failure_prediction_enabled>0)?TRUE:FALSE;
	new_host->x_2d=x_2d;
	new_host->y_2d=y_2d;
	new_host->have_2d_coords=(have_2d_coords>0)?TRUE:FALSE;
	new_host->x_3d=x_3d;
	new_host->y_3d=y_3d;
	new_host->z_3d=z_3d;
	new_host->have_3d_coords=(have_3d_coords>0)?TRUE:FALSE;
	new_host->should_be_drawn=(should_be_drawn>0)?TRUE:FALSE;
	new_host->obsess_over_host=(obsess_over_host>0)?TRUE:FALSE;
	new_host->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
	new_host->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
#ifdef NSCORE
	new_host->current_state=initial_state;
	new_host->current_event_id=0L;
	new_host->last_event_id=0L;
	new_host->current_problem_id=0L;
	new_host->last_problem_id=0L;
	new_host->last_state=initial_state;
	new_host->last_hard_state=initial_state;
	new_host->check_type=HOST_CHECK_ACTIVE;
	new_host->last_host_notification=(time_t)0;
	new_host->next_host_notification=(time_t)0;
	new_host->next_check=(time_t)0;
	new_host->should_be_scheduled=TRUE;
	new_host->last_check=(time_t)0;
	new_host->current_attempt=(initial_state==HOST_UP)?1:max_attempts;
	new_host->state_type=HARD_STATE;
	new_host->execution_time=0.0;
	new_host->is_executing=FALSE;
	new_host->latency=0.0;
	new_host->last_state_change=(time_t)0;
	new_host->last_hard_state_change=(time_t)0;
	new_host->last_time_up=(time_t)0;
	new_host->last_time_down=(time_t)0;
	new_host->last_time_unreachable=(time_t)0;
	new_host->has_been_checked=FALSE;
	new_host->is_being_freshened=FALSE;
	new_host->problem_has_been_acknowledged=FALSE;
	new_host->acknowledgement_type=ACKNOWLEDGEMENT_NONE;
	new_host->notifications_enabled=(notifications_enabled>0)?TRUE:FALSE;
	new_host->notified_on_down=FALSE;
	new_host->notified_on_unreachable=FALSE;
	new_host->current_notification_number=0;
#ifdef USE_ST_BASED_ESCAL_RANGES
	new_host->current_down_notification_number=0;
	new_host->current_unreachable_notification_number=0;
#endif
	new_host->current_notification_id=0L;
	new_host->no_more_notifications=FALSE;
	new_host->check_flapping_recovery_notification=FALSE;
	new_host->scheduled_downtime_depth=0;
	new_host->check_options=CHECK_OPTION_NONE;
	new_host->pending_flex_downtime=0;
	for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
		new_host->state_history[x]=STATE_OK;
	new_host->state_history_index=0;
	new_host->last_state_history_update=(time_t)0;
	new_host->is_flapping=FALSE;
	new_host->flapping_comment_id=0;
	new_host->percent_state_change=0.0;
	new_host->total_services=0;
	new_host->total_service_check_interval=0L;
	new_host->modified_attributes=MODATTR_NONE;
	new_host->circular_path_checked=FALSE;
	new_host->contains_circular_path=FALSE;
#endif

	/* add new host to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[HOST_SKIPLIST],(void *)new_host);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
#ifdef NSCORE
		my_free(new_host->plugin_output);
		my_free(new_host->long_plugin_output);
		my_free(new_host->perf_data);
#endif
		my_free(new_host->statusmap_image);
		my_free(new_host->vrml_image);
		my_free(new_host->icon_image_alt);
		my_free(new_host->icon_image);
		my_free(new_host->action_url);
		my_free(new_host->notes_url);
		my_free(new_host->notes);
		my_free(new_host->failure_prediction_options);
		my_free(new_host->event_handler);
		my_free(new_host->host_check_command);
		my_free(new_host->notification_period);
		my_free(new_host->check_period);
		my_free(new_host->address);
		my_free(new_host->alias);
		my_free(new_host->display_name);
		my_free(new_host->name);
		my_free(new_host);
		return NULL;
	        }

	/* hosts are sorted alphabetically, so add new items to tail of list */
	if(host_list==NULL){
		host_list=new_host;
		host_list_tail=host_list;
		}
	else{
		host_list_tail->next=new_host;
		host_list_tail=new_host;
		}

	return new_host;
	}



hostsmember *add_parent_host_to_host(host *hst,char *host_name){
	hostsmember *new_hostsmember=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(hst==NULL || host_name==NULL || !strcmp(host_name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host is NULL or parent host name is NULL\n");
		return NULL;
	        }

	/* a host cannot be a parent/child of itself */
	if(!strcmp(host_name,hst->name)){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host '%s' cannot be a child/parent of itself\n",hst->name);
		return NULL;
	        }

	/* allocate memory */
	if((new_hostsmember=(hostsmember *)calloc(1, sizeof(hostsmember)))==NULL)
		return NULL;

	/* duplicate string vars */
	if((new_hostsmember->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_hostsmember->host_name);
		my_free(new_hostsmember);
		return NULL;
	        }

	/* add the parent host entry to the host definition */
	new_hostsmember->next=hst->parent_hosts;
	hst->parent_hosts=new_hostsmember;

	return new_hostsmember;
        }



hostsmember *add_child_link_to_host(host *hst, host *child_ptr){
	hostsmember *new_hostsmember=NULL;

	/* make sure we have the data we need */
	if(hst==NULL || child_ptr==NULL)
		return NULL;

	/* allocate memory */
	if((new_hostsmember=(hostsmember *)malloc(sizeof(hostsmember)))==NULL)
		return NULL;

	/* initialize values */
	new_hostsmember->host_name=NULL;
#ifdef NSCORE
	new_hostsmember->host_ptr=child_ptr;
#endif

	/* add the child entry to the host definition */
	new_hostsmember->next=hst->child_hosts;
	hst->child_hosts=new_hostsmember;

	return new_hostsmember;
        }



servicesmember *add_service_link_to_host(host *hst, service *service_ptr){
	servicesmember *new_servicesmember=NULL;

	/* make sure we have the data we need */
	if(hst==NULL || service_ptr==NULL)
		return NULL;

	/* allocate memory */
	if((new_servicesmember=(servicesmember *)calloc(1, sizeof(servicesmember)))==NULL)
		return NULL;

	/* initialize values */
#ifdef NSCORE
	new_servicesmember->service_ptr=service_ptr;
#endif

	/* add the child entry to the host definition */
	new_servicesmember->next=hst->services;
	hst->services=new_servicesmember;

	return new_servicesmember;
        }



/* add a new contactgroup to a host */
contactgroupsmember *add_contactgroup_to_host(host *hst, char *group_name){
	contactgroupsmember *new_contactgroupsmember=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(hst==NULL || (group_name==NULL || !strcmp(group_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host or contactgroup member is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_contactgroupsmember=calloc(1, sizeof(contactgroupsmember)))==NULL)
		return NULL;
	
	/* duplicate string vars */
	if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactgroupsmember->group_name);
		my_free(new_contactgroupsmember);
		return NULL;
	        }
	
	/* add the new member to the head of the member list */
	new_contactgroupsmember->next=hst->contact_groups;
	hst->contact_groups=new_contactgroupsmember;;

	return new_contactgroupsmember;
        }



/* adds a contact to a host */
contactsmember *add_contact_to_host(host *hst, char *contact_name){

	return add_contact_to_object(&hst->contacts,contact_name);
        }



/* adds a custom variable to a host */
customvariablesmember *add_custom_variable_to_host(host *hst, char *varname, char *varvalue){

	return add_custom_variable_to_object(&hst->custom_variables,varname,varvalue);
        }



/* add a new host group to the list in memory */
hostgroup *add_hostgroup(char *name, char *alias, char *notes, char *notes_url, char *action_url){
	hostgroup *new_hostgroup=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(name==NULL || !strcmp(name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory */
	if((new_hostgroup=(hostgroup *)calloc(1, sizeof(hostgroup)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_hostgroup->group_name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_hostgroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
		result=ERROR;
	if(notes){
		if((new_hostgroup->notes=(char *)strdup(notes))==NULL)
			result=ERROR;
		}
	if(notes_url){
		if((new_hostgroup->notes_url=(char *)strdup(notes_url))==NULL)
			result=ERROR;
		}
	if(action_url){
		if((new_hostgroup->action_url=(char *)strdup(action_url))==NULL)
			result=ERROR;
		}

	/* add new host group to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[HOSTGROUP_SKIPLIST],(void *)new_hostgroup);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add hostgroup '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_hostgroup->alias);
		my_free(new_hostgroup->group_name);
		my_free(new_hostgroup);
		return NULL;
	        }

	/* hostgroups are sorted alphabetically, so add new items to tail of list */
	if(hostgroup_list==NULL){
		hostgroup_list=new_hostgroup;
		hostgroup_list_tail=hostgroup_list;
		}
	else{
		hostgroup_list_tail->next=new_hostgroup;
		hostgroup_list_tail=new_hostgroup;
		}

	return new_hostgroup;
	}


/* add a new host to a host group */
hostsmember *add_host_to_hostgroup(hostgroup *temp_hostgroup, char *host_name){
	hostsmember *new_member=NULL;
	hostsmember *last_member=NULL;
	hostsmember *temp_member=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(temp_hostgroup==NULL || (host_name==NULL || !strcmp(host_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Hostgroup or group member is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_member=calloc(1, sizeof(hostsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_member->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_member->host_name);
		my_free(new_member);
		return NULL;
	        }
	
	/* add the new member to the member list, sorted by host name */
	last_member=temp_hostgroup->members;
	for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
		if(strcmp(new_member->host_name,temp_member->host_name)<0){
			new_member->next=temp_member;
			if(temp_member==temp_hostgroup->members)
				temp_hostgroup->members=new_member;
			else
				last_member->next=new_member;
			break;
		        }
		else
			last_member=temp_member;
	        }
	if(temp_hostgroup->members==NULL){
		new_member->next=NULL;
		temp_hostgroup->members=new_member;
	        }
	else if(temp_member==NULL){
		new_member->next=NULL;
		last_member->next=new_member;
	        }

	return new_member;
        }


/* add a new service group to the list in memory */
servicegroup *add_servicegroup(char *name, char *alias, char *notes, char *notes_url, char *action_url){
	servicegroup *new_servicegroup=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(name==NULL || !strcmp(name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory */
	if((new_servicegroup=(servicegroup *)calloc(1, sizeof(servicegroup)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_servicegroup->group_name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_servicegroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
		result=ERROR;
	if(notes){
		if((new_servicegroup->notes=(char *)strdup(notes))==NULL)
			result=ERROR;
		}
	if(notes_url){
		if((new_servicegroup->notes_url=(char *)strdup(notes_url))==NULL)
			result=ERROR;
		}
	if(action_url){
		if((new_servicegroup->action_url=(char *)strdup(action_url))==NULL)
			result=ERROR;
		}

	/* add new service group to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[SERVICEGROUP_SKIPLIST],(void *)new_servicegroup);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add servicegroup '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_servicegroup->alias);
		my_free(new_servicegroup->group_name);
		my_free(new_servicegroup);
		return NULL;
	        }

	/* servicegroups are sorted alphabetically, so add new items to tail of list */
	if(servicegroup_list==NULL){
		servicegroup_list=new_servicegroup;
		servicegroup_list_tail=servicegroup_list;
		}
	else{
		servicegroup_list_tail->next=new_servicegroup;
		servicegroup_list_tail=new_servicegroup;
		}

	return new_servicegroup;
	}


/* add a new service to a service group */
servicesmember *add_service_to_servicegroup(servicegroup *temp_servicegroup, char *host_name, char *svc_description){
	servicesmember *new_member=NULL;
	servicesmember *last_member=NULL;
	servicesmember *temp_member=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(temp_servicegroup==NULL || (host_name==NULL || !strcmp(host_name,"")) || (svc_description==NULL || !strcmp(svc_description,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Servicegroup or group member is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_member=calloc(1, sizeof(servicesmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_member->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if((new_member->service_description=(char *)strdup(svc_description))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_member->service_description);
		my_free(new_member->host_name);
		my_free(new_member);
		return NULL;
	        }
	
	/* add new member to member list, sorted by host name then service description */
	last_member=temp_servicegroup->members;
	for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){

		if(strcmp(new_member->host_name,temp_member->host_name)<0){
			new_member->next=temp_member;
			if(temp_member==temp_servicegroup->members)
				temp_servicegroup->members=new_member;
			else
				last_member->next=new_member;
			break;
		        }

		else if(strcmp(new_member->host_name,temp_member->host_name)==0 && strcmp(new_member->service_description,temp_member->service_description)<0){
			new_member->next=temp_member;
			if(temp_member==temp_servicegroup->members)
				temp_servicegroup->members=new_member;
			else
				last_member->next=new_member;
			break;
		        }

		else
			last_member=temp_member;
	        }
	if(temp_servicegroup->members==NULL){
		new_member->next=NULL;
		temp_servicegroup->members=new_member;
	        }
	else if(temp_member==NULL){
		new_member->next=NULL;
		last_member->next=new_member;
	        }

	return new_member;
        }


/* add a new contact to the list in memory */
contact *add_contact(char *name,char *alias, char *email, char *pager, char **addresses, char *svc_notification_period, char *host_notification_period,int notify_service_ok,int notify_service_critical,int notify_service_warning, int notify_service_unknown, int notify_service_flapping, int notify_service_downtime, int notify_host_up, int notify_host_down, int notify_host_unreachable, int notify_host_flapping, int notify_host_downtime, int host_notifications_enabled, int service_notifications_enabled, int can_submit_commands, int retain_status_information, int retain_nonstatus_information){
	contact *new_contact=NULL;
	int x=0;
	int result=OK;

	/* make sure we have the data we need */
	if(name==NULL || !strcmp(name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact name is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new contact */
	if((new_contact=(contact *)calloc(1, sizeof(contact)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contact->name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_contact->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
		result=ERROR;
	if(email){
		if((new_contact->email=(char *)strdup(email))==NULL)
			result=ERROR;
	        }
	if(pager){
		if((new_contact->pager=(char *)strdup(pager))==NULL)
			result=ERROR;
	        }
	if(svc_notification_period){
		if((new_contact->service_notification_period=(char *)strdup(svc_notification_period))==NULL)
			result=ERROR;
	        }
	if(host_notification_period){
		if((new_contact->host_notification_period=(char *)strdup(host_notification_period))==NULL)
			result=ERROR;
	        }
	if(addresses){
		for(x=0;x<MAX_CONTACT_ADDRESSES;x++){
			if(addresses[x]){
				if((new_contact->address[x]=(char *)strdup(addresses[x]))==NULL)
					result=ERROR;
			        }
		        }
	        }

	new_contact->notify_on_service_recovery=(notify_service_ok>0)?TRUE:FALSE;
	new_contact->notify_on_service_critical=(notify_service_critical>0)?TRUE:FALSE;
	new_contact->notify_on_service_warning=(notify_service_warning>0)?TRUE:FALSE;
	new_contact->notify_on_service_unknown=(notify_service_unknown>0)?TRUE:FALSE;
	new_contact->notify_on_service_flapping=(notify_service_flapping>0)?TRUE:FALSE;
	new_contact->notify_on_service_downtime=(notify_service_downtime>0)?TRUE:FALSE;
	new_contact->notify_on_host_recovery=(notify_host_up>0)?TRUE:FALSE;
	new_contact->notify_on_host_down=(notify_host_down>0)?TRUE:FALSE;
	new_contact->notify_on_host_unreachable=(notify_host_unreachable>0)?TRUE:FALSE;
	new_contact->notify_on_host_flapping=(notify_host_flapping>0)?TRUE:FALSE;
	new_contact->notify_on_host_downtime=(notify_host_downtime>0)?TRUE:FALSE;
	new_contact->host_notifications_enabled=(host_notifications_enabled>0)?TRUE:FALSE;
	new_contact->service_notifications_enabled=(service_notifications_enabled>0)?TRUE:FALSE;
	new_contact->can_submit_commands=(can_submit_commands>0)?TRUE:FALSE;
	new_contact->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
	new_contact->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
#ifdef NSCORE
	new_contact->last_host_notification=(time_t)0L;
	new_contact->last_service_notification=(time_t)0L;
	new_contact->modified_attributes=MODATTR_NONE;
	new_contact->modified_host_attributes=MODATTR_NONE;
	new_contact->modified_service_attributes=MODATTR_NONE;

	new_contact->host_notification_period_ptr=NULL;
	new_contact->service_notification_period_ptr=NULL;
	new_contact->contactgroups_ptr=NULL;
#endif

	/* add new contact to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[CONTACT_SKIPLIST],(void *)new_contact);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		for(x=0;x<MAX_CONTACT_ADDRESSES;x++)
			my_free(new_contact->address[x]);
		my_free(new_contact->name);
		my_free(new_contact->alias);
		my_free(new_contact->email);
		my_free(new_contact->pager);
		my_free(new_contact->service_notification_period);
		my_free(new_contact->host_notification_period);
		my_free(new_contact);
		return NULL;
	        }

	/* contacts are sorted alphabetically, so add new items to tail of list */
	if(contact_list==NULL){
		contact_list=new_contact;
		contact_list_tail=contact_list;
		}
	else{
		contact_list_tail->next=new_contact;
		contact_list_tail=new_contact;
		}

	return new_contact;
	}



/* adds a host notification command to a contact definition */
commandsmember *add_host_notification_command_to_contact(contact *cntct,char *command_name){
	commandsmember *new_commandsmember=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(cntct==NULL || (command_name==NULL || !strcmp(command_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact or host notification command is NULL\n");
		return NULL;
	        }

	/* allocate memory */
	if((new_commandsmember=calloc(1, sizeof(commandsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_commandsmember->command=(char *)strdup(command_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_commandsmember->command);
		my_free(new_commandsmember);
		return NULL;
	        }

	/* add the notification command */
	new_commandsmember->next=cntct->host_notification_commands;
	cntct->host_notification_commands=new_commandsmember;

	return new_commandsmember;
        }



/* adds a service notification command to a contact definition */
commandsmember *add_service_notification_command_to_contact(contact *cntct,char *command_name){
	commandsmember *new_commandsmember=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(cntct==NULL || (command_name==NULL || !strcmp(command_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact or service notification command is NULL\n");
		return NULL;
	        }

	/* allocate memory */
	if((new_commandsmember=calloc(1, sizeof(commandsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_commandsmember->command=(char *)strdup(command_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_commandsmember->command);
		my_free(new_commandsmember);
		return NULL;
	        }

	/* add the notification command */
	new_commandsmember->next=cntct->service_notification_commands;
	cntct->service_notification_commands=new_commandsmember;

	return new_commandsmember;
        }



/* adds a custom variable to a contact */
customvariablesmember *add_custom_variable_to_contact(contact *cntct, char *varname, char *varvalue){

	return add_custom_variable_to_object(&cntct->custom_variables,varname,varvalue);
        }



/* add a new contact group to the list in memory */
contactgroup *add_contactgroup(char *name,char *alias){
	contactgroup *new_contactgroup=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(name==NULL || !strcmp(name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new contactgroup entry */
	if((new_contactgroup=calloc(1, sizeof(contactgroup)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contactgroup->group_name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_contactgroup->alias=(char *)strdup((alias==NULL)?name:alias))==NULL)
		result=ERROR;

	/* add new contact group to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[CONTACTGROUP_SKIPLIST],(void *)new_contactgroup);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contactgroup '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactgroup->alias);
		my_free(new_contactgroup->group_name);
		my_free(new_contactgroup);
		return NULL;
	        }

	/* contactgroups are sorted alphabetically, so add new items to tail of list */
	if(contactgroup_list==NULL){
		contactgroup_list=new_contactgroup;
		contactgroup_list_tail=contactgroup_list;
		}
	else{
		contactgroup_list_tail->next=new_contactgroup;
		contactgroup_list_tail=new_contactgroup;
		}

	return new_contactgroup;
	}



/* add a new member to a contact group */
contactsmember *add_contact_to_contactgroup(contactgroup *grp, char *contact_name){
	contactsmember *new_contactsmember=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(grp==NULL || (contact_name==NULL || !strcmp(contact_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contactgroup or contact name is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_contactsmember=calloc(1, sizeof(contactsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contactsmember->contact_name=(char *)strdup(contact_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactsmember->contact_name);
		my_free(new_contactsmember);
		return NULL;
	        }
	
	/* add the new member to the head of the member list */
	new_contactsmember->next=grp->members;
	grp->members=new_contactsmember;

	return new_contactsmember;
        }



/* add a new service to the list in memory */
service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notify_downtime, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_ok, int flap_detection_on_warning, int flap_detection_on_unknown, int flap_detection_on_critical, int stalk_on_ok, int stalk_on_warning, int stalk_on_unknown, int stalk_on_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){
	service *new_service=NULL;
	int result=OK;
#ifdef NSCORE
	int x=0;
#endif

	/* make sure we have everything we need */
	if((host_name==NULL || !strcmp(host_name,"")) || (description==NULL || !strcmp(description,"")) || (check_command==NULL || !strcmp(check_command,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service description, host name, or check command is NULL\n");
		return NULL;
	        }

	/* check values */
	if(max_attempts<=0 || check_interval<0 || retry_interval<=0 || notification_interval<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid max_check_attempts, check_interval, retry_interval, or notification_interval value for service '%s' on host '%s'\n",description,host_name);
		return NULL;
	        }

	if(first_notification_delay<0){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Invalid first_notification_delay value for service '%s' on host '%s'\n",description,host_name);
		return NULL;
	        }

	/* allocate memory */
	if((new_service=(service *)calloc(1, sizeof(service)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_service->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if((new_service->description=(char *)strdup(description))==NULL)
		result=ERROR;
	if((new_service->display_name=(char *)strdup((display_name==NULL)?description:display_name))==NULL)
		result=ERROR;
	if((new_service->service_check_command=(char *)strdup(check_command))==NULL)
		result=ERROR;
	if(event_handler){
		if((new_service->event_handler=(char *)strdup(event_handler))==NULL)
			result=ERROR;
	        }
	if(notification_period){
		if((new_service->notification_period=(char *)strdup(notification_period))==NULL)
			result=ERROR;
	        }
	if(check_period){
		if((new_service->check_period=(char *)strdup(check_period))==NULL)
			result=ERROR;
	        }
	if(failure_prediction_options){
		if((new_service->failure_prediction_options=(char *)strdup(failure_prediction_options))==NULL)
			result=ERROR;
	        }
	if(notes){
		if((new_service->notes=(char *)strdup(notes))==NULL)
			result=ERROR;
	        }
	if(notes_url){
		if((new_service->notes_url=(char *)strdup(notes_url))==NULL)
			result=ERROR;
	        }
	if(action_url){
		if((new_service->action_url=(char *)strdup(action_url))==NULL)
			result=ERROR;
	        }
	if(icon_image){
		if((new_service->icon_image=(char *)strdup(icon_image))==NULL)
			result=ERROR;
	        }
	if(icon_image_alt){
		if((new_service->icon_image_alt=(char *)strdup(icon_image_alt))==NULL)
			result=ERROR;
	        }

	new_service->check_interval=check_interval;
	new_service->retry_interval=retry_interval;
	new_service->max_attempts=max_attempts;
	new_service->parallelize=(parallelize>0)?TRUE:FALSE;
	new_service->notification_interval=notification_interval;
	new_service->first_notification_delay=first_notification_delay;
	new_service->notify_on_unknown=(notify_unknown>0)?TRUE:FALSE;
	new_service->notify_on_warning=(notify_warning>0)?TRUE:FALSE;
	new_service->notify_on_critical=(notify_critical>0)?TRUE:FALSE;
	new_service->notify_on_recovery=(notify_recovery>0)?TRUE:FALSE;
	new_service->notify_on_flapping=(notify_flapping>0)?TRUE:FALSE;
	new_service->notify_on_downtime=(notify_downtime>0)?TRUE:FALSE;
	new_service->is_volatile=(is_volatile>0)?((is_volatile==2)?VOLATILE_WITH_RENOTIFICATION_INTERVAL:TRUE):FALSE;
	new_service->flap_detection_enabled=(flap_detection_enabled>0)?TRUE:FALSE;
	new_service->low_flap_threshold=low_flap_threshold;
	new_service->high_flap_threshold=high_flap_threshold;
	new_service->flap_detection_on_ok=(flap_detection_on_ok>0)?TRUE:FALSE;
	new_service->flap_detection_on_warning=(flap_detection_on_warning>0)?TRUE:FALSE;
	new_service->flap_detection_on_unknown=(flap_detection_on_unknown>0)?TRUE:FALSE;
	new_service->flap_detection_on_critical=(flap_detection_on_critical>0)?TRUE:FALSE;
	new_service->stalk_on_ok=(stalk_on_ok>0)?TRUE:FALSE;
	new_service->stalk_on_warning=(stalk_on_warning>0)?TRUE:FALSE;
	new_service->stalk_on_unknown=(stalk_on_unknown>0)?TRUE:FALSE;
	new_service->stalk_on_critical=(stalk_on_critical>0)?TRUE:FALSE;
	new_service->process_performance_data=(process_perfdata>0)?TRUE:FALSE;
	new_service->check_freshness=(check_freshness>0)?TRUE:FALSE;
	new_service->freshness_threshold=freshness_threshold;
	new_service->accept_passive_service_checks=(accept_passive_checks>0)?TRUE:FALSE;
	new_service->event_handler_enabled=(event_handler_enabled>0)?TRUE:FALSE;
	new_service->checks_enabled=(checks_enabled>0)?TRUE:FALSE;
	new_service->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
	new_service->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
	new_service->notifications_enabled=(notifications_enabled>0)?TRUE:FALSE;
	new_service->obsess_over_service=(obsess_over_service>0)?TRUE:FALSE;
	new_service->failure_prediction_enabled=(failure_prediction_enabled>0)?TRUE:FALSE;
#ifdef NSCORE
	new_service->problem_has_been_acknowledged=FALSE;
	new_service->acknowledgement_type=ACKNOWLEDGEMENT_NONE;
	new_service->check_type=SERVICE_CHECK_ACTIVE;
	new_service->current_attempt=(initial_state==STATE_OK)?1:max_attempts;
	new_service->current_state=initial_state;
	new_service->current_event_id=0L;
	new_service->last_event_id=0L;
	new_service->current_problem_id=0L;
	new_service->last_problem_id=0L;
	new_service->last_state=initial_state;
	new_service->last_hard_state=initial_state;
	new_service->state_type=HARD_STATE;
	new_service->host_problem_at_last_check=FALSE;
	new_service->check_flapping_recovery_notification=FALSE;
	new_service->next_check=(time_t)0;
	new_service->should_be_scheduled=TRUE;
	new_service->last_check=(time_t)0;
	new_service->last_notification=(time_t)0;
	new_service->next_notification=(time_t)0;
	new_service->no_more_notifications=FALSE;
	new_service->last_state_change=(time_t)0;
	new_service->last_hard_state_change=(time_t)0;
	new_service->last_time_ok=(time_t)0;
	new_service->last_time_warning=(time_t)0;
	new_service->last_time_unknown=(time_t)0;
	new_service->last_time_critical=(time_t)0;
	new_service->has_been_checked=FALSE;
	new_service->is_being_freshened=FALSE;
	new_service->notified_on_unknown=FALSE;
	new_service->notified_on_warning=FALSE;
	new_service->notified_on_critical=FALSE;
	new_service->current_notification_number=0;
#ifdef USE_ST_BASED_ESCAL_RANGES
	new_service->current_warning_notification_number=0;
	new_service->current_critical_notification_number=0;
	new_service->current_unknown_notification_number=0;
#endif
	new_service->current_notification_id=0L;
	new_service->latency=0.0;
	new_service->execution_time=0.0;
	new_service->is_executing=FALSE;
	new_service->check_options=CHECK_OPTION_NONE;
	new_service->scheduled_downtime_depth=0;
	new_service->pending_flex_downtime=0;
	for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
		new_service->state_history[x]=STATE_OK;
	new_service->state_history_index=0;
	new_service->is_flapping=FALSE;
	new_service->flapping_comment_id=0;
	new_service->percent_state_change=0.0;
	new_service->modified_attributes=MODATTR_NONE;
#endif

	/* add new service to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[SERVICE_SKIPLIST],(void *)new_service);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service '%s' on host '%s' has already been defined\n",description,host_name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service '%s' on host '%s' to skiplist\n",description,host_name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
#ifdef NSCORE
		my_free(new_service->perf_data);
		my_free(new_service->plugin_output);
		my_free(new_service->long_plugin_output);
#endif
		my_free(new_service->failure_prediction_options);
		my_free(new_service->notification_period);
		my_free(new_service->event_handler);
		my_free(new_service->service_check_command);
		my_free(new_service->description);
		my_free(new_service->host_name);
		my_free(new_service);
		return NULL;
	        }

	/* services are sorted alphabetically, so add new items to tail of list */
	if(service_list==NULL){
		service_list=new_service;
		service_list_tail=service_list;
		}
	else{
		service_list_tail->next=new_service;
		service_list_tail=new_service;
		}

	return new_service;
	}



/* adds a contact group to a service */
contactgroupsmember *add_contactgroup_to_service(service *svc,char *group_name){
	contactgroupsmember *new_contactgroupsmember=NULL;
	int result=OK;

	/* bail out if we weren't given the data we need */
	if(svc==NULL || (group_name==NULL || !strcmp(group_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service or contactgroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory for the contactgroups member */
	if((new_contactgroupsmember=calloc(1, sizeof(contactgroupsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactgroupsmember);
		return NULL;
	        }

	/* add this contactgroup to the service */
	new_contactgroupsmember->next=svc->contact_groups;
	svc->contact_groups=new_contactgroupsmember;

	return new_contactgroupsmember;
	}



/* adds a contact to a service */
contactsmember *add_contact_to_service(service *svc, char *contact_name){

	return add_contact_to_object(&svc->contacts,contact_name);
        }



/* adds a custom variable to a service */
customvariablesmember *add_custom_variable_to_service(service *svc, char *varname, char *varvalue){

	return add_custom_variable_to_object(&svc->custom_variables,varname,varvalue);
        }



/* add a new command to the list in memory */
command *add_command(char *name,char *value){
	command *new_command=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if((name==NULL || !strcmp(name,"")) || (value==NULL || !strcmp(value,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Command name of command line is NULL\n");
		return NULL;
	        }

	/* allocate memory for the new command */
	if((new_command=(command *)calloc(1, sizeof(command)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_command->name=(char *)strdup(name))==NULL)
		result=ERROR;
	if((new_command->command_line=(char *)strdup(value))==NULL)
		result=ERROR;

	/* add new command to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[COMMAND_SKIPLIST],(void *)new_command);
		switch(result){
		case SKIPLIST_ERROR_DUPLICATE:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Command '%s' has already been defined\n",name);
			result=ERROR;
			break;
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add command '%s' to skiplist\n",name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_command->command_line);
		my_free(new_command->name);
		my_free(new_command);
		return NULL;
	        }

	/* commands are sorted alphabetically, so add new items to tail of list */
	if(command_list==NULL){
		command_list=new_command;
		command_list_tail=command_list;
		}
	else {
		command_list_tail->next=new_command;
		command_list_tail=new_command;
		}

	return new_command;
        }



/* add a new service escalation to the list in memory */
#ifndef USE_ST_BASED_ESCAL_RANGES
serviceescalation *add_serviceescalation(char *host_name,char *description, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_recovery){
#else
serviceescalation *add_serviceescalation(char *host_name,char *description, int first_notification, int last_notification, int first_warning_notification, int last_warning_notification, int first_critical_notification, int last_critical_notification, int first_unknown_notification, int last_unknown_notification, double notification_interval, char *escalation_period, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_recovery){
#endif
	serviceescalation *new_serviceescalation=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if((host_name==NULL || !strcmp(host_name,"")) || (description==NULL || !strcmp(description,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service escalation host name or description is NULL\n");
		return NULL;
	        }

#ifdef TEST
	printf("NEW SVC ESCALATION: %s/%s = %d/%d/%.3f\n",host_name,description,first_notification,last_notification,notification_interval);
#endif

	/* allocate memory for a new service escalation entry */
	if((new_serviceescalation=calloc(1, sizeof(serviceescalation)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_serviceescalation->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if((new_serviceescalation->description=(char *)strdup(description))==NULL)
		result=ERROR;
	if(escalation_period){
		if((new_serviceescalation->escalation_period=(char *)strdup(escalation_period))==NULL)
			result=ERROR;
	        }

	new_serviceescalation->first_notification=first_notification;
	new_serviceescalation->last_notification=last_notification;
#ifdef USE_ST_BASED_ESCAL_RANGES
	new_serviceescalation->first_warning_notification=first_warning_notification;
	new_serviceescalation->last_warning_notification=last_warning_notification;
	new_serviceescalation->first_critical_notification=first_critical_notification;
	new_serviceescalation->last_critical_notification=last_critical_notification;
	new_serviceescalation->first_unknown_notification=first_unknown_notification;
	new_serviceescalation->last_unknown_notification=last_unknown_notification;
#endif
	new_serviceescalation->notification_interval=(notification_interval<=0)?0:notification_interval;
	new_serviceescalation->escalate_on_recovery=(escalate_on_recovery>0)?TRUE:FALSE;
	new_serviceescalation->escalate_on_warning=(escalate_on_warning>0)?TRUE:FALSE;
	new_serviceescalation->escalate_on_unknown=(escalate_on_unknown>0)?TRUE:FALSE;
	new_serviceescalation->escalate_on_critical=(escalate_on_critical>0)?TRUE:FALSE;

	/* add new serviceescalation to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[SERVICEESCALATION_SKIPLIST],(void *)new_serviceescalation);
		switch(result){
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add escalation for service '%s' on host '%s' to skiplist\n",description,host_name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_serviceescalation->host_name);
		my_free(new_serviceescalation->description);
		my_free(new_serviceescalation->escalation_period);
		my_free(new_serviceescalation);
		return NULL;
	        }

	/* service escalations are sorted alphabetically, so add new items to tail of list */
	if(serviceescalation_list==NULL){
		serviceescalation_list=new_serviceescalation;
		serviceescalation_list_tail=serviceescalation_list;
		}
	else{
		serviceescalation_list_tail->next=new_serviceescalation;
		serviceescalation_list_tail=new_serviceescalation;
		}

	return new_serviceescalation;
	}



/* adds a contact group to a service escalation */
contactgroupsmember *add_contactgroup_to_serviceescalation(serviceescalation *se,char *group_name){
	contactgroupsmember *new_contactgroupsmember=NULL;
	int result=OK;

	/* bail out if we weren't given the data we need */
	if(se==NULL || (group_name==NULL || !strcmp(group_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Service escalation or contactgroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory for the contactgroups member */
	if((new_contactgroupsmember=(contactgroupsmember *)calloc(1, sizeof(contactgroupsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactgroupsmember->group_name);
		my_free(new_contactgroupsmember);
		return NULL;
	        }

	/* add this contactgroup to the service escalation */
	new_contactgroupsmember->next=se->contact_groups;
	se->contact_groups=new_contactgroupsmember;

	return new_contactgroupsmember;
	}



/* adds a contact to a service escalation */
contactsmember *add_contact_to_serviceescalation(serviceescalation *se, char *contact_name){

	return add_contact_to_object(&se->contacts,contact_name);
        }



/* adds a service dependency definition */
servicedependency *add_service_dependency(char *dependent_host_name, char *dependent_service_description, char *host_name, char *service_description, int dependency_type, int inherits_parent, int fail_on_ok, int fail_on_warning, int fail_on_unknown, int fail_on_critical, int fail_on_pending, char *dependency_period){
	servicedependency *new_servicedependency=NULL;
	int result=OK;

	/* make sure we have what we need */
	if((host_name==NULL || !strcmp(host_name,"")) || (service_description==NULL || !strcmp(service_description,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL master service description/host name in service dependency definition\n");
		return NULL;
	        }
	if((dependent_host_name==NULL || !strcmp(dependent_host_name,"")) || (dependent_service_description==NULL || !strcmp(dependent_service_description,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL dependent service description/host name in service dependency definition\n");
		return NULL;
	        }

	/* allocate memory for a new service dependency entry */
	if((new_servicedependency=(servicedependency *)calloc(1, sizeof(servicedependency)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_servicedependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
		result=ERROR;
	if((new_servicedependency->dependent_service_description=(char *)strdup(dependent_service_description))==NULL)
		result=ERROR;
	if((new_servicedependency->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if((new_servicedependency->service_description=(char *)strdup(service_description))==NULL)
		result=ERROR;
	if(dependency_period){
		if((new_servicedependency->dependency_period=(char *)strdup(dependency_period))==NULL)
			result=ERROR;
		}

	new_servicedependency->dependency_type=(dependency_type==EXECUTION_DEPENDENCY)?EXECUTION_DEPENDENCY:NOTIFICATION_DEPENDENCY;
	new_servicedependency->inherits_parent=(inherits_parent>0)?TRUE:FALSE;
	new_servicedependency->fail_on_ok=(fail_on_ok==1)?TRUE:FALSE;
	new_servicedependency->fail_on_warning=(fail_on_warning==1)?TRUE:FALSE;
	new_servicedependency->fail_on_unknown=(fail_on_unknown==1)?TRUE:FALSE;
	new_servicedependency->fail_on_critical=(fail_on_critical==1)?TRUE:FALSE;
	new_servicedependency->fail_on_pending=(fail_on_pending==1)?TRUE:FALSE;
#ifdef NSCORE
	new_servicedependency->circular_path_checked=FALSE;
	new_servicedependency->contains_circular_path=FALSE;
#endif

	/* add new service dependency to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],(void *)new_servicedependency);
		switch(result){
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add service dependency to skiplist\n");
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_servicedependency->host_name);
		my_free(new_servicedependency->service_description);
		my_free(new_servicedependency->dependent_host_name);
		my_free(new_servicedependency->dependent_service_description);
		my_free(new_servicedependency);
		return NULL;
	        }

	/* service dependencies are sorted alphabetically, so add new items to tail of list */
	if(servicedependency_list==NULL){
		servicedependency_list=new_servicedependency;
		servicedependency_list_tail=servicedependency_list;
		}
	else{
		servicedependency_list_tail->next=new_servicedependency;
		servicedependency_list_tail=new_servicedependency;
		}

	return new_servicedependency;
        }


/* adds a host dependency definition */
hostdependency *add_host_dependency(char *dependent_host_name, char *host_name, int dependency_type, int inherits_parent, int fail_on_up, int fail_on_down, int fail_on_unreachable, int fail_on_pending, char *dependency_period){
	hostdependency *new_hostdependency=NULL;
	int result=OK;

	/* make sure we have what we need */
	if((dependent_host_name==NULL || !strcmp(dependent_host_name,"")) || (host_name==NULL || !strcmp(host_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL host name in host dependency definition\n");
		return NULL;
	        }

	/* allocate memory for a new host dependency entry */
	if((new_hostdependency=(hostdependency *)calloc(1, sizeof(hostdependency)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_hostdependency->dependent_host_name=(char *)strdup(dependent_host_name))==NULL)
		result=ERROR;
	if((new_hostdependency->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if(dependency_period){
		if((new_hostdependency->dependency_period=(char *)strdup(dependency_period))==NULL)
			result=ERROR;
		}

	new_hostdependency->dependency_type=(dependency_type==EXECUTION_DEPENDENCY)?EXECUTION_DEPENDENCY:NOTIFICATION_DEPENDENCY;
	new_hostdependency->inherits_parent=(inherits_parent>0)?TRUE:FALSE;
	new_hostdependency->fail_on_up=(fail_on_up==1)?TRUE:FALSE;
	new_hostdependency->fail_on_down=(fail_on_down==1)?TRUE:FALSE;
	new_hostdependency->fail_on_unreachable=(fail_on_unreachable==1)?TRUE:FALSE;
	new_hostdependency->fail_on_pending=(fail_on_pending==1)?TRUE:FALSE;
#ifdef NSCORE
	new_hostdependency->circular_path_checked=FALSE;
	new_hostdependency->contains_circular_path=FALSE;
#endif

	/* add new host dependency to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[HOSTDEPENDENCY_SKIPLIST],(void *)new_hostdependency);
		switch(result){
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add host dependency to skiplist\n");
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_hostdependency->host_name);
		my_free(new_hostdependency->dependent_host_name);
		my_free(new_hostdependency);
		return NULL;
	        }

	/* host dependencies are sorted alphabetically, so add new items to tail of list */
	if(hostdependency_list==NULL){
		hostdependency_list=new_hostdependency;
		hostdependency_list_tail=hostdependency_list;
		}
	else {
		hostdependency_list_tail->next=new_hostdependency;
		hostdependency_list_tail=new_hostdependency;
		}

	return new_hostdependency;
        }



/* add a new host escalation to the list in memory */
#ifndef USE_ST_BASED_ESCAL_RANGES
hostescalation *add_hostescalation(char *host_name,int first_notification,int last_notification, double notification_interval, char *escalation_period, int escalate_on_down, int escalate_on_unreachable, int escalate_on_recovery){
#else
hostescalation *add_hostescalation(char *host_name,int first_notification,int last_notification, int first_down_notification, int last_down_notification, int first_unreachable_notification, int last_unreachable_notification, double notification_interval, char *escalation_period, int escalate_on_down, int escalate_on_unreachable, int escalate_on_recovery){
#endif
	hostescalation *new_hostescalation=NULL;
	int result=OK;

	/* make sure we have the data we need */
	if(host_name==NULL || !strcmp(host_name,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host escalation host name is NULL\n");
		return NULL;
	        }

#ifdef TEST
	printf("NEW HST ESCALATION: %s = %d/%d/%.3f\n",host_name,first_notification,last_notification,notification_interval);
#endif

	/* allocate memory for a new host escalation entry */
	if((new_hostescalation=calloc(1, sizeof(hostescalation)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_hostescalation->host_name=(char *)strdup(host_name))==NULL)
		result=ERROR;
	if(escalation_period){
		if((new_hostescalation->escalation_period=(char *)strdup(escalation_period))==NULL)
			result=ERROR;
	        }

	new_hostescalation->first_notification=first_notification;
	new_hostescalation->last_notification=last_notification;
#ifdef USE_ST_BASED_ESCAL_RANGES
	new_hostescalation->first_down_notification=first_down_notification;
	new_hostescalation->last_down_notification=last_down_notification;
	new_hostescalation->first_unreachable_notification=first_unreachable_notification;
	new_hostescalation->last_unreachable_notification=last_unreachable_notification;
#endif
	new_hostescalation->notification_interval=(notification_interval<=0)?0:notification_interval;
	new_hostescalation->escalate_on_recovery=(escalate_on_recovery>0)?TRUE:FALSE;
	new_hostescalation->escalate_on_down=(escalate_on_down>0)?TRUE:FALSE;
	new_hostescalation->escalate_on_unreachable=(escalate_on_unreachable>0)?TRUE:FALSE;

	/* add new hostescalation to skiplist */
	if(result==OK){
		result=skiplist_insert(object_skiplists[HOSTESCALATION_SKIPLIST],(void *)new_hostescalation);
		switch(result){
		case SKIPLIST_OK:
			result=OK;
			break;
		default:
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add hostescalation '%s' to skiplist\n",host_name);
			result=ERROR;
			break;
			}
		}

	/* handle errors */
	if(result==ERROR){
		my_free(new_hostescalation->host_name);
		my_free(new_hostescalation->escalation_period);
		my_free(new_hostescalation);
		return NULL;
	        }

	/* host escalations are sorted alphabetically, so add new items to tail of list */
	if(hostescalation_list==NULL){
		hostescalation_list=new_hostescalation;
		hostescalation_list_tail=hostescalation_list;
		}
	else{
		hostescalation_list_tail->next=new_hostescalation;
		hostescalation_list_tail=new_hostescalation;
		}

	return new_hostescalation;
	}

/* add a condition to a (host or service) escalation in memory */
escalation_condition *add_host_service_escalation_condition(hostescalation *my_hostescalation, serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
        escalation_condition *new_escalation_condition=NULL;
        int result=OK;
          
        /* make sure we have the data we need */
        if(host_name==NULL || !strcmp(host_name,"")){
                logit(NSLOG_CONFIG_ERROR,TRUE,"Error: escalation condition: host name is NULL\n");
                return NULL;
        }
       
#ifdef TEST
        printf("NEW ESCALATION CONDITION: host = %s; service = %s; connector = %d/\n",host_name,service_description,connector);
 #endif 
       
        /* remove whitespaces */
        strip(host_name);
        strip(service_description);
       
        /* allocate memory for a new escalation_condition entry */
        if((new_escalation_condition=malloc(sizeof(escalation_condition)))==NULL)
                return NULL;
       
        /* initialize vars */
        new_escalation_condition->host_name=NULL;
        new_escalation_condition->service_description=NULL;
        new_escalation_condition->next=NULL;
        new_escalation_condition->escalate_on_warning=FALSE;
        new_escalation_condition->escalate_on_unknown=FALSE;
        new_escalation_condition->escalate_on_critical=FALSE;
        new_escalation_condition->escalate_on_ok=FALSE;
        new_escalation_condition->escalate_on_down=FALSE;
        new_escalation_condition->escalate_on_unreachable=FALSE;
        
        /* service condition */
        if(service_description!=NULL && strcmp(service_description,"")
                                && host_name!=NULL && strcmp(host_name,"")) {
                if((new_escalation_condition->host_name=(char *)strdup(host_name))==NULL)
                        result=ERROR;
                if((new_escalation_condition->service_description=(char *)strdup(service_description))==NULL)
                        result=ERROR;
                        
                new_escalation_condition->escalate_on_warning=(escalate_on_warning>0)?TRUE:FALSE;
                new_escalation_condition->escalate_on_unknown=(escalate_on_unknown>0)?TRUE:FALSE;
                new_escalation_condition->escalate_on_critical=(escalate_on_critical>0)?TRUE:FALSE;
                new_escalation_condition->escalate_on_ok=(escalate_on_ok>0)?TRUE:FALSE;
        }
        
        /* host condition */
        else if(host_name!=NULL && strcmp(host_name,"")) {
                if((new_escalation_condition->host_name=(char *)strdup(host_name))==NULL)
                        result=ERROR;
                       
                new_escalation_condition->escalate_on_down=(escalate_on_down>0)?TRUE:FALSE;
                new_escalation_condition->escalate_on_unreachable=(escalate_on_unreachable>0)?TRUE:FALSE;
                new_escalation_condition->escalate_on_ok=(escalate_on_ok>0)?TRUE:FALSE;
        }
       
        /* connector to next condition */
        new_escalation_condition->connector=(connector>=0 && connector<=2)?connector : EC_CONNECTOR_NO;
       
        /* handle errors */
        if(result==ERROR){
                my_free(new_escalation_condition->host_name);
                my_free(new_escalation_condition->service_description);
                my_free(new_escalation_condition);
                return NULL;
                }
        
        /* if head of escalation condition is NULL set it to new condition */
        if(my_serviceescalation!=NULL && my_serviceescalation->condition==NULL){
                my_serviceescalation->condition=new_escalation_condition;
        }
        else if(my_hostescalation!=NULL && my_hostescalation->condition==NULL){
                my_hostescalation->condition=new_escalation_condition;
        }
        /* else add new condition to the tail of condition list */
        else {
                last_condition->next=new_escalation_condition;
        }
        return new_escalation_condition;
}

/* add a condition to a host escalation in memory */
escalation_condition *add_hostescalation_condition(hostescalation *my_hostescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
        return add_host_service_escalation_condition(my_hostescalation, NULL, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
}

/* add a condition to a service escalation in memory */
escalation_condition *add_serviceescalation_condition(serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok){
        return add_host_service_escalation_condition(NULL, my_serviceescalation, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
}

/* adds a contact group to a host escalation */
contactgroupsmember *add_contactgroup_to_hostescalation(hostescalation *he,char *group_name){
	contactgroupsmember *new_contactgroupsmember=NULL;
	int result=OK;

	/* bail out if we weren't given the data we need */
	if(he==NULL || (group_name==NULL || !strcmp(group_name,""))){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Host escalation or contactgroup name is NULL\n");
		return NULL;
	        }

	/* allocate memory for the contactgroups member */
	if((new_contactgroupsmember=(contactgroupsmember *)calloc(1, sizeof(contactgroupsmember)))==NULL)
		return NULL;

	/* duplicate vars */
	if((new_contactgroupsmember->group_name=(char *)strdup(group_name))==NULL)
		result=ERROR;

	/* handle errors */
	if(result==ERROR){
		my_free(new_contactgroupsmember->group_name);
		my_free(new_contactgroupsmember);
		return NULL;
	        }

	/* add this contactgroup to the host escalation */
	new_contactgroupsmember->next=he->contact_groups;
	he->contact_groups=new_contactgroupsmember;

	return new_contactgroupsmember;
	}



/* adds a contact to a host escalation */
contactsmember *add_contact_to_hostescalation(hostescalation *he, char *contact_name){

	return add_contact_to_object(&he->contacts,contact_name);
        }



/* adds a contact to an object */
contactsmember *add_contact_to_object(contactsmember **object_ptr, char *contactname){
	contactsmember *new_contactsmember=NULL;

	/* make sure we have the data we need */
	if(object_ptr==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact object is NULL\n");
		return NULL;
	        }

	if(contactname==NULL || !strcmp(contactname,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Contact name is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_contactsmember=malloc(sizeof(contactsmember)))==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for contact\n");
		return NULL;
	        }
	if((new_contactsmember->contact_name=(char *)strdup(contactname))==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for contact name\n");
		my_free(new_contactsmember);
		return NULL;
	        }

	/* set initial values */
#ifdef NSCORE
	new_contactsmember->contact_ptr=NULL;
#endif

	/* add the new contact to the head of the contact list */
	new_contactsmember->next=*object_ptr;
	*object_ptr=new_contactsmember;

	return new_contactsmember;
        }



/* adds a custom variable to an object */
customvariablesmember *add_custom_variable_to_object(customvariablesmember **object_ptr, char *varname, char *varvalue){
	customvariablesmember *new_customvariablesmember=NULL;

	/* make sure we have the data we need */
	if(object_ptr==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Custom variable object is NULL\n");
		return NULL;
	        }

	if(varname==NULL || !strcmp(varname,"")){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Custom variable name is NULL\n");
		return NULL;
	        }

	/* allocate memory for a new member */
	if((new_customvariablesmember=malloc(sizeof(customvariablesmember)))==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable\n");
		return NULL;
	        }
	if((new_customvariablesmember->variable_name=(char *)strdup(varname))==NULL){
		logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable name\n");
		my_free(new_customvariablesmember);
		return NULL;
	        }
	if(varvalue){
		if((new_customvariablesmember->variable_value=(char *)strdup(varvalue))==NULL){
			logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not allocate memory for custom variable value\n");
			my_free(new_customvariablesmember->variable_name);
			my_free(new_customvariablesmember);
			return NULL;
	                }
	        }
	else
		new_customvariablesmember->variable_value=NULL;

	/* set initial values */
	new_customvariablesmember->has_been_modified=FALSE;

	/* add the new member to the head of the member list */
	new_customvariablesmember->next=*object_ptr;
	*object_ptr=new_customvariablesmember;

	return new_customvariablesmember;
        }




/******************************************************************/
/******************** OBJECT SEARCH FUNCTIONS *********************/
/******************************************************************/

/* given a timeperiod name and a starting point, find a timeperiod from the list in memory */
timeperiod * find_timeperiod(char *name){
	timeperiod temp_timeperiod;

	if(name==NULL)
		return NULL;

	temp_timeperiod.name=name;

	return skiplist_find_first(object_skiplists[TIMEPERIOD_SKIPLIST],&temp_timeperiod,NULL);
	}


/* given a host name, find it in the list in memory */
host * find_host(char *name){
	host temp_host;

	if(name==NULL)
		return NULL;

	temp_host.name=name;

	return skiplist_find_first(object_skiplists[HOST_SKIPLIST],&temp_host,NULL);
	}


/* find a hostgroup from the list in memory */
hostgroup * find_hostgroup(char *name){
	hostgroup temp_hostgroup;

	if(name==NULL)
		return NULL;

	temp_hostgroup.group_name=name;

	return skiplist_find_first(object_skiplists[HOSTGROUP_SKIPLIST],&temp_hostgroup,NULL);
	}


/* find a servicegroup from the list in memory */
servicegroup * find_servicegroup(char *name){
	servicegroup temp_servicegroup;

	if(name==NULL)
		return NULL;

	temp_servicegroup.group_name=name;

	return skiplist_find_first(object_skiplists[SERVICEGROUP_SKIPLIST],&temp_servicegroup,NULL);
	}


/* find a contact from the list in memory */
contact * find_contact(char *name){
	contact temp_contact;

	if(name==NULL)
		return NULL;

	temp_contact.name=name;

	return skiplist_find_first(object_skiplists[CONTACT_SKIPLIST],&temp_contact,NULL);
	}


/* find a contact group from the list in memory */
contactgroup * find_contactgroup(char *name){
	contactgroup temp_contactgroup;

	if(name==NULL)
		return NULL;

	temp_contactgroup.group_name=name;

	return skiplist_find_first(object_skiplists[CONTACTGROUP_SKIPLIST],&temp_contactgroup,NULL);
	}


/* given a command name, find a command from the list in memory */
command * find_command(char *name){
	command temp_command;

	if(name==NULL)
		return NULL;

	temp_command.name=name;

	return skiplist_find_first(object_skiplists[COMMAND_SKIPLIST],&temp_command,NULL);
        }


/* given a host/service name, find the service in the list in memory */
service * find_service(char *host_name,char *svc_desc){
	service temp_service;

	if(host_name==NULL || svc_desc==NULL)
		return NULL;

	temp_service.host_name=host_name;
	temp_service.description=svc_desc;

	return skiplist_find_first(object_skiplists[SERVICE_SKIPLIST],&temp_service,NULL);
        }




/******************************************************************/
/******************* OBJECT TRAVERSAL FUNCTIONS *******************/
/******************************************************************/

hostescalation *get_first_hostescalation_by_host(char *host_name, void **ptr){
	hostescalation temp_hostescalation;

	if(host_name==NULL)
		return NULL;

	temp_hostescalation.host_name=host_name;

	return skiplist_find_first(object_skiplists[HOSTESCALATION_SKIPLIST],&temp_hostescalation,ptr);
        }


hostescalation *get_next_hostescalation_by_host(char *host_name, void **ptr){
	hostescalation temp_hostescalation;

	if(host_name==NULL)
		return NULL;

	temp_hostescalation.host_name=host_name;

	return skiplist_find_next(object_skiplists[HOSTESCALATION_SKIPLIST],&temp_hostescalation,ptr);
        }


serviceescalation *get_first_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr){
	serviceescalation temp_serviceescalation;

	if(host_name==NULL || svc_description==NULL)
		return NULL;

	temp_serviceescalation.host_name=host_name;
	temp_serviceescalation.description=svc_description;

	return skiplist_find_first(object_skiplists[SERVICEESCALATION_SKIPLIST],&temp_serviceescalation,ptr);
	}


serviceescalation *get_next_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr){
	serviceescalation temp_serviceescalation;

	if(host_name==NULL || svc_description==NULL)
		return NULL;

	temp_serviceescalation.host_name=host_name;
	temp_serviceescalation.description=svc_description;

	return skiplist_find_next(object_skiplists[SERVICEESCALATION_SKIPLIST],&temp_serviceescalation,ptr);
        }


hostdependency *get_first_hostdependency_by_dependent_host(char *host_name, void **ptr){
	hostdependency temp_hostdependency;

	if(host_name==NULL)
		return NULL;

	temp_hostdependency.dependent_host_name=host_name;

	return skiplist_find_first(object_skiplists[HOSTDEPENDENCY_SKIPLIST],&temp_hostdependency,ptr);
        }


hostdependency *get_next_hostdependency_by_dependent_host(char *host_name, void **ptr){
	hostdependency temp_hostdependency;

	if(host_name==NULL || ptr==NULL)
		return NULL;

	temp_hostdependency.dependent_host_name=host_name;

	return skiplist_find_next(object_skiplists[HOSTDEPENDENCY_SKIPLIST],&temp_hostdependency,ptr);
        }


servicedependency *get_first_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr){
	servicedependency temp_servicedependency;

	if(host_name==NULL || svc_description==NULL)
		return NULL;

	temp_servicedependency.dependent_host_name=host_name;
	temp_servicedependency.dependent_service_description=svc_description;

	return skiplist_find_first(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],&temp_servicedependency,ptr);
        }


servicedependency *get_next_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr){
	servicedependency temp_servicedependency;

	if(host_name==NULL || svc_description==NULL || ptr==NULL)
		return NULL;

	temp_servicedependency.dependent_host_name=host_name;
	temp_servicedependency.dependent_service_description=svc_description;

	return skiplist_find_next(object_skiplists[SERVICEDEPENDENCY_SKIPLIST],&temp_servicedependency,ptr);

	return NULL;
        }


#ifdef NSCORE
/* adds a object to a list of objects */
int add_object_to_objectlist(objectlist **list, void *object_ptr){
	objectlist *temp_item=NULL;
	objectlist *new_item=NULL;

	if(list==NULL || object_ptr==NULL)
		return ERROR;

	/* skip this object if its already in the list */
	for(temp_item=*list;temp_item;temp_item=temp_item->next){
		if(temp_item->object_ptr==object_ptr)
			break;
	        }
	if(temp_item)
		return OK;

	/* allocate memory for a new list item */
	if((new_item=(objectlist *)malloc(sizeof(objectlist)))==NULL)
		return ERROR;

	/* initialize vars */
	new_item->object_ptr=object_ptr;

	/* add new item to head of list */
	new_item->next=*list;
	*list=new_item;

	return OK;
        }



/* frees memory allocated to a temporary object list */
int free_objectlist(objectlist **temp_list){
	objectlist *this_objectlist=NULL;
	objectlist *next_objectlist=NULL;

	if(temp_list==NULL)
		return ERROR;

	/* free memory allocated to object list */
	for(this_objectlist=*temp_list;this_objectlist!=NULL;this_objectlist=next_objectlist){
		next_objectlist=this_objectlist->next;
		my_free(this_objectlist);
	        }

	*temp_list=NULL;

	return OK;
        }
#endif



/******************************************************************/
/********************* OBJECT QUERY FUNCTIONS *********************/
/******************************************************************/

/* determines whether or not a specific host is an immediate child of another host */
int is_host_immediate_child_of_host(host *parent_host,host *child_host){
	hostsmember *temp_hostsmember=NULL;

	/* not enough data */
	if(child_host==NULL)
		return FALSE;

	/* root/top-level hosts */
	if(parent_host==NULL){
		if(child_host->parent_hosts==NULL)
			return TRUE;
	        }

	/* mid-level/bottom hosts */
	else{

		for(temp_hostsmember=child_host->parent_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
#ifdef NSCORE
			if(temp_hostsmember->host_ptr==parent_host)
				return TRUE;
#else
			if(!strcmp(temp_hostsmember->host_name,parent_host->name))
				return TRUE;
#endif
		        }
	        }

	return FALSE;
	}


/* determines whether or not a specific host is an immediate parent of another host */
int is_host_immediate_parent_of_host(host *child_host,host *parent_host){

	if(is_host_immediate_child_of_host(parent_host,child_host)==TRUE)
		return TRUE;

	return FALSE;
	}


/* returns a count of the immediate children for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_immediate_child_hosts(host *hst){
	int children=0;
	host *temp_host=NULL;

	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
		if(is_host_immediate_child_of_host(hst,temp_host)==TRUE)
			children++;
		}

	return children;
	}


/* returns a count of the total children for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_total_child_hosts(host *hst){
	int children=0;
	host *temp_host=NULL;

	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
		if(is_host_immediate_child_of_host(hst,temp_host)==TRUE)
			children+=number_of_total_child_hosts(temp_host)+1;
		}

	return children;
	}


/* get the number of immediate parent hosts for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_immediate_parent_hosts(host *hst){
	int parents=0;
	host *temp_host=NULL;

	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
		if(is_host_immediate_parent_of_host(hst,temp_host)==TRUE){
			parents++;
		        }
	        }

	return parents;
        }


/* get the total number of parent hosts for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_total_parent_hosts(host *hst){
	int parents=0;
	host *temp_host=NULL;

	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
		if(is_host_immediate_parent_of_host(hst,temp_host)==TRUE){
			parents+=number_of_total_parent_hosts(temp_host)+1;
		        }
	        }

	return parents;
        }


/*  tests whether a host is a member of a particular hostgroup */
/* NOTE: This function is only used by the CGIS */
int is_host_member_of_hostgroup(hostgroup *group, host *hst){
	hostsmember *temp_hostsmember=NULL;

	if(group==NULL || hst==NULL)
		return FALSE;

	for(temp_hostsmember=group->members;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
#ifdef NSCORE
		if(temp_hostsmember->host_ptr==hst)
			return TRUE;
#else
		if(!strcmp(temp_hostsmember->host_name,hst->name))
			return TRUE;
#endif
	        }

	return FALSE;
        }


/*  tests whether a host is a member of a particular servicegroup */
/* NOTE: This function is only used by the CGIS */
int is_host_member_of_servicegroup(servicegroup *group, host *hst){
	servicesmember *temp_servicesmember=NULL;

	if(group==NULL || hst==NULL)
		return FALSE;

	for(temp_servicesmember=group->members;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
#ifdef NSCORE
		if(temp_servicesmember->service_ptr!=NULL && temp_servicesmember->service_ptr->host_ptr==hst)
			return TRUE;
#else
		if(!strcmp(temp_servicesmember->host_name,hst->name))
			return TRUE;
#endif
	        }

	return FALSE;
        }


/*  tests whether a service is a member of a particular servicegroup */
/* NOTE: This function is only used by the CGIS */
int is_service_member_of_servicegroup(servicegroup *group, service *svc){
	servicesmember *temp_servicesmember=NULL;

	if(group==NULL || svc==NULL)
		return FALSE;

	for(temp_servicesmember=group->members;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
#ifdef NSCORE
		if(temp_servicesmember->service_ptr==svc)
			return TRUE;
#else
		if(!strcmp(temp_servicesmember->host_name,svc->host_name) && !strcmp(temp_servicesmember->service_description,svc->description))
			return TRUE;
#endif
	        }

	return FALSE;
        }

/* 06/14/10 MF all 3 functions mandatory for mk_livestatus */
/*  tests whether a contact is a member of a particular contactgroup - used only by the CGIs */
int is_contact_member_of_contactgroup(contactgroup *group, contact *cntct){
        contactsmember *temp_contactsmember=NULL;

        if(group==NULL || cntct==NULL)
                return FALSE;
 
        /* search all contacts in this contact group */
        for(temp_contactsmember=group->members;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
 
#ifdef NSCORE
                if(temp_contactsmember->contact_ptr==cntct)
                        return TRUE;
#else
                if(!strcmp(temp_contactsmember->contact_name,cntct->name))
                        return TRUE;
#endif
                 }
 
        return FALSE;
        }


/*  tests whether a contact is a member of a particular hostgroup - used only by the CGIs */
int is_contact_for_hostgroup(hostgroup *group, contact *cntct){
        hostsmember *temp_hostsmember=NULL;
        host *temp_host=NULL;
 
        if(group==NULL || cntct==NULL)
                return FALSE;
 
        for(temp_hostsmember=group->members;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
#ifdef NSCORE
                temp_host=temp_hostsmember->host_ptr;
#else
                temp_host=find_host(temp_hostsmember->host_name);
#endif
                if(temp_host==NULL)
                        continue;
                if(is_contact_for_host(temp_host,cntct)==TRUE)
                        return TRUE;
                }
 
        return FALSE;
        }
 
 /*  tests whether a contact is a member of a particular servicegroup - used only by the CGIs */
 int is_contact_for_servicegroup(servicegroup *group, contact *cntct){
        servicesmember *temp_servicesmember=NULL;
        service *temp_service=NULL;
 
        if(group==NULL || cntct==NULL)
                return FALSE;
 
        for(temp_servicesmember=group->members;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
#ifdef NSCORE
                temp_service=temp_servicesmember->service_ptr;
#else
                temp_service=find_service(temp_servicesmember->host_name,temp_servicesmember->service_description);
#endif
                if(temp_service==NULL)
                        continue;
                if(is_contact_for_service(temp_service,cntct)==TRUE)
                        return TRUE;
                }
 
        return FALSE;
        }


/*  tests whether a contact is a contact for a particular host */
int is_contact_for_host(host *hst, contact *cntct){
	contactsmember *temp_contactsmember=NULL;
	contact *temp_contact=NULL;
	contactgroupsmember *temp_contactgroupsmember=NULL;
	contactgroup *temp_contactgroup=NULL;
	
	if(hst==NULL || cntct==NULL){
		return FALSE;
	        }

	/* search all individual contacts of this host */
	for(temp_contactsmember=hst->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
		temp_contact=temp_contactsmember->contact_ptr;
#else
		temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
		if(temp_contact==NULL)
			continue;
		if(temp_contact==cntct)
			return TRUE;
		}

	/* search all contactgroups of this host */
	for(temp_contactgroupsmember=hst->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
#ifdef NSCORE
		temp_contactgroup=temp_contactgroupsmember->group_ptr;
#else
		temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
#endif
		if(temp_contactgroup==NULL)
			continue;

		for(temp_contactsmember=temp_contactgroup->members;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
			temp_contact=temp_contactsmember->contact_ptr;
#else
			temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
			if(temp_contact==NULL)
				continue;
			if(temp_contact==cntct)
				return TRUE;
			}
		}

	return FALSE;
        }



/* tests whether or not a contact is an escalated contact for a particular host */
int is_escalated_contact_for_host(host *hst, contact *cntct){
	contactsmember *temp_contactsmember=NULL;
	contact *temp_contact=NULL;
	hostescalation *temp_hostescalation=NULL;
	contactgroupsmember *temp_contactgroupsmember=NULL;
	contactgroup *temp_contactgroup=NULL;
	void *ptr=NULL;


	/* search all host escalations */
	for(temp_hostescalation=get_first_hostescalation_by_host(hst->name,&ptr);temp_hostescalation!=NULL;temp_hostescalation=get_next_hostescalation_by_host(hst->name,&ptr)){

		/* search all contacts of this host escalation */
		for(temp_contactsmember=temp_hostescalation->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
			temp_contact=temp_contactsmember->contact_ptr;
#else
			temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
			if(temp_contact==NULL)
				continue;
			if(temp_contact==cntct)
				return TRUE;
			}
		
		/* search all contactgroups of this host escalation */
		for(temp_contactgroupsmember=temp_hostescalation->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
#ifdef NSCORE
			temp_contactgroup=temp_contactgroupsmember->group_ptr;
#else
			temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
#endif
			if(temp_contactgroup==NULL)
				continue;

			for(temp_contactsmember=temp_contactgroup->members;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
				temp_contact=temp_contactsmember->contact_ptr;
#else
				temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
				if(temp_contact==NULL)
					continue;
				if(temp_contact==cntct)
					return TRUE;
				}
			}
		}

	return FALSE;
        }


/*  tests whether a contact is a contact for a particular service */
int is_contact_for_service(service *svc, contact *cntct){
	contactsmember *temp_contactsmember=NULL;
	contact *temp_contact=NULL;
	contactgroupsmember *temp_contactgroupsmember=NULL;
	contactgroup *temp_contactgroup=NULL;

	if(svc==NULL || cntct==NULL)
		return FALSE;

	/* search all individual contacts of this service */
	for(temp_contactsmember=svc->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
		temp_contact=temp_contactsmember->contact_ptr;
#else
		temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
		
		if(temp_contact==cntct)
			return TRUE;
		}

	/* search all contactgroups of this service */
	for(temp_contactgroupsmember=svc->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
#ifdef NSCORE
		temp_contactgroup=temp_contactgroupsmember->group_ptr;
#else
		temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
#endif
		if(temp_contactgroup==NULL)
			continue;

		for(temp_contactsmember=temp_contactgroup->members;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
			temp_contact=temp_contactsmember->contact_ptr;
#else
			temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
			if(temp_contact==NULL)
				continue;
			if(temp_contact==cntct)
				return TRUE;
			}
		}

	return FALSE;
        }



/* tests whether or not a contact is an escalated contact for a particular service */
int is_escalated_contact_for_service(service *svc, contact *cntct){
	serviceescalation *temp_serviceescalation=NULL;
	contactsmember *temp_contactsmember=NULL;
	contact *temp_contact=NULL;
	contactgroupsmember *temp_contactgroupsmember=NULL;
	contactgroup *temp_contactgroup=NULL;
	void *ptr=NULL;

	/* search all the service escalations */
	for(temp_serviceescalation=get_first_serviceescalation_by_service(svc->host_name,svc->description,&ptr);temp_serviceescalation!=NULL;temp_serviceescalation=get_next_serviceescalation_by_service(svc->host_name,svc->description,&ptr)){

		/* search all contacts of this service escalation */
		for(temp_contactsmember=temp_serviceescalation->contacts;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
			temp_contact=temp_contactsmember->contact_ptr;
#else
			temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
			if(temp_contact==NULL)
				continue;
			if(temp_contact==cntct)
				return TRUE;
			}
		
		/* search all contactgroups of this service escalation */
		for(temp_contactgroupsmember=temp_serviceescalation->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){
#ifdef NSCORE
			temp_contactgroup=temp_contactgroupsmember->group_ptr;
#else
			temp_contactgroup=find_contactgroup(temp_contactgroupsmember->group_name);
#endif
			if(temp_contactgroup==NULL)
				continue;

			for(temp_contactsmember=temp_contactgroup->members;temp_contactsmember!=NULL;temp_contactsmember=temp_contactsmember->next){
#ifdef NSCORE
				temp_contact=temp_contactsmember->contact_ptr;
#else
				temp_contact=find_contact(temp_contactsmember->contact_name);
#endif
				if(temp_contact==NULL)
					continue;
				if(temp_contact==cntct)
					return TRUE;
				}
			}
	        }

	return FALSE;
        }


#ifdef NSCORE

/* checks to see if there exists a circular dependency for a service */
int check_for_circular_servicedependency_path(servicedependency *root_dep, servicedependency *dep, int dependency_type){
	servicedependency *temp_sd=NULL;

	if(root_dep==NULL || dep==NULL)
		return FALSE;

	/* this is not the proper dependency type */
	if(root_dep->dependency_type!=dependency_type || dep->dependency_type!=dependency_type)
		return FALSE;

	/* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
	if(root_dep->contains_circular_path==TRUE)
		return TRUE;

	/* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
	/* this should speed up detection for some loops */
	if(dep->circular_path_checked==TRUE)
		return FALSE;

	/* set the check flag so we don't get into an infinite loop */
	dep->circular_path_checked=TRUE;

	/* is this service dependent on the root service? */
	if(dep!=root_dep){
		if(root_dep->dependent_service_ptr==dep->master_service_ptr){
			root_dep->contains_circular_path=TRUE;
			dep->contains_circular_path=TRUE;
			return TRUE;
		        }
	        }

	/* notification dependencies are ok at this point as long as they don't inherit */
	if(dependency_type==NOTIFICATION_DEPENDENCY && dep->inherits_parent==FALSE)
		return FALSE;

	/* check all parent dependencies */
	for(temp_sd=servicedependency_list;temp_sd!=NULL;temp_sd=temp_sd->next){

		/* only check parent dependencies */
		if(dep->master_service_ptr!=temp_sd->dependent_service_ptr)
			continue;

		if(check_for_circular_servicedependency_path(root_dep,temp_sd,dependency_type)==TRUE)
			return TRUE;
	        }

	return FALSE;
        }


/* checks to see if there exists a circular dependency for a host */
int check_for_circular_hostdependency_path(hostdependency *root_dep, hostdependency *dep, int dependency_type){
	hostdependency *temp_hd=NULL;

	if(root_dep==NULL || dep==NULL)
		return FALSE;

	/* this is not the proper dependency type */
	if(root_dep->dependency_type!=dependency_type || dep->dependency_type!=dependency_type)
		return FALSE;

	/* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
	if(root_dep->contains_circular_path==TRUE)
		return TRUE;

	/* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
	/* this should speed up detection for some loops */
	if(dep->circular_path_checked==TRUE)
		return FALSE;

	/* set the check flag so we don't get into an infinite loop */
	dep->circular_path_checked=TRUE;

	/* is this host dependent on the root host? */
	if(dep!=root_dep){
		if(root_dep->dependent_host_ptr==dep->master_host_ptr){
			root_dep->contains_circular_path=TRUE;
			dep->contains_circular_path=TRUE;
			return TRUE;
		        }
	        }

	/* notification dependencies are ok at this point as long as they don't inherit */
	if(dependency_type==NOTIFICATION_DEPENDENCY && dep->inherits_parent==FALSE)
		return FALSE;

	/* check all parent dependencies */
	for(temp_hd=hostdependency_list;temp_hd!=NULL;temp_hd=temp_hd->next){

		/* only check parent dependencies */
		if(dep->master_host_ptr!=temp_hd->dependent_host_ptr)
			continue;

		if(check_for_circular_hostdependency_path(root_dep,temp_hd,dependency_type)==TRUE)
			return TRUE;
	        }

	return FALSE;
        }

#endif




/******************************************************************/
/******************* OBJECT DELETION FUNCTIONS ********************/
/******************************************************************/


/* free all allocated memory for objects */
int free_object_data(void){
	timeperiod *this_timeperiod=NULL;
	timeperiod *next_timeperiod=NULL;
	daterange *this_daterange=NULL;
	daterange *next_daterange=NULL;
	timerange *this_timerange=NULL;
	timerange *next_timerange=NULL;
	timeperiodexclusion *this_timeperiodexclusion=NULL;
	timeperiodexclusion *next_timeperiodexclusion=NULL;
	host *this_host=NULL;
	host *next_host=NULL;
	hostsmember *this_hostsmember=NULL;
	hostsmember *next_hostsmember=NULL;
	hostgroup *this_hostgroup=NULL;
	hostgroup *next_hostgroup=NULL;
	servicegroup *this_servicegroup=NULL;
	servicegroup *next_servicegroup=NULL;
	servicesmember *this_servicesmember=NULL;
	servicesmember *next_servicesmember=NULL;
	contact	*this_contact=NULL;
	contact *next_contact=NULL;
	contactgroup *this_contactgroup=NULL;
	contactgroup *next_contactgroup=NULL;
	contactsmember *this_contactsmember=NULL;
	contactsmember *next_contactsmember=NULL;
	contactgroupsmember *this_contactgroupsmember=NULL;
	contactgroupsmember *next_contactgroupsmember=NULL;
	customvariablesmember *this_customvariablesmember=NULL;
	customvariablesmember *next_customvariablesmember=NULL;
	service *this_service=NULL;
	service *next_service=NULL;
	command *this_command=NULL;
	command *next_command=NULL;
	commandsmember *this_commandsmember=NULL;
	commandsmember *next_commandsmember=NULL;
	serviceescalation *this_serviceescalation=NULL;
	serviceescalation *next_serviceescalation=NULL;
	servicedependency *this_servicedependency=NULL;
	servicedependency *next_servicedependency=NULL;
	hostdependency *this_hostdependency=NULL;
	hostdependency *next_hostdependency=NULL;
	hostescalation *this_hostescalation=NULL;
	hostescalation *next_hostescalation=NULL;
        escalation_condition *this_escalation_condition=NULL;
        escalation_condition *next_escalation_condition=NULL;
	register int x=0;
	register int i=0;


	/**** free memory for the timeperiod list ****/
	this_timeperiod=timeperiod_list;
	while(this_timeperiod!=NULL){

		/* free the exception time ranges contained in this timeperiod */
		for(x=0;x<DATERANGE_TYPES;x++){

			for(this_daterange=this_timeperiod->exceptions[x];this_daterange!=NULL;this_daterange=next_daterange){
				next_daterange=this_daterange->next;
				for(this_timerange=this_daterange->times;this_timerange!=NULL;this_timerange=next_timerange){
					next_timerange=this_timerange->next;
					my_free(this_timerange);
					}
				my_free(this_daterange);
			        }
		        }

		/* free the day time ranges contained in this timeperiod */
		for(x=0;x<7;x++){

			for(this_timerange=this_timeperiod->days[x];this_timerange!=NULL;this_timerange=next_timerange){
				next_timerange=this_timerange->next;
				my_free(this_timerange);
			        }
		        }

		/* free exclusions */
		for(this_timeperiodexclusion=this_timeperiod->exclusions;this_timeperiodexclusion!=NULL;this_timeperiodexclusion=next_timeperiodexclusion){
			next_timeperiodexclusion=this_timeperiodexclusion->next;
			my_free(this_timeperiodexclusion->timeperiod_name);
			my_free(this_timeperiodexclusion);
			}

		next_timeperiod=this_timeperiod->next;
		my_free(this_timeperiod->name);
		my_free(this_timeperiod->alias);
		my_free(this_timeperiod);
		this_timeperiod=next_timeperiod;
		}

	/* reset pointers */
	timeperiod_list=NULL;


	/**** free memory for the host list ****/
	this_host=host_list;
	while(this_host!=NULL){

		next_host=this_host->next;

		/* free memory for parent hosts */
		this_hostsmember=this_host->parent_hosts;
		while(this_hostsmember!=NULL){
			next_hostsmember=this_hostsmember->next;
			my_free(this_hostsmember->host_name);
			my_free(this_hostsmember);
			this_hostsmember=next_hostsmember;
			}

		/* free memory for child host links */
		this_hostsmember=this_host->child_hosts;
		while(this_hostsmember!=NULL){
			next_hostsmember=this_hostsmember->next;
			my_free(this_hostsmember->host_name);
			my_free(this_hostsmember);
			this_hostsmember=next_hostsmember;
			}

		/* free memory for service links */
		this_servicesmember=this_host->services;
		while(this_servicesmember!=NULL){
			next_servicesmember=this_servicesmember->next;
			my_free(this_servicesmember->host_name);
			my_free(this_servicesmember->service_description);
			my_free(this_servicesmember);
			this_servicesmember=next_servicesmember;
			}

		/* free memory for contact groups */
		this_contactgroupsmember=this_host->contact_groups;
		while(this_contactgroupsmember!=NULL){
			next_contactgroupsmember=this_contactgroupsmember->next;
			my_free(this_contactgroupsmember->group_name);
			my_free(this_contactgroupsmember);
			this_contactgroupsmember=next_contactgroupsmember;
			}

		/* free memory for contacts */
		this_contactsmember=this_host->contacts;
		while(this_contactsmember!=NULL){
			next_contactsmember=this_contactsmember->next;
			my_free(this_contactsmember->contact_name);
			my_free(this_contactsmember);
			this_contactsmember=next_contactsmember;
			}

		/* free memory for custom variables */
		this_customvariablesmember=this_host->custom_variables;
		while(this_customvariablesmember!=NULL){
			next_customvariablesmember=this_customvariablesmember->next;
			my_free(this_customvariablesmember->variable_name);
			my_free(this_customvariablesmember->variable_value);
			my_free(this_customvariablesmember);
			this_customvariablesmember=next_customvariablesmember;
		        }

		my_free(this_host->name);
		my_free(this_host->display_name);
		my_free(this_host->alias);
		my_free(this_host->address);
#ifdef NSCORE
		my_free(this_host->plugin_output);
		my_free(this_host->long_plugin_output);
		my_free(this_host->perf_data);

		free_objectlist(&this_host->hostgroups_ptr);
#endif
		my_free(this_host->check_period);
		my_free(this_host->host_check_command);
		my_free(this_host->event_handler);
		my_free(this_host->failure_prediction_options);
		my_free(this_host->notification_period);
		my_free(this_host->notes);
		my_free(this_host->notes_url);
		my_free(this_host->action_url);
		my_free(this_host->icon_image);
		my_free(this_host->icon_image_alt);
		my_free(this_host->vrml_image);
		my_free(this_host->statusmap_image);
		my_free(this_host);
		this_host=next_host;
	        }

	/* reset pointers */
	host_list=NULL;


	/**** free memory for the host group list ****/
	this_hostgroup=hostgroup_list;
	while(this_hostgroup!=NULL){

		/* free memory for the group members */
		this_hostsmember=this_hostgroup->members;
		while(this_hostsmember!=NULL){
			next_hostsmember=this_hostsmember->next;
			my_free(this_hostsmember->host_name);
			my_free(this_hostsmember);
			this_hostsmember=next_hostsmember;
		        }

		next_hostgroup=this_hostgroup->next;
		my_free(this_hostgroup->group_name);
		my_free(this_hostgroup->alias);
		my_free(this_hostgroup->notes);
		my_free(this_hostgroup->notes_url);
		my_free(this_hostgroup->action_url);
		my_free(this_hostgroup);
		this_hostgroup=next_hostgroup;
		}

	/* reset pointers */
	hostgroup_list=NULL;


	/**** free memory for the service group list ****/
	this_servicegroup=servicegroup_list;
	while(this_servicegroup!=NULL){

		/* free memory for the group members */
		this_servicesmember=this_servicegroup->members;
		while(this_servicesmember!=NULL){
			next_servicesmember=this_servicesmember->next;
			my_free(this_servicesmember->host_name);
			my_free(this_servicesmember->service_description);
			my_free(this_servicesmember);
			this_servicesmember=next_servicesmember;
		        }

		next_servicegroup=this_servicegroup->next;
		my_free(this_servicegroup->group_name);
		my_free(this_servicegroup->alias);
		my_free(this_servicegroup->notes);
		my_free(this_servicegroup->notes_url);
		my_free(this_servicegroup->action_url);
		my_free(this_servicegroup);
		this_servicegroup=next_servicegroup;
		}

	/* reset pointers */
	servicegroup_list=NULL;


	/**** free memory for the contact list ****/
	this_contact=contact_list;
	while(this_contact!=NULL){
	  
		/* free memory for the host notification commands */
		this_commandsmember=this_contact->host_notification_commands;
		while(this_commandsmember!=NULL){
			next_commandsmember=this_commandsmember->next;
			if(this_commandsmember->command!=NULL)
				my_free(this_commandsmember->command);
			my_free(this_commandsmember);
			this_commandsmember=next_commandsmember;
		        }

		/* free memory for the service notification commands */
		this_commandsmember=this_contact->service_notification_commands;
		while(this_commandsmember!=NULL){
			next_commandsmember=this_commandsmember->next;
			if(this_commandsmember->command!=NULL)
				my_free(this_commandsmember->command);
			my_free(this_commandsmember);
			this_commandsmember=next_commandsmember;
		        }

		/* free memory for custom variables */
		this_customvariablesmember=this_contact->custom_variables;
		while(this_customvariablesmember!=NULL){
			next_customvariablesmember=this_customvariablesmember->next;
			my_free(this_customvariablesmember->variable_name);
			my_free(this_customvariablesmember->variable_value);
			my_free(this_customvariablesmember);
			this_customvariablesmember=next_customvariablesmember;
		        }

		next_contact=this_contact->next;
		my_free(this_contact->name);
		my_free(this_contact->alias);
		my_free(this_contact->email);
		my_free(this_contact->pager);
		for(i=0;i<MAX_CONTACT_ADDRESSES;i++)
			my_free(this_contact->address[i]);
		my_free(this_contact->host_notification_period);
		my_free(this_contact->service_notification_period);

#ifdef NSCORE
		free_objectlist(&this_contact->contactgroups_ptr);
#endif

		my_free(this_contact);
		this_contact=next_contact;
		}

	/* reset pointers */
	contact_list=NULL;


	/**** free memory for the contact group list ****/
	this_contactgroup=contactgroup_list;
	while(this_contactgroup!=NULL){

		/* free memory for the group members */
		this_contactsmember=this_contactgroup->members;
		while(this_contactsmember!=NULL){
			next_contactsmember=this_contactsmember->next;
			my_free(this_contactsmember->contact_name);
			my_free(this_contactsmember);
			this_contactsmember=next_contactsmember;
		        }

		next_contactgroup=this_contactgroup->next;
		my_free(this_contactgroup->group_name);
		my_free(this_contactgroup->alias);
		my_free(this_contactgroup);
		this_contactgroup=next_contactgroup;
		}

	/* reset pointers */
	contactgroup_list=NULL;


	/**** free memory for the service list ****/
	this_service=service_list;
	while(this_service!=NULL){

		next_service=this_service->next;

		/* free memory for contact groups */
		this_contactgroupsmember=this_service->contact_groups;
		while(this_contactgroupsmember!=NULL){
			next_contactgroupsmember=this_contactgroupsmember->next;
			my_free(this_contactgroupsmember->group_name);
			my_free(this_contactgroupsmember);
			this_contactgroupsmember=next_contactgroupsmember;
	                }

		/* free memory for contacts */
		this_contactsmember=this_service->contacts;
		while(this_contactsmember!=NULL){
			next_contactsmember=this_contactsmember->next;
			my_free(this_contactsmember->contact_name);
			my_free(this_contactsmember);
			this_contactsmember=next_contactsmember;
			}

		/* free memory for custom variables */
		this_customvariablesmember=this_service->custom_variables;
		while(this_customvariablesmember!=NULL){
			next_customvariablesmember=this_customvariablesmember->next;
			my_free(this_customvariablesmember->variable_name);
			my_free(this_customvariablesmember->variable_value);
			my_free(this_customvariablesmember);
			this_customvariablesmember=next_customvariablesmember;
		        }

		my_free(this_service->host_name);
		my_free(this_service->description);
		my_free(this_service->display_name);
		my_free(this_service->service_check_command);
#ifdef NSCORE
		my_free(this_service->plugin_output);
		my_free(this_service->long_plugin_output);
		my_free(this_service->perf_data);

		my_free(this_service->event_handler_args);
		my_free(this_service->check_command_args);

		free_objectlist(&this_service->servicegroups_ptr);
#endif
		my_free(this_service->notification_period);
		my_free(this_service->check_period);
		my_free(this_service->event_handler);
		my_free(this_service->failure_prediction_options);
		my_free(this_service->notes);
		my_free(this_service->notes_url);
		my_free(this_service->action_url);
		my_free(this_service->icon_image);
		my_free(this_service->icon_image_alt);
		my_free(this_service);
		this_service=next_service;
	        }

	/* reset pointers */
	service_list=NULL;


	/**** free memory for the command list ****/
	this_command=command_list;
	while(this_command!=NULL){
		next_command=this_command->next;
		my_free(this_command->name);
		my_free(this_command->command_line);
		my_free(this_command);
		this_command=next_command;
	        }

	/* reset pointers */
	command_list=NULL;


	/**** free memory for the service escalation list ****/
	this_serviceescalation=serviceescalation_list;
	while(this_serviceescalation!=NULL){

		/* free memory for the contact group members */
		this_contactgroupsmember=this_serviceescalation->contact_groups;
		while(this_contactgroupsmember!=NULL){
			next_contactgroupsmember=this_contactgroupsmember->next;
			my_free(this_contactgroupsmember->group_name);
			my_free(this_contactgroupsmember);
			this_contactgroupsmember=next_contactgroupsmember;
		        }

		/* free memory for contacts */
		this_contactsmember=this_serviceescalation->contacts;
		while(this_contactsmember!=NULL){
			next_contactsmember=this_contactsmember->next;
			my_free(this_contactsmember->contact_name);
			my_free(this_contactsmember);
			this_contactsmember=next_contactsmember;
			}

                /* free memory for escalation_conditions */
                this_escalation_condition=this_serviceescalation->condition;
                while(this_escalation_condition!=NULL){
                        next_escalation_condition=this_escalation_condition->next;
                        my_free(this_escalation_condition->host_name);
                        my_free(this_escalation_condition->service_description);
                        my_free(this_escalation_condition);
                        this_escalation_condition=next_escalation_condition;
                        }

		next_serviceescalation=this_serviceescalation->next;
		my_free(this_serviceescalation->host_name);
		my_free(this_serviceescalation->description);
		my_free(this_serviceescalation->escalation_period);
		my_free(this_serviceescalation);
		this_serviceescalation=next_serviceescalation;
	        }

	/* reset pointers */
	serviceescalation_list=NULL;


	/**** free memory for the service dependency list ****/
	this_servicedependency=servicedependency_list;
	while(this_servicedependency!=NULL){
		next_servicedependency=this_servicedependency->next;
		my_free(this_servicedependency->dependency_period);
		my_free(this_servicedependency->dependent_host_name);
		my_free(this_servicedependency->dependent_service_description);
		my_free(this_servicedependency->host_name);
		my_free(this_servicedependency->service_description);
		my_free(this_servicedependency);
		this_servicedependency=next_servicedependency;
	        }

	/* reset pointers */
	servicedependency_list=NULL;


	/**** free memory for the host dependency list ****/
	this_hostdependency=hostdependency_list;
	while(this_hostdependency!=NULL){
		next_hostdependency=this_hostdependency->next;
		my_free(this_hostdependency->dependency_period);
		my_free(this_hostdependency->dependent_host_name);
		my_free(this_hostdependency->host_name);
		my_free(this_hostdependency);
		this_hostdependency=next_hostdependency;
	        }

	/* reset pointers */
	hostdependency_list=NULL;


	/**** free memory for the host escalation list ****/
	this_hostescalation=hostescalation_list;
	while(this_hostescalation!=NULL){

		/* free memory for the contact group members */
		this_contactgroupsmember=this_hostescalation->contact_groups;
		while(this_contactgroupsmember!=NULL){
			next_contactgroupsmember=this_contactgroupsmember->next;
			my_free(this_contactgroupsmember->group_name);
			my_free(this_contactgroupsmember);
			this_contactgroupsmember=next_contactgroupsmember;
		        }

		/* free memory for contacts */
		this_contactsmember=this_hostescalation->contacts;
		while(this_contactsmember!=NULL){
			next_contactsmember=this_contactsmember->next;
			my_free(this_contactsmember->contact_name);
			my_free(this_contactsmember);
			this_contactsmember=next_contactsmember;
			}

                /* free memory for escalation_conditions */
                this_escalation_condition=this_hostescalation->condition;
                while(this_escalation_condition!=NULL){
                        next_escalation_condition=this_escalation_condition->next;
                        my_free(this_escalation_condition->host_name);
                        my_free(this_escalation_condition->service_description);
                        my_free(this_escalation_condition);
                        this_escalation_condition=next_escalation_condition;
                        }

		next_hostescalation=this_hostescalation->next;
		my_free(this_hostescalation->host_name);
		my_free(this_hostescalation->escalation_period);
		my_free(this_hostescalation);
		this_hostescalation=next_hostescalation;
	        }

	/* reset pointers */
	hostescalation_list=NULL;

	/* free object skiplists */
	free_object_skiplists();

	return OK;
        }