Check-in [c5478a987a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fix parse mime type
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c5478a987a97c88abd383c34964985682b8c64fe
User & Date: dsx 2014-09-13 09:23:50
Context
2014-09-13
09:24
fix lookup mime type check-in: fc316cfcdd user: dsx tags: trunk
09:23
fix parse mime type check-in: c5478a987a user: dsx tags: trunk
2014-09-06
19:28
Fix commit message 503988d1a085d2f00f41d1ff773aca4a9f239eb2 Simplify do_status (cast vs macro) Read mime type from file check-in: f5aa353fa0 user: dsx tags: trunk
Changes

Changes to parse.y.

140
141
142
143
144
145
146

147
148
149
150
151
152
153
...
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
...
758
759
760
761
762
763
764
765
766
767
768
769


770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
















793
794
795
796
797
798
799
...
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
struct vhost * location_lookup(const char *);

void parse_network(const char *);
static inline int fill_network_inet(struct mohawk_network *, struct addrinfo *, unsigned long *, int);
static inline int fill_network_inet6(struct mohawk_network *, struct addrinfo *, unsigned long *, int);

void parse_mime_type(const char *);


extern int yylineno;

static struct vhost *current_vh = NULL, *save_current_vh = NULL, *location_last = NULL;
static struct mohawk_hash *hash_mohawk = NULL, *hash_last = NULL;
static struct mohawk_list *list_mohawk = NULL, *list_last = NULL;
static struct mohawk_network *network_last = NULL;
................................................................................
*     text/html                             html htm shtml;
* apache:
* application/octet-stream        bin dms lha lzh exe class so dll
*/
void
parse_mime_type(const char *filename)
{
	struct mohawk_hash *hash_mohawk;
	char buf[PATH_MAX], *start, *end, *mime;
	FILE *fp;
	int lines = 1;

	if ((fp = fopen(filename, "r")) == NULL)
		errx(EXIT_FAILURE, "Can't fopen '%s'", filename);

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		if (!buf[0] || buf[0] == '#')
			continue;

		start = buf;
		while (isspace(*start)) { start++; }
		if (!isalpha(*start)) { continue; }

		end = start;
................................................................................
		if (!isspace(*end)) { continue; }
		*end = '\0';
		mime = start;

		end++;
		if (*end == '\0') { continue; }

		do {
			start = end;
			while (isspace(*start)) { start++; }
			if (!isalpha(*start)) { goto next_line; }



			end = start;
			while (isalpha(*end)) { end++; }
			if (*end) { *end = '\0'; end++; }

			if ((hash_mohawk = malloc(sizeof(struct mohawk_hash))) == NULL)
				errx(1, "Unable to allocate memory");
			if ((hash_mohawk->key = strdup(start)) == NULL)
				errx(1, "Unable to allocate memory");
			if ((hash_mohawk->value = strdup(mime)) == NULL)
				errx(1, "Unable to allocate memory");
			if (SLIST_EMPTY(&conf.mime_type))
				SLIST_INSERT_HEAD(&conf.mime_type, hash_mohawk, entry);
			else
				SLIST_INSERT_AFTER(hash_last, hash_mohawk, entry);
			hash_last = hash_mohawk;
		} while (*end);

next_line:
		lines++;
	}

	fclose(fp);
}
















%}

%{
int yylex(void);
%}

/* syntax */
................................................................................
};

debug: MOHAWK_DEBUG STATE {
	if (conf.debug < 0)
		conf.debug = $2;
};

mime_type: MIME_TYPE WORD { parse_mime_type($2); };
         | MIME_TYPE mime_type_content { };

mime_type_content: OBRACE mime_type_items EBRACE { };

mime_type_items: | mime_type_items mime_type_item ;

mime_type_item: WORD WORD {
	if ((hash_mohawk = malloc(sizeof(struct mohawk_hash))) == NULL)
		errx(1, "Unable to allocate memory");
	hash_mohawk->key = $1;
	hash_mohawk->value = $2;
	if (SLIST_EMPTY(&conf.mime_type))
		SLIST_INSERT_HEAD(&conf.mime_type, hash_mohawk, entry);
	else
		SLIST_INSERT_AFTER(hash_last, hash_mohawk, entry);
	hash_last = hash_mohawk;
};

pidfile: PIDFILE WORD {
	if (conf.pidfile == NULL)
		conf.pidfile = $2;
};

syslog_facility: SYSLOG_FACILITY WORD {







>







 







<








|







 







<
|
|
|
<
>
>
|
|
|

|
<
<
<
<
<
<
<
<
<
<
<







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







|
|
|
|
|
|
<
<
<
<







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
734
735
736
737
738
739
740

741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
...
758
759
760
761
762
763
764

765
766
767

768
769
770
771
772
773
774











775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
...
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874




875
876
877
878
879
880
881
struct vhost * location_lookup(const char *);

void parse_network(const char *);
static inline int fill_network_inet(struct mohawk_network *, struct addrinfo *, unsigned long *, int);
static inline int fill_network_inet6(struct mohawk_network *, struct addrinfo *, unsigned long *, int);

void parse_mime_type(const char *);
static inline void add_mime_type(char *, char *);

extern int yylineno;

static struct vhost *current_vh = NULL, *save_current_vh = NULL, *location_last = NULL;
static struct mohawk_hash *hash_mohawk = NULL, *hash_last = NULL;
static struct mohawk_list *list_mohawk = NULL, *list_last = NULL;
static struct mohawk_network *network_last = NULL;
................................................................................
*     text/html                             html htm shtml;
* apache:
* application/octet-stream        bin dms lha lzh exe class so dll
*/
void
parse_mime_type(const char *filename)
{

	char buf[PATH_MAX], *start, *end, *mime;
	FILE *fp;
	int lines = 1;

	if ((fp = fopen(filename, "r")) == NULL)
		errx(EXIT_FAILURE, "Can't fopen '%s'", filename);

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		if (!buf[0] || buf[0] == '\n' || buf[0] == '#')
			continue;

		start = buf;
		while (isspace(*start)) { start++; }
		if (!isalpha(*start)) { continue; }

		end = start;
................................................................................
		if (!isspace(*end)) { continue; }
		*end = '\0';
		mime = start;

		end++;
		if (*end == '\0') { continue; }


		start = end;
		while (isspace(*start)) { start++; }
		if (!isalpha(*start)) { goto next_line; }

		if ((end = strchr(start, '\n')) == NULL)
			errx(1, "File '%s' line %d: line too long", filename, lines);
		*end = '\0';
		if ((end = strchr(start, ';')) != NULL)
			*end = '\0';

		add_mime_type(strdup(mime), strdup(start));












next_line:
		lines++;
	}

	fclose(fp);
}

static inline void
add_mime_type(char *key, char *value)
{
	if (key == NULL || value == NULL)
		errx(1, "Unable to allocate memory");
	if ((hash_mohawk = malloc(sizeof(struct mohawk_hash))) == NULL)
		errx(1, "Unable to allocate memory");
	hash_mohawk->key = key;
	hash_mohawk->value = value;
	if (SLIST_EMPTY(&conf.mime_type))
		SLIST_INSERT_HEAD(&conf.mime_type, hash_mohawk, entry);
	else
		SLIST_INSERT_AFTER(hash_last, hash_mohawk, entry);
	hash_last = hash_mohawk;
}
%}

%{
int yylex(void);
%}

/* syntax */
................................................................................
};

debug: MOHAWK_DEBUG STATE {
	if (conf.debug < 0)
		conf.debug = $2;
};

mime_type: MIME_TYPE WORD { parse_mime_type($2); }
         | MIME_TYPE mime_type_content { };

mime_type_content: OBRACE mime_type_items EBRACE { };

mime_type_items: | mime_type_items mime_type_item ;

mime_type_item: WORD WORD {
	if (strchr($1, '/'))
		add_mime_type($1, $2);
	else
		add_mime_type($2, $1);
}
              | WORD WORDS { add_mime_type($1, $2); };





pidfile: PIDFILE WORD {
	if (conf.pidfile == NULL)
		conf.pidfile = $2;
};

syslog_facility: SYSLOG_FACILITY WORD {