[PATCH] Reduce duplication of code
Posted: Thu Jan 13, 2011 12:43 pm
--4SFOXa2GPu3tIq4H
Content-Type: multipart/mixed; boundary="jRHKVT23PllUwdXP"
Content-Disposition: inline
--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi,
I'm looking slightly longer term at extending cgi.cfg to support using
contact_group names in the authorized_for* settings, and this is step
one on the road. If someone thinks the above is a bad idea (or if reuse
of code is a bad idea) let me know and I'll stop.
Cheers,
--=20
--------------------------------------------------------------------------
| Stephen Gran | Perhaps the biggest disappointments |
| [email protected] | were the ones you expected anyway. |
| http://www.lobefin.net/~steve | |
--------------------------------------------------------------------------
--jRHKVT23PllUwdXP
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="0001-Reduce-duplication-of-code.patch"
Content-Transfer-Encoding: quoted-printable
=46rom c89a5c5c8ce190f437e75f8466c75cac5acff3fb Mon Sep 17 00:00:00 2001
=46rom: Stephen Gran
Date: Thu, 13 Jan 2011 12:38:50 +0000
Subject: [PATCH] Reduce duplication of code
We use the same code in several places instead of calling a function.
Call the function instead.
Signed-off-by: Stephen Gran
---
common/objects.c | 66 ++++++++++++++------------------------------------=
----
1 files changed, 17 insertions(+), 49 deletions(-)
diff --git a/common/objects.c b/common/objects.c
index cc1ec84..396fa67 100644
--- a/common/objects.c
+++ b/common/objects.c
@@ -2800,23 +2800,29 @@ int is_service_member_of_servicegroup(servicegroup =
*group, service *svc){
* The cgi's stopped using it quite long ago though, so we need only
* compile it if we're building the core
*/
-#ifdef NSCORE
int is_contact_member_of_contactgroup(contactgroup *group, contact *cntct)
{
contactsmember *member;
+ contact *temp_contact=3DNULL;
=20
if (!group || !cntct)
return FALSE;
=20
/* search all contacts in this contact group */
for (member =3D group->members; member; member =3D member->next) {
- if (member->contact_ptr =3D=3D cntct)
+#ifdef NSCORE
+ temp_contact=3Dmember->contact_ptr;
+#else
+ temp_contact=3Dfind_contact(member->contact_name);
+#endif
+ if(temp_contact=3D=3DNULL)
+ continue;
+ if (temp_contact =3D=3D cntct)
return TRUE;
}
=20
return FALSE;
}
-#endif /* NSCORE */
=20
/* tests whether a contact is a contact for a particular host */
int is_contact_for_host(host *hst, contact *cntct){
@@ -2851,18 +2857,8 @@ int is_contact_for_host(host *hst, contact *cntct){
#endif
if(temp_contactgroup=3D=3DNULL)
continue;
-
- for(temp_contactsmember=3Dtemp_contactgroup->members;temp_contactsmember=
!=3DNULL;temp_contactsmember=3Dtemp_contactsmember->next){
-#ifdef NSCORE
- temp_contact=3Dtemp_contactsmember->contact_ptr;
-#else
- temp_contact=3Dfind_contact(temp_contactsmember->contact_name);
-#endif
- if(temp_contact=3D=3DNULL)
- continue;
- if(temp_contact=3D=3Dcntct)
- return TRUE;
- }
+ if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
+ return TRUE;
}
=20
return FALSE;
@@ -2905,18 +2901,9 @@ int is_escalated_contact_for_host(host *hst, contact=
*cntct){
#endif
if(temp_contactgroup=3D=3DNULL)
continue;
+ if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
+ return TRUE;
=20
- for(temp_contactsmember=3Dtemp_contactgroup->members;temp_contactsmembe=
r!=3DNULL;temp_contactsmember=3Dtemp_contactsmember->next){
-#ifdef NSCORE
- temp_contact=3Dtemp_contactsmember->contact_ptr;
-#else
- temp_contact=3Dfind_contact(temp_contactsmember->contact_name);
-#endif
- if(temp_contact=3D=3DNULL)
- continue;
- if(temp_contact=3D=3Dcntct)
- return TRUE;
- }
}
}
=20
@@ -2955,18 +2942,9 @@ int is_contact_for_service(service *svc, contact *cn=
tct){
#endif
if(temp_contactgroup=3D=3DNULL)
continue;
+ if(is_contact_member_of_contactgroup(temp_contactgroup,cntct))
+
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]