[NeoStats-Devel] [Commits] r2632 - in trunk: . include src

[email protected]
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Fish
Date: Sat Jun 11 14:09:46 2005
New Revision: 2632

Added:
   trunk/src/updates.c   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/include/neostats.h
   trunk/src/Makefile.am
   trunk/src/Makefile.in
   trunk/src/ircsend.c
   trunk/src/main.c
   trunk/src/sock.c
Log:
updates to support OPSB targetip and sending open proxy reports to secure.irc-chat.net

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Sat Jun 11 14:09:46 2005
@@ -4,6 +4,10 @@
 Fish (F), Mark (M), DeadNotBuried (D)
 ===============================================================================
 * NeoStats * Version 3.0.a3-dev
+ - Move Secure.irc-chat.net update code to core to allow OPSB to use it as
+   well (F)
+ - Store the IP address we connect to in tme so we can reference it from
+   other modules (F) 
  - allow SERVICEROOT to check against IP Address as well as Host (D)
  - check if exclusions are already included in list before adding (D)
  - attempt to find bot unused nickname when both nick and altnick in use (D)

Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h	(original)
+++ trunk/include/neostats.h	Sat Jun 11 14:09:46 2005
@@ -637,6 +637,7 @@
 	char version[VERSIONSIZE];
 	int dobind;
 	struct sockaddr_in lsa;
+	struct sockaddr_in srvip;
 	time_t tslastping;
 	int ulag;
 } tme;
@@ -996,13 +997,6 @@
 	void *data;
 	/* if socktype = SOCK_STANDARD, function calls */
 	/** Socket read function */
-#if 0
-	sock_func readfnc;
-	/** Socket write function */
-	sock_func writefnc;
-	/** Socket error function */
-	sock_func errfnc;
-#endif
 	/** rmsgs */
 	long rmsgs;
 	/** rbytes */
@@ -1587,4 +1581,13 @@
 #define SetBotModValue( b, data ) b->moddata = data
 #define GetBotModValue( b ) b->moddata
 
+/* MQ Server update sending functions */
+typedef enum MQ_MSG_TYPE {
+	UPDATE_SSREPORT=1,
+	UPDATE_OPSBREPORT,
+} MQ_MSG_TYPE;
+
+EXPORTFUNC void sendtoMQ( MQ_MSG_TYPE type, void *data, size_t len);
+int InitUpdate();
+
 #endif /* NEOSTATS_H */

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Jun 11 14:09:46 2005
@@ -11,7 +11,7 @@
 		base64.c numerics.c settings.c botinfo.c \
 		adnscheck.c adnsevent.c adnsgeneral.c adnsparse.c adnsquery.c \
 		adnsreply.c adnssetup.c adnstransmit.c adnstypes.c \
-		oscalls.c ossocket.c osfile.c 
+		oscalls.c ossocket.c osfile.c updates.c
 AM_CFLAGS = @PCRE_CFLAGS@ @CURL_CFLAGS@ -DNEOSTATSCORE \
 		-I$(top_srcdir)/lib/event
 neostats_LDADD = @PCRE_LIBS@ @CURL_LIBS@ @LIBDB@ \

Modified: trunk/src/Makefile.in
==============================================================================
--- trunk/src/Makefile.in	(original)
+++ trunk/src/Makefile.in	Sat Jun 11 14:09:46 2005
@@ -74,7 +74,7 @@
 	adnsgeneral.$(OBJEXT) adnsparse.$(OBJEXT) adnsquery.$(OBJEXT) \
 	adnsreply.$(OBJEXT) adnssetup.$(OBJEXT) adnstransmit.$(OBJEXT) \
 	adnstypes.$(OBJEXT) oscalls.$(OBJEXT) ossocket.$(OBJEXT) \
-	osfile.$(OBJEXT)
+	osfile.$(OBJEXT) updates.$(OBJEXT)
 neostats_OBJECTS = $(am_neostats_OBJECTS)
 neostats_DEPENDENCIES = $(top_srcdir)/lib/event/libevent.a
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
@@ -231,7 +231,7 @@
 		base64.c numerics.c settings.c botinfo.c \
 		adnscheck.c adnsevent.c adnsgeneral.c adnsparse.c adnsquery.c \
 		adnsreply.c adnssetup.c adnstransmit.c adnstypes.c \
