From af86e3d56b8d163abced1223c881cbb848655a0d Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Fri, 19 Nov 2010 04:10:23 +0000
Subject: [PATCH] Now ignores comments following string-style .ini key values
 (as shown in the example sexpots.ini in docs/sexpots.txt) - now truncates
 string values (com dev name, init strings, etc.) at first white-space char.
 Bug reported by Netsurge.

---
 src/sexpots/sexpots.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/sexpots/sexpots.c b/src/sexpots/sexpots.c
index f374111437..ce6fe77217 100644
--- a/src/sexpots/sexpots.c
+++ b/src/sexpots/sexpots.c
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html		*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -59,8 +59,8 @@
 
 /* global vars */
 BOOL	daemonize=FALSE;
-char	termtype[TELNET_TERM_MAXLEN+1]	= NAME;
-char	termspeed[TELNET_TERM_MAXLEN+1]	= "28800,28800";	/* "tx,rx", max length not defined */
+char	termtype[INI_MAX_VALUE_LEN+1]	= NAME;
+char	termspeed[INI_MAX_VALUE_LEN+1]	= "28800,28800";	/* "tx,rx", max length not defined */
 char	revision[16];
 
 char	mdm_init[INI_MAX_VALUE_LEN]		= "AT&F";
@@ -1328,6 +1328,20 @@ BOOL WINAPI ControlHandler(DWORD CtrlType)
 }
 #endif
 
+/****************************************************************************/
+/****************************************************************************/
+char* iniGetExistingWord(str_list_t list, const char* section, const char* key
+					,const char* deflt, char* value)
+{
+	char* p;
+
+	if((p=iniGetExistingString(list, section, key, deflt, value)) !=NULL) {
+		FIND_WHITESPACE(value);
+		*value=0;
+	}
+	return p;
+}
+
 void parse_ini_file(const char* ini_fname)
 {
 	FILE* fp;
@@ -1349,7 +1363,7 @@ void parse_ini_file(const char* ini_fname)
 	
 	/* [COM] Section */
 	section="COM";
-	iniGetExistingString(list, section, "Device", NULL, com_dev);
+	iniGetExistingWord(list, section, "Device", NULL, com_dev);
 	com_baudrate    = iniGetLongInt(list, section, "BaudRate", com_baudrate);
 	com_hangup	    = iniGetBool(list, section, "Hangup", com_hangup);
 	hangup_attempts = iniGetInteger(list, section, "HangupAttempts", hangup_attempts);
@@ -1360,15 +1374,15 @@ void parse_ini_file(const char* ini_fname)
 
 	/* [Modem] Section */
 	section="Modem";
-	iniGetExistingString(list, section, "Init", "", mdm_init);
-	iniGetExistingString(list, section, "AutoAnswer", "", mdm_autoans);
-	iniGetExistingString(list, section, "Cleanup", "", mdm_cleanup);
-	iniGetExistingString(list, section, "EnableCallerID", "", mdm_cid);
+	iniGetExistingWord(list, section, "Init", "", mdm_init);
+	iniGetExistingWord(list, section, "AutoAnswer", "", mdm_autoans);
+	iniGetExistingWord(list, section, "Cleanup", "", mdm_cleanup);
+	iniGetExistingWord(list, section, "EnableCallerID", "", mdm_cid);
 	mdm_timeout     = iniGetInteger(list, section, "Timeout", mdm_timeout);
 
 	/* [TCP] Section */
 	section="TCP";
-	iniGetExistingString(list, section, "Host", NULL, host);
+	iniGetExistingWord(list, section, "Host", NULL, host);
 	port					= iniGetShortInt(list, section, "Port", port);
 	tcp_nodelay				= iniGetBool(list,section,"NODELAY", tcp_nodelay);
 
@@ -1377,15 +1391,15 @@ void parse_ini_file(const char* ini_fname)
 	telnet					= iniGetBool(list,section,"Enabled", telnet);
 	debug_telnet			= iniGetBool(list,section,"Debug", debug_telnet);
 	telnet_advertise_cid	= iniGetBool(list,section,"AdvertiseLocation", telnet_advertise_cid);
-	iniGetExistingString(list, section, "TermType", NULL, termtype);
-	iniGetExistingString(list, section, "TermSpeed", NULL, termspeed);
+	iniGetExistingWord(list, section, "TermType", NULL, termtype);
+	iniGetExistingWord(list, section, "TermSpeed", NULL, termspeed);
 
 	/* [Ident] Section */
 	section="Ident";
 	ident					= iniGetBool(list,section,"Enabled", ident);
 	ident_port				= iniGetShortInt(list, section, "Port", ident_port);
 	ident_interface			= iniGetIpAddress(list, section, "Interface", ident_interface);
-	iniGetExistingString(list, section, "Response", NULL, ident_response);
+	iniGetExistingWord(list, section, "Response", NULL, ident_response);
 
 }
 
-- 
GitLab