Andrew Dunstan <[EMAIL PROTECTED]> writes:
> OK, then *This* patch does it the way I think is clearest. Most of it
> is just reindenting.

Okay, I applied this patch, and made a few additional cleanups along
the way (the whole function and a couple other things don't need to be
declared in hba.h, for example). The incremental diff between what I
applied and what Andrew posted is attached.

BTW, I think the proper fix is to rewrite next_token(), which is
rather obfuscated at present. Anyone want to take a shot at this?

-Neil

diff -u src/backend/libpq/hba.c src/backend/libpq/hba.c
--- src/backend/libpq/hba.c	1 Feb 2004 17:17:34 -0000
+++ src/backend/libpq/hba.c	2 Feb 2004 16:48:43 -0000
@@ -37,12 +37,23 @@
 #include "storage/fd.h"
 
 
-#define IDENT_USERNAME_MAX 512
 /* Max size of username ident server can return */
+#define IDENT_USERNAME_MAX 512
+
+/* Standard TCP port number for Ident service.  Assigned by IANA */
+#define IDENT_PORT 113
+
+/* Name of the config file  */
+#define CONF_FILE "pg_hba.conf"
+
+/* Name of the usermap file */
+#define USERMAP_FILE "pg_ident.conf"
 
 /* This is used to separate values in multi-valued column strings */
 #define MULTI_VALUE_SEP "\001"
 
+#define MAX_TOKEN	256
+
 /*
  * These variables hold the pre-parsed contents of the hba and ident
  * configuration files.  Each is a list of sublists, one sublist for
@@ -80,19 +91,19 @@
 
 
 /*
- *	 Grab one token out of fp. Tokens are strings of non-blank
- *	 characters bounded by blank characters, beginning of line, and
- *	 end of line. Blank means space or tab. Return the token as
- *	 *buf. Leave file positioned to character immediately after the
- *	 token or EOF, whichever comes first. If no more tokens on line,
- *	 return null string as *buf and position file to beginning of
- *	 next line or EOF, whichever comes first. Allow spaces in quoted
- *	 strings. Terminate on unquoted commas. Handle comments. Treat
- *   unquoted keywords that might be user names or database names 
- *   specially, by appending a newline to them.
+ * Grab one token out of fp. Tokens are strings of non-blank
+ * characters bounded by blank characters, beginning of line, and
+ * end of line. Blank means space or tab. Return the token as
+ * *buf. Leave file positioned at the character immediately after the
+ * token or EOF, whichever comes first. If no more tokens on line,
+ * return empty string as *buf and position the file to the beginning
+ * of the next line or EOF, whichever comes first. Allow spaces in
+ * quoted strings. Terminate on unquoted commas. Handle
+ * comments. Treat unquoted keywords that might be user names or
+ * database names specially, by appending a newline to them.
  */
-void
-next_token(FILE *fp, char *buf, const int bufsz)
+static void
+next_token(FILE *fp, char *buf, int bufsz)
 {
 	int			c;
 	char	   *start_buf = buf;
@@ -101,6 +112,8 @@
 	bool		was_quote = false;
 	bool        saw_quote = false;
 
+	Assert(end_buf > start_buf);
+
 	/* Move over initial whitespace and commas */
 	while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
 		;
@@ -173,20 +186,15 @@
 
 	*buf = '\0';
 
-	if ( !saw_quote && 
-	     (
-			 strcmp(start_buf,"all") == 0  ||
-			 strcmp(start_buf,"sameuser") == 0  ||
-			 strcmp(start_buf,"samegroup") == 0 
-		 )
-		)
+	if (!saw_quote && 
+	     (strcmp(start_buf, "all") == 0 ||
+		  strcmp(start_buf, "sameuser") == 0 ||
+		  strcmp(start_buf, "samegroup") == 0))
 	{
 		/* append newline to a magical keyword */
 		*buf++ = '\n';
 		*buf = '\0';
 	}
-
-
 }
 
 /*
only in patch2:
unchanged:
--- src/include/libpq/hba.h	29 Nov 2003 22:41:03 -0000	1.34
+++ src/include/libpq/hba.h	2 Feb 2004 16:27:01 -0000
@@ -17,15 +17,6 @@
 
 #include "nodes/pg_list.h"
 
-#define CONF_FILE "pg_hba.conf"
- /* Name of the config file  */
-
-#define USERMAP_FILE "pg_ident.conf"
- /* Name of the usermap file */
-
-#define IDENT_PORT 113
- /* Standard TCP port number for Ident service.  Assigned by IANA */
-
 typedef enum UserAuth
 {
 	uaReject,
@@ -43,9 +34,6 @@
 
 typedef struct Port hbaPort;
 
-#define MAX_TOKEN	256
-
-extern void next_token(FILE *fp, char *buf, const int bufsz);
 extern List **get_user_line(const char *user);
 extern void load_hba(void);
 extern void load_ident(void);
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to