6
6
* found in the LICENSE file at https://github.com/bleenco/bproxy
7
7
*/
8
8
#include "config.h"
9
+ #include "log.h"
9
10
10
11
char * read_file (char * path )
11
12
{
@@ -16,7 +17,7 @@ char *read_file(char *path)
16
17
17
18
if (!f )
18
19
{
19
- fprintf ( stderr , "could not open file %s for reading!\n " , path );
20
+ log_error ( "could not open file %s for reading!" , path );
20
21
exit (1 );
21
22
}
22
23
@@ -47,14 +48,14 @@ void parse_config(const char *json_string, config_t *config)
47
48
int r = jsmn_parse (& p , json_string , strlen (json_string ), t , sizeof (t ) / sizeof (t [0 ]));
48
49
if (r < 0 )
49
50
{
50
- fprintf ( stderr , "failed to parse config JSON: %d\n " , r );
51
+ log_error ( "failed to parse config JSON: %d" , r );
51
52
exit (1 );
52
53
}
53
54
54
55
// assume top-level element is an object
55
56
if (r < 1 || t [0 ].type != JSMN_OBJECT )
56
57
{
57
- fprintf ( stderr , "wrong configuration!\n " );
58
+ log_error ( "wrong JSON configuration!" );
58
59
exit (1 );
59
60
}
60
61
@@ -70,11 +71,30 @@ void parse_config(const char *json_string, config_t *config)
70
71
free (port );
71
72
i ++ ;
72
73
}
74
+ else if (jsoneq (json_string , & t [i ], "gzip_mime_types" ) == 0 )
75
+ {
76
+ if (t [i + 1 ].type != JSMN_ARRAY )
77
+ {
78
+ log_error ("wrong configuration, gzip_mime_types should be an array!" );
79
+ exit (1 );
80
+ }
81
+
82
+ config -> num_gzip_mime_types = 0 ;
83
+ for (int j = 0 ; j < t [i + 1 ].size ; j ++ )
84
+ {
85
+ jsmntok_t * mime_type = & t [i + j + 2 ];
86
+ char * mime = malloc (50 );
87
+ sprintf (mime , "%.*s" , mime_type -> end - mime_type -> start , json_string + mime_type -> start );
88
+ config -> gzip_mime_types [config -> num_gzip_mime_types ] = malloc (sizeof (char ) * 50 );
89
+ memcpy (config -> gzip_mime_types [config -> num_gzip_mime_types ], mime , strlen (mime ));
90
+ config -> num_gzip_mime_types ++ ;
91
+ }
92
+ }
73
93
else if (jsoneq (json_string , & t [i ], "proxies" ) == 0 )
74
94
{
75
95
if (t [i + 1 ].type != JSMN_ARRAY )
76
96
{
77
- fprintf ( stderr , "wrong configuration, proxies should be array!\n " );
97
+ log_error ( "wrong configuration, proxies should be an array!" );
78
98
exit (1 );
79
99
}
80
100
@@ -88,7 +108,7 @@ void parse_config(const char *json_string, config_t *config)
88
108
int rr = jsmn_parse (& pp , proxy_str , strlen (proxy_str ), token , sizeof (token ) / sizeof (token [0 ]));
89
109
if (rr < 0 )
90
110
{
91
- fprintf ( stderr , "failed to parse JSON (proxies): %d\n " , rr );
111
+ log_error ( "failed to parse JSON (proxies): %d" , rr );
92
112
exit (1 );
93
113
}
94
114
@@ -143,9 +163,5 @@ void parse_config(const char *json_string, config_t *config)
143
163
free (proxy_str );
144
164
return ;
145
165
}
146
- else if (jsoneq (json_string , & t [i ], "gzip-types" ) == 0 )
147
- {
148
- printf ("yeey" );
149
- }
150
166
}
151
167
}
0 commit comments