-		oscalls.c ossocket.c osfile.c 
+		oscalls.c ossocket.c osfile.c updates.c
 
 AM_CFLAGS = @PCRE_CFLAGS@ @CURL_CFLAGS@ -DNEOSTATSCORE \
 		-I$(top_srcdir)/lib/event
@@ -355,6 +355,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/support.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transfer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/updates.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/users.Po@am__quote@
 
 mostlyclean-libtool:

Modified: trunk/src/ircsend.c
==============================================================================
--- trunk/src/ircsend.c	(original)
+++ trunk/src/ircsend.c	Sat Jun 11 14:09:46 2005
@@ -144,9 +144,10 @@
 static void _send_svspart( const char *source, const char *target, const char *chan );
 static void _send_svsmode( const char *source, const char *target, const char *modes );
 static void _send_svskill( const char *source, const char *target, const char *reason );
-#if 0 /* Work in progress */
+
 static void _send_akill( const char *source, const char *host, const char *ident, const char *setby, const unsigned long length, const char *reason, const unsigned long ts );
 static void _send_rakill( const char *source, const char *host, const char *ident );
+#if 0 /* Work in progress */
 static void _send_sqline( const char *source, const char *mask, const char *reason );
 static void _send_unsqline( const char *source, const char *mask );
 static void _send_sgline( const char *source, const char *mask, const char *reason );
@@ -190,9 +191,10 @@
 	{( void * )&irc_send_swhois, NULL, "send_swhois", NULL, NULL, NULL, NULL, 0, FEATURE_SWHOIS},
 	{( void * )&irc_send_smo, NULL, "send_smo", NULL, NULL, NULL, NULL, 0, FEATURE_SMO},
 	{( void * )&irc_send_svstime, NULL, "send_svstime", NULL, NULL, NULL, NULL, 0, FEATURE_SVSTIME},
-#if 0 /* Work in progress */
+
 	{( void * )&irc_send_akill, NULL, "send_akill", &MSG_AKILL, "MSG_AKILL", &TOK_AKILL, "TOK_AKILL", 0, 0},
 	{( void * )&irc_send_rakill, NULL, "send_rakill", &MSG_RAKILL, "MSG_RAKILL", &TOK_RAKILL, "TOK_RAKILL", 0, 0},
+#if 0 /* Work in progress */
 	{( void * )&irc_send_sqline, NULL, "send_sqline", &MSG_UNSQLINE, "MSG_UNSQLINE", &TOK_UNSQLINE, "TOK_UNSQLINE", 0, 0},
 	{( void * )&irc_send_unsqline, NULL, "send_unsqline", &MSG_SQLINE, "MSG_SQLINE", &TOK_SQLINE, "TOK_SQLINE", 0, 0},
 	{( void * )&irc_send_zline, NULL, "send_zline", &MSG_ZLINE, "MSG_ZLINE", &TOK_ZLINE, "TOK_ZLINE", 0, 0},

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Sat Jun 11 14:09:46 2005
@@ -427,6 +427,7 @@
 	   _fini problems when we fork */
 	ConfLoadModules();
 	/* Connect to server */
+	InitUpdate();
 	Connect();
 #ifdef WIN32
 	return 0;

