/* PUBLIC HTAA_parseArgList() * PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD * ON ENTRY: * str is a comma-separated list: * * item, item, item * where * item ::= value * | name=value * | name="value" * * Leading and trailing whitespace is ignored * everywhere except inside quotes, so the following * examples are equal: * * name=value,foo=bar * name="value",foo="bar" * name = value , foo = bar * name = "value" , foo = "bar" * * ON EXIT: * returns a list of name-value pairs (actually HTAssocList*). * For items with no name, just value, the name is * the number of order number of that item. E.g. * "1" for the first, etc. */ HTAssocList *HTAA_parseArgList(char *str) { HTAssocList *assoc_list = HTAssocList_new(); char *cur = NULL; char *name = NULL; int n = 0; if (!str) return assoc_list; while (*str) { SKIPWS(str); /* Skip leading whitespace */ cur = str; n++; while (*cur && *cur != '=' && *cur != ',') cur++; /* Find end of name (or lonely value without a name) */ KILLWS(cur); /* Kill trailing whitespace */ if (*cur == '=') { /* Name followed by a value */ *(cur++) = '\0'; /* Terminate name */ StrAllocCopy(name, str); SKIPWS(cur); /* Skip WS leading the value */ str = cur; if (*str == '"') { /* Quoted value */ str++; cur = str; while (*cur && *cur != '"') cur++; if (*cur == '"') *(cur++) = '\0'; /* Terminate value */ /* else it is lacking terminating quote */ SKIPWS(cur); /* Skip WS leading comma */ if (*cur == ',') cur++; /* Skip separating colon */ } else { /* Unquoted value */ while (*cur && *cur != ',') cur++; KILLWS(cur); /* Kill trailing whitespace */ if (*cur == ',') *(cur++) = '\0'; /* else *cur already NULL */ } } else { /* No name, just a value */ if (*cur == ',') *(cur++) = '\0'; /* Terminate value */ /* else last value on line (already terminated by NULL) */ HTSprintf0(&name, "%d", n); /* Item order number for name */ } HTAssocList_add(assoc_list, name, str); str = cur; } /* while *str */ FREE(name); return assoc_list; }
void HTAA_parseProtFile( HTAAProt *prot, FILE *fp ) { if ( prot && fp ) { LexItem lex_item; char *fieldname = 0; do { lex_item = lex( fp ); if ( lex_item != LEX_EOF ) { for ( ; lex_item == LEX_REC_SEP; ) { lex_item = lex( fp ); } if ( lex_item == LEX_EOF ) goto B7; else { if ( lex_item == LEX_ALPH_STR ) { HTSACopy( &fieldname, HTlex_buffer ); lex_item = lex( fp ); if ( lex_item != LEX_FIELD_SEP ) unlex( lex_item ); if ( strncasecomp( fieldname, "Auth", 4 ) == 0 ) { lex_item = lex( fp ); do { if ( lex_item == LEX_ALPH_STR ) { HTAAScheme scheme = HTAAScheme_enum( HTlex_buffer ); if ( scheme ) { if ( prot->valid_schemes == 0 ) { prot->valid_schemes = HTList_new( ); } HTList_addObject( &prot->valid_schemes, &scheme ); if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "%s %s `%s'\n", "HTAA_parseProtFile: valid", "authentication scheme:", HTAAScheme_name( scheme ) ); } } else if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "%s %s `%s'\n", "HTAA_parseProtFile: unknown", "authentication scheme:", HTlex_buffer ); } lex( fp ); while ( lex_item = lex( fp ), lex_item == LEX_ITEM_SEP ) { lex( fp ); } } } while ( lex_item != LEX_REC_SEP ); } else { if ( strncasecomp( fieldname, "mask", 4 ) == 0 ) { prot->mask_group = HTAA_parseGroupDef( fp ); lex_item = LEX_REC_SEP; if ( WWW_TraceFlag ) { if ( prot->mask_group ) { fwrite( "HTAA_parseProtFile: Mask group:\n", 1, 32, TraceFP( ) ); HTAA_printGroupDef( &prot->mask_group ); } else { fwrite( "HTAA_parseProtFile: Mask group syntax error\n", 1, 44, TraceFP( ) ); } } } else { lex_item = lex( fp ); if ( lex_item == LEX_ALPH_STR ) { if ( prot->values == 0 ) { prot->values = HTAssocList_new( ); } HTAssocList_add( &prot->values, fieldname, HTlex_buffer ); lex_item = lex( fp ); if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "%s `%s' bound to value `%s'\n", "HTAA_parseProtFile: Name", fieldname, HTlex_buffer ); } } } } } if ( lex_item != LEX_EOF && lex_item != LEX_REC_SEP ) { if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "%s %s %d (that line ignored)\n", "HTAA_parseProtFile: Syntax error", "in protection setup file at line", HTlex_line ); } do { lex_item = lex( fp ); } while ( lex_item != LEX_EOF && lex_item != LEX_REC_SEP ); } } } B7:; if ( fieldname == 0 ) break; free( fieldname ); break; } while ( lex_item != LEX_REC_SEP ); } return; }