[cvslog] (2006-08-20 15:23:16 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Sun Aug 20 09:23:16 CST 2006


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2006-08-20 15:23:15 UTC
Commited by: sven

Modified files:
     lib/eggdrop/linemode.c lib/eggdrop/linemode.h
     lib/eggdrop/sockbuf.c modules/script/scriptnet.c

Log message:

 * fixed some linebuf bugs about eaten lines, corrupted memory and stuff
 * added some meaningful return values
 * scripts can now call net_linemode without a second parameter to get     
   the current linebuf status
 * wrote some doxygen style comments as Bryan suggested back in february

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/linemode.c
diff -u eggdrop1.9/lib/eggdrop/linemode.c:1.7 eggdrop1.9/lib/eggdrop/linemode.c:1.8
--- eggdrop1.9/lib/eggdrop/linemode.c:1.7	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/lib/eggdrop/linemode.c	Sun Aug 20 10:23:05 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: linemode.c,v 1.7 2004-10-17 05:14:06 stdarg Exp $";
+static const char rcsid[] = "$Id: linemode.c,v 1.8 2006-08-20 15:23:05 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -96,8 +96,8 @@
 	/* If there is any buffered data, do one more on->read callback. */
 	if (old_data->len) {
 		old_data->data[old_data->len] = 0;
-		old_data->len = 0;
 		sockbuf_on_read(idx, LINEMODE_LEVEL, old_data->data, old_data->len);
+		old_data->len = 0;
 	}
 
 	/* And now continue the eof event chain. */
@@ -121,23 +121,62 @@
 	NULL, linemode_on_delete
 };
 
+/*!
+ * \brief Turns linebuffering on an index on
+ *
+ * \param idx the index to turn on linebuffering for
+ * \return 0 on success, -1 on error
+ */
+
 int linemode_on(int idx)
 {
 	linemode_t *old_data;
 
+	if (linemode_check(idx)) return -1;
 	old_data = calloc(1, sizeof(*old_data));
 	sockbuf_attach_filter(idx, &linemode_filter, old_data);
 	return(0);
 }
 
+/*!
+ * \brief Turns linebuffering on an index off
+ *
+ * If there if a line currently buffered it's send of immidiatly.
+ *
+ * \param idx the index to turn off linebuffering for
+ * \return 0 on success, -1 on error
+ */
+
 int linemode_off(int idx)
 {
+	int ret;
 	linemode_t *old_data;
 
-	sockbuf_detach_filter(idx, &linemode_filter, &old_data);
+	ret = sockbuf_detach_filter(idx, &linemode_filter, &old_data);
+	if (ret) return ret;
 	if (old_data) {
-		if (old_data->data) free(old_data->data);
+		if (old_data->data) {
+			if (old_data->len) {
+				old_data->data[old_data->len] = 0;
+				sockbuf_on_read(idx, LINEMODE_LEVEL, old_data->data, old_data->len);
+				old_data->len = 0;
+			}
+			free(old_data->data);
+		}
 		free(old_data);
 	}
 	return(0);
 }
+
+/*!
+ * \brief Checks if an index is in linebuffered mode
+ *
+ * \param idx the index to check
+ * \return 1 if linebuffered, 0 if not linebuffered, -1 on error
+ */
+
+int linemode_check(int idx)
+{
+	if (!sockbuf_isvalid(idx)) return -1;
+	return !sockbuf_get_filter_data(idx, &linemode_filter, 0);
+}
Index: eggdrop1.9/lib/eggdrop/linemode.h
diff -u eggdrop1.9/lib/eggdrop/linemode.h:1.2 eggdrop1.9/lib/eggdrop/linemode.h:1.3
--- eggdrop1.9/lib/eggdrop/linemode.h:1.2	Wed Dec 17 01:39:14 2003
+++ eggdrop1.9/lib/eggdrop/linemode.h	Sun Aug 20 10:23:05 2006
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Id: linemode.h,v 1.2 2003-12-17 07:39:14 wcc Exp $
+ * $Id: linemode.h,v 1.3 2006-08-20 15:23:05 sven Exp $
  */
 
 #ifndef _EGG_LINEMODE_H_
@@ -24,5 +24,6 @@
 
 int linemode_on(int idx);
 int linemode_off(int idx);
+int linemode_check(int idx);
 
 #endif /* !_EGG_LINEMODE_H_ */
Index: eggdrop1.9/lib/eggdrop/sockbuf.c
diff -u eggdrop1.9/lib/eggdrop/sockbuf.c:1.20 eggdrop1.9/lib/eggdrop/sockbuf.c:1.21
--- eggdrop1.9/lib/eggdrop/sockbuf.c:1.20	Mon Nov 14 21:59:49 2005
+++ eggdrop1.9/lib/eggdrop/sockbuf.c	Sun Aug 20 10:23:05 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: sockbuf.c,v 1.20 2005-11-15 03:59:49 wcc Exp $";
+static const char rcsid[] = "$Id: sockbuf.c,v 1.21 2006-08-20 15:23:05 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -758,7 +758,7 @@
 	sbuf = &sockbufs[idx];
 	for (i = 0; i < sbuf->nfilters; i++) {
 		if (sbuf->filters[i] == filter) {
-			*(void **)client_data_ptr = sbuf->filter_client_data[i];
+			if (client_data_ptr) *(void **)client_data_ptr = sbuf->filter_client_data[i];
 			return(0);
 		}
 	}
@@ -777,8 +777,8 @@
 
 	for (i = 0; i < sbuf->nfilters; i++) if (sbuf->filters[i] == filter) break;
 	if (i == sbuf->nfilters) {
-		if (client_data_ptr) client_data_ptr = NULL;
-		return(0);
+		if (client_data_ptr) *(void **)client_data_ptr = NULL;
+		return(-1);
 	}
 
 	if (client_data_ptr) *(void **)client_data_ptr = sbuf->filter_client_data[i];
Index: eggdrop1.9/modules/script/scriptnet.c
diff -u eggdrop1.9/modules/script/scriptnet.c:1.10 eggdrop1.9/modules/script/scriptnet.c:1.11
--- eggdrop1.9/modules/script/scriptnet.c:1.10	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/modules/script/scriptnet.c	Sun Aug 20 10:23:05 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scriptnet.c,v 1.10 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: scriptnet.c,v 1.11 2006-08-20 15:23:05 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -44,7 +44,7 @@
 static int script_net_open(const char *host, int port, int timeout);
 static int script_net_close(int idx);
 static int script_net_write(int idx, const char *text, int len);
-static int script_net_linemode(int idx, int onoff);
+static int script_net_linemode(int nargs, int idx, int onoff);
 static int script_net_handler(int idx, const char *event, script_callback_t *handler);
 static int script_net_info(script_var_t *retval, int idx, char *what);
 static int script_net_throttle(int idx, int speedin, int speedout);
@@ -140,11 +140,11 @@
 	return sockbuf_write(idx, text, len);
 }
 
-static int script_net_linemode(int idx, int onoff)
+static int script_net_linemode(int nargs, int idx, int onoff)
 {
-	if (onoff) linemode_on(idx);
-	else linemode_off(idx);
-	return(0);
+	if (nargs == 1) return linemode_check(idx);
+	if (onoff) return linemode_on(idx);
+	else return linemode_off(idx);
 }
 
 static int script_net_handler(int idx, const char *event, script_callback_t *callback)
@@ -314,7 +314,7 @@
 	{"", "net_close", script_net_close, NULL, 1, "i", "idx", SCRIPT_INTEGER, 0},	/* DDD */
 	{"", "net_write", script_net_write, NULL, 2, "isi", "idx text ?len?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
 	{"", "net_handler", script_net_handler, NULL, 2, "isc", "idx event callback", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
-	{"", "net_linemode", script_net_linemode, NULL, 2, "ii", "idx on-off", SCRIPT_INTEGER, 0},	/* DDD */
+	{"", "net_linemode", script_net_linemode, NULL, 1, "ii", "idx ?on-off?", SCRIPT_INTEGER, SCRIPT_PASS_COUNT | SCRIPT_VAR_ARGS},	/* DDD */
 	{"", "net_info", script_net_info, NULL, 2, "is", "idx what", 0, SCRIPT_PASS_RETVAL},	/* DDD */
 	{"", "net_throttle", script_net_throttle, NULL, 3, "iii", "idx speed-in speed-out", SCRIPT_INTEGER, 0},	/* DDD */
 	{"", "net_throttle_in", script_net_throttle_set, (void *)0, 2, "ii", "idx speed", SCRIPT_INTEGER, SCRIPT_PASS_CDATA},	/* DDD */
----------------------- End of diff -----------------------



More information about the Changes mailing list