Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > e7700dc12cf26945b8589c73fc931a2c > files > 4

rrdcollect-0.2.9-4.mga3.src.rpm

diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/include/rrdcollect.h rrdcollect-0.2.4-socket/include/rrdcollect.h
--- rrdcollect-0.2.4/include/rrdcollect.h	2009-02-25 15:40:37.000000000 +0100
+++ rrdcollect-0.2.4-socket/include/rrdcollect.h	2009-05-18 19:13:33.000000000 +0200
@@ -148,6 +148,7 @@ struct uri_t {
 		RRDCOLLECT_SNMP
 	}
 	*/
+	unsigned port;
 	const char *host;
 	const char *path;
 };
diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/counters.c rrdcollect-0.2.4-socket/src/counters.c
--- rrdcollect-0.2.4/src/counters.c	2009-02-25 15:40:37.000000000 +0100
+++ rrdcollect-0.2.4-socket/src/counters.c	2009-05-18 19:17:23.000000000 +0200
@@ -20,6 +20,9 @@
 
 #include "rrdcollect.h"
 
+#include <netinet/in.h>
+#include <netdb.h>
+
 struct rrd_t **rrd = NULL;
 int rrd_count = 0;
 
@@ -111,14 +114,29 @@ void perform_tests()
 {
 	int i;
 	for (i = 0; i < test_count; i++) {
-		FILE *input;
+		FILE *input = NULL;
 		int n;
 		int line = 0;
 
 #ifdef ENABLE_EXEC
 		/* Horribly ugly and shameful code... */
-		if (*(test[i]->uri->domain) == 'e') { /* exec */
+		if (strcmp(test[i]->uri->domain, "exec") == 0) {
 			input = popen(test[i]->uri->path, "r");
+		} else if (strcmp(test[i]->uri->domain, "socket") == 0) { 
+			int sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+			struct sockaddr_in server;
+			struct hostent *host;
+
+			server.sin_family = AF_INET;
+			server.sin_port = htons(test[i]->uri->port);
+			server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+			host = gethostbyname(test[i]->uri->host);
+			if (host)
+				server.sin_addr.s_addr = *(uint32_t *)host->h_addr_list[0];
+
+			if (connect(sock, (struct sockaddr *)&server, sizeof(server)) >= 0)
+				input = fdopen(sock, "r");
 		} else { /* file */
 #endif /* ENABLE_EXEC */
 			input = fopen(test[i]->uri->path, "r");
@@ -127,7 +145,7 @@ void perform_tests()
 #endif /* ENABLE_EXEC */
 
 		if (!input) {
-			send_log(LOG_ERR, "Cannot open file %s: %s\n", test[i]->uri->path, strerror(errno));
+			send_log(LOG_ERR, "Cannot open %s: %s\n", test[i]->uri->path, strerror(errno));
 			errno = 0;
 			continue; /* FIXME: more intelligent error handling! */
 		}
@@ -157,7 +175,7 @@ void perform_tests()
 		}
 
 #ifdef ENABLE_EXEC
-		if (*(test[i]->uri->domain) == 'e') { /* exec */
+		if (strcmp(test[i]->uri->domain, "exec") == 0) {
 			pclose(input);
 		} else {
 #endif /* ENABLE_EXEC */
diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/parse.c rrdcollect-0.2.4-socket/src/parse.c
--- rrdcollect-0.2.4/src/parse.c	2009-02-25 15:41:24.000000000 +0100
+++ rrdcollect-0.2.4-socket/src/parse.c	2009-05-18 19:20:23.000000000 +0200
@@ -164,28 +164,39 @@ static char *find_host_end(char *line)
 static int get_uri(char *domain, struct uri_t *uri)
 {
 	char *dend, *host, *path;
+	char *port;
        
 	if (!(dend = find_domain_end(domain)))
 		return 1;
 
-	host = dend+2;
+	host = dend + 3;
 
 	if (!(path = find_host_end(host)))
 		return 2;
 
-	/* FIXME: smarted domain handling!!! */
+	/* FIXME: smarter domain handling!!! */
 	if (strncmp(domain, "file", dend-domain)
 #ifdef ENABLE_EXEC
-				&& strncmp(domain, "exec", dend-domain)
+		&& strncmp(domain, "exec", dend-domain)
 #endif /* ENABLE_EXEC*/
+		&& strncmp(domain, "socket", dend-domain)
 			) {
 		return 3;
 	}
 
+	uri->path = strdup(path);
+
 	/* Now we can modify the line */
-	*(path++) = '\0';
+	*path = '\0';
 	*dend = '\0';
 
+	/* check for port */
+	if ((port = index(host, ':'))) {
+		uri->port = atoi(port + 1);
+		*port = '\0';
+	} else
+		uri->port = 0;
+
 #ifdef ENABLE_EXEC
 	if(strcmp(domain,"exec")==0) {
 		if(path[0]!='/') {
@@ -199,7 +210,6 @@ static int get_uri(char *domain, struct 
 
 	uri->domain = strdup(domain);
 	uri->host = strdup(host);
-	uri->path = strdup(path);
 	
 	return 0;
 }
diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/scan.c rrdcollect-0.2.4-socket/src/scan.c
--- rrdcollect-0.2.4/src/scan.c	2007-07-28 18:42:49.000000000 +0200
+++ rrdcollect-0.2.4-socket/src/scan.c	2009-05-18 19:24:15.000000000 +0200
@@ -185,8 +185,13 @@ int scan(const char *buf, const char *fm
 				fmt++;
 				break;
 				
-			case ' ':
 			case '\t':
+				/* match zero spaces too */
+				if(!isspace(*(buf))) {
+					fmt++;
+					break;
+				}
+			case ' ':
 			case '\n':
 			case '\r':
 			case '\f':