Re: Syslog Facility Patch - Mailing list pgsql-hackers
| From | Larry Rosenman |
|---|---|
| Subject | Re: Syslog Facility Patch |
| Date | |
| Msg-id | 20001115133808.A21998@lerami.lerctr.org Whole thread Raw |
| In response to | Re: Syslog Facility Patch (Peter Eisentraut <peter_e@gmx.net>) |
| Responses |
Re: Syslog Facility Patch
|
| List | pgsql-hackers |
* Peter Eisentraut <peter_e@gmx.net> [001115 13:11]:
> Larry Rosenman writes:
>
> > > syntax is lexically compatible with the syntax of the SET command.
> > > Therefore you can't have "funny" characters in 'value' unless
> > > single-quoted.
> > I added period(.), hyphen(-), and underscore(_).
>
> Probably '/' and ':' as well, for krb_server_keyfile.
Added.
>
> > ! UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._])*
> > ! STRING (\'|\")([^'"\n]|\\.)*(\'|\")
>
> That will accept strings that start with one kind of quote and end with
> another. Please stick to single-quotes only, unless you want to make a
> case for the double-quotes.
Done.
>
> I'm also not quite sure about
>
> > + if (s[i] == '\'')
> > + {
> > +
> > + /*
> > + * Note: if scanner is working right, unescaped quotes can
> > + * only appear in pairs, so there should be another character.
> > + */
> > + i++;
> > + newStr[j] = s[i];
> > + }
>
> The SQL scanner accepts 'foo''bar' as the SQL-approved method of escaping
> quotes in quotes. GUC doesn't do that (way too complicated for now), so
> this probably needs to be adjusted.
Removed.
>
> Other than that, looks good.
I also added the token that caused the parse error to be printed out.
I also added some whitespace on a couple of places that the lines
were getting, err, long.
New Version:
Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.4
diff -c -r1.4 guc-file.l
*** src/backend/utils/misc/guc-file.l 2000/07/27 19:49:18 1.4
--- src/backend/utils/misc/guc-file.l 2000/11/15 19:34:54
***************
*** 16,21 ****
--- 16,22 ---- #include <sys/stat.h> #include <unistd.h> #include <errno.h>
+ #include <ctype.h> #include "miscadmin.h" #include "storage/fd.h"
***************
*** 32,37 ****
--- 33,39 ---- GUC_INTEGER = 3, GUC_REAL = 4, GUC_EQUALS = 5,
+ GUC_UNQUOTED_STRING = 6, GUC_EOL = 99, GUC_ERROR = 100 };
***************
*** 45,51 **** /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
! %} SIGN ("-"|"+")
--- 47,53 ---- /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
! char *GUC_scanstr(char *); %} SIGN ("-"|"+")
***************
*** 61,77 **** LETTER_OR_DIGIT [A-Za-z_0-9\200-\377] ID {LETTER}{LETTER_OR_DIGIT}*
- /*
- * FIXME: This string syntax is nice and all but of course the quotes
- * need to be stripped before we can make any use of the string value.
- * There is a function in parser/scansup.c that does this but it uses
- * palloc and there might be a little more magic needed to get it to
- * work right. Now there are no string options, and if there were then
- * the unquoted (`ID') tokens should still work. Of course this only
- * affects the configuration file.
- */
- STRING \'([^'\n]|\\.)*' %% \n ConfigFileLineno++; return GUC_EOL;
--- 63,72 ---- LETTER_OR_DIGIT [A-Za-z_0-9\200-\377] ID {LETTER}{LETTER_OR_DIGIT}*
+ UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/×])*
+ STRING \'([^'"\n]|\\.)*\'
+ %% \n ConfigFileLineno++; return GUC_EOL;
***************
*** 80,85 ****
--- 75,81 ---- {ID} return GUC_ID; {STRING} return GUC_STRING;
+ {UNQUOTED_STRING} return GUC_UNQUOTED_STRING; {INTEGER} return GUC_INTEGER; {REAL} return GUC_REAL; =
return GUC_EQUALS;
***************
*** 139,145 **** int elevel; FILE * fp;
! Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP); Assert(DataDir);
elevel= (context == PGC_SIGHUP) ? DEBUG : ERROR;
--- 135,142 ---- int elevel; FILE * fp;
! Assert(context == PGC_POSTMASTER || context == PGC_BACKEND
! || context == PGC_SIGHUP); Assert(DataDir); elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR;
***************
*** 210,220 **** if (token == GUC_EQUALS) token = yylex();
! if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL)
goto parse_error; opt_value = strdup(yytext); if (opt_value == NULL)
goto out_of_memory; parse_state = 2; break;
--- 207,230 ---- if (token == GUC_EQUALS) token = yylex();
! if (token != GUC_ID && token != GUC_STRING &&
! token != GUC_INTEGER && token != GUC_REAL &&
! token != GUC_UNQUOTED_STRING) goto parse_error; opt_value =
strdup(yytext); if (opt_value == NULL) goto out_of_memory;
+ if (token == GUC_STRING)
+ {
+ /* remove the beginning and ending quote/apostrophe */
+ /* first: shift the whole shooting match down one
+ character */
+ memmove(opt_value,opt_value+1,strlen(opt_value)-1);
+ /* second: null out the 2 characters we shifted */
+ opt_value[strlen(opt_value)-2]='\0';
+ /* do the escape thing. free()'s the strdup above */
+ opt_value=GUC_scanstr(opt_value);
+ } parse_state = 2; break;
***************
*** 266,272 **** FreeFile(fp); free(filename); free_name_value_list(head);
! elog(elevel, CONFIG_FILENAME ":%u: syntax error", ConfigFileLineno); return; out_of_memory:
--- 276,283 ---- FreeFile(fp); free(filename); free_name_value_list(head);
! elog(elevel, CONFIG_FILENAME ":%u: syntax error, token=\"%s\"",
! ConfigFileLineno,yytext); return; out_of_memory:
***************
*** 283,286 ****
--- 294,382 ---- yywrap(void) { return 1;
+ }
+
+ /* ----------------
+ * scanstr
+ *
+ * if the string passed in has escaped codes, map the escape codes to actual
+ * chars
+ *
+ * the string returned is malloc'd and should eventually be free'd by the
+ * caller!
+ * ----------------
+ */
+
+ char *
+ GUC_scanstr(char *s)
+ {
+ char *newStr;
+ int len,
+ i,
+ j;
+
+ if (s == NULL || s[0] == '\0')
+ {
+ if (s != NULL) free (s);
+ return strdup("");
+
+ }
+ len = strlen(s);
+
+ newStr = malloc(len + 1); /* string cannot get longer */
+
+ for (i = 0, j = 0; i < len; i++)
+ {
+ if (s[i] == '\\')
+ {
+ i++;
+ switch (s[i])
+ {
+ case 'b':
+ newStr[j] = '\b';
+ break;
+ case 'f':
+ newStr[j] = '\f';
+ break;
+ case 'n':
+ newStr[j] = '\n';
+ break;
+ case 'r':
+ newStr[j] = '\r';
+ break;
+ case 't':
+ newStr[j] = '\t';
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ {
+ int k;
+ long octVal = 0;
+
+ for (k = 0;
+ s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
+ k++)
+ octVal = (octVal << 3) + (s[i + k] - '0');
+ i += k - 1;
+ newStr[j] = ((char) octVal);
+ }
+ break;
+ default:
+ newStr[j] = s[i];
+ break;
+ }
+ } /* switch */
+ else
+ newStr[j] = s[i];
+ j++;
+ }
+ newStr[j] = '\0';
+ free(s);
+ return newStr; }
--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
pgsql-hackers by date: