[Nagios-checkins] SF.net SVN: nagios:[2111] nagioscore/trunk

ageric at users.sourceforge.net ageric at users.sourceforge.net
Sun Aug 26 20:09:06 UTC 2012


Revision: 2111
          http://nagios.svn.sourceforge.net/nagios/?rev=2111&view=rev
Author:   ageric
Date:     2012-08-26 20:09:06 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
base/notifications: Remove some duplicated code

There are at least two places where contacts are located either by
name or by alias. This patch replaces those two places within
notifications.c with a small helper and a call to that helper.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/base/notifications.c
    nagioscore/trunk/include/shared.h

Modified: nagioscore/trunk/base/notifications.c
===================================================================
--- nagioscore/trunk/base/notifications.c	2012-08-26 20:08:28 UTC (rev 2110)
+++ nagioscore/trunk/base/notifications.c	2012-08-26 20:09:06 UTC (rev 2111)
@@ -47,7 +47,21 @@
 extern char            *generic_summary;
 
 
+/*** silly helpers ****/
+static contact *find_contact_by_name_or_alias(const char *name)
+{
+	contact *c = NULL;
 
+	if (!name || !(c = find_contact(name)))
+		return c;
+	for (c = contact_list; c; c = c->next)
+		if (!strcmp(c->alias, name))
+			break;
+
+	return c;
+}
+
+
 /******************************************************************/
 /***************** SERVICE NOTIFICATION FUNCTIONS *****************/
 /******************************************************************/
@@ -150,14 +164,7 @@
 
 		/* if this notification has an author, attempt to lookup the associated contact */
 		if(not_author != NULL) {
-
-			/* see if we can find the contact - first by name, then by alias */
-			if((temp_contact = find_contact(not_author)) == NULL) {
-				for(temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
-					if(!strcmp(temp_contact->alias, not_author))
-						break;
-					}
-				}
+			temp_contact = find_contact_by_name_or_alias(not_author);
 			}
 
 		/* get author and comment macros */
@@ -1120,14 +1127,7 @@
 
 		/* if this notification has an author, attempt to lookup the associated contact */
 		if(not_author != NULL) {
-
-			/* see if we can find the contact - first by name, then by alias */
-			if((temp_contact = find_contact(not_author)) == NULL) {
-				for(temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
-					if(!strcmp(temp_contact->alias, not_author))
-						break;
-					}
-				}
+			temp_contact = find_contact_by_name_or_alias(not_author);
 			}
 
 		/* get author and comment macros */

Modified: nagioscore/trunk/include/shared.h
===================================================================
--- nagioscore/trunk/include/shared.h	2012-08-26 20:08:28 UTC (rev 2110)
+++ nagioscore/trunk/include/shared.h	2012-08-26 20:09:06 UTC (rev 2111)
@@ -33,6 +33,8 @@
 	unsigned int servicegroups;
 	};
 
+extern struct object_count num_objects;
+
 extern char *my_strtok(char *buffer, char *tokens);
 extern char *my_strsep(char **stringp, const char *delim);
 extern mmapfile *mmap_fopen(char *filename);

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list