Modified: trunk/src/sock.c
==============================================================================
--- trunk/src/sock.c	(original)
+++ trunk/src/sock.c	Sat Jun 11 14:09:46 2005
@@ -98,16 +98,15 @@
 static OS_SOCKET ConnectTo (char *host, int port)
 {
 	struct hostent *hp;
-	struct sockaddr_in sa;
 	OS_SOCKET s;
 
 	if ((hp = gethostbyname (host)) == NULL) {
 		return NS_FAILURE;
 	}
-	os_memset( &sa, 0, sizeof( sa ) );
-	sa.sin_family = AF_INET;
-	sa.sin_port = htons (port);
-	os_memcpy( ( char * ) &sa.sin_addr, hp->h_addr, hp->h_length );
+	os_memset( &me.srvip, 0, sizeof( me.srvip ) );
+	me.srvip.sin_family = AF_INET;
+	me.srvip.sin_port = htons (port);
+	os_memcpy( ( char * ) &me.srvip.sin_addr, hp->h_addr, hp->h_length );
 	if( ( s = os_sock_socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 )
 	{
 		return NS_FAILURE;
@@ -116,7 +115,7 @@
 	{
 		os_sock_bind( s, ( struct sockaddr * ) &me.lsa, sizeof( me.lsa ) );
 	}
-	if( os_sock_connect( s, ( struct sockaddr * ) &sa, sizeof( sa ) ) != 0 ) 
+	if( os_sock_connect( s, ( struct sockaddr * ) &me.srvip, sizeof( me.srvip ) ) != 0 ) 
 	{
 		os_sock_close (s);
 		return NS_FAILURE;
@@ -155,7 +154,6 @@
 	int maxfdsunused;
 #endif
 
-	printf("readloop called\n");
 	me.lastmsg = me.now;
 	while (1) { /* loop till we get a error */
 		SET_SEGV_LOCATION();

Added: trunk/src/updates.c
==============================================================================
--- (empty file)
+++ trunk/src/updates.c	Sat Jun 11 14:09:46 2005
@@ -0,0 +1,86 @@
+/* NeoStats - IRC Statistical Services 
+** Copyright (c) 1999-2005 Adam Rutter, Justin Hammond, Mark Hetherington
+** http://www.neostats.net/
+**
+**  This program is free software; you can redistribute it and/or modify
+**  it under the terms of the GNU General Public License as published by
+**  the Free Software Foundation; either version 2 of the License, or
+**  (at your option) any later version.
+**
+**  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+**  USA
+**
+** NeoStats CVS Identification
+** $Id$
+*/
+
+/* @file NeoStats interface to send updates back to NeoStats/Secure.irc-chat.net
+ */
+
+#include "neostats.h"
+
+void GotUpdateAddress(void *data, adns_answer *a);
+
+struct updateserver {
+	int ok;
+	struct sockaddr_in sendtomq;
+	int sock;
+} mqs;
+
+int InitUpdate(void) 
+{
+	mqs.ok = 0;
+	dns_lookup( "mqpool.neostats.net",  adns_r_a, GotUpdateAddress, NULL );
+	dlog(DEBUG1, "Updates Initialized successfully");
+	return NS_SUCCESS;
+}
+
+void FiniUpdate(void) 
+{
+}
+
+void GotUpdateAddress(void *data, adns_answer *a) 
+{
+	char *url;
+	int i, len, ri;
+
+	SET_SEGV_LOCATION();
+	adns_rr_info(a->type, 0, 0, &len, 0, 0);
+	for(i = 0; i < a->nrrs;  i++) {
+		ri = adns_rr_info(a->type, 0, 0, 0, a->rrs.bytes +i*len, &url);
+		if (!ri) {
+			/* ok, we got a valid answer, lets maybe kick of the update check.*/
+			mqs.sendtomq.sin_addr.s_addr = inet_addr(url);
+			mqs.sendtomq.sin_port = htons(2335);
+			mqs.sendtomq.sin_family = AF_INET;
+			mqs.sock = socket(AF_INET, SOCK_DGRAM, 0);
+			mqs.ok = 1;
+			nlog (LOG_NORMAL, "Got DNS for MQ Pool Server: %s", url);
+		} else {
+			nlog(LOG_WARNING, "DNS error Checking for MQ Server Pool: %s", adns_strerror(ri));
+		}
+		ns_free (url);
+	}
+	if (a->nrrs < 1) {
+		nlog(LOG_WARNING, "DNS Error checking for MQ Server Pool");
+	}
+}
+void sendtoMQ( MQ_MSG_TYPE type, void *data, size_t len) {
+	char *buf;
+	
+	if (mqs.ok == 1) {
+		/* for now, we know that data is always a char string */
+		buf = malloc(sizeof(int) + len);
+		ircsnprintf(buf, (sizeof(int)+len+1), "%d\n%s", type, (char *)data);
+		dlog(DEBUG1, "Send Update: %s", buf);
+		sendto(mqs.sock, buf, strlen(buf), 0,  (struct sockaddr *) &mqs.sendtomq, sizeof(mqs.sendtomq));
+		free(buf);
+	}
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.