Project

General

Profile

lighttpd-1.4.11-mod_geoip_default_country_code.patch

spillgroup, 2008-01-31 10:07

View differences:

lighttpd-1.4.11-mod_geoip/src/mod_geoip.c 2006-10-04 15:18:19.000000000 +0200
63 63
typedef struct {
64 64
	unsigned short mem_cache;
65 65
	buffer	*db_name;
66
	buffer *default_country_code;
66 67
	GeoIP   *gi;
67 68
} plugin_config;
68 69

  
......
100 101
			if (!s) continue;
101 102
			
102 103
			buffer_free(s->db_name);
104
			buffer_free(s->default_country_code);
103 105
			
104 106
			/* clean up */
105 107
			GeoIP_delete(s->gi);
......
123 125
	config_values_t cv[] = { 
124 126
		{ "geoip.db-filename",	NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },	/* 0 */
125 127
		{ "geoip.memory-cache",	NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },    /* 1 */
128
		{ "geoip.default_country_code", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },    /* 2 */
126 129
		{ NULL,			NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
127 130
	};
128 131
	
......
138 141
		
139 142
		s->db_name = buffer_init();
140 143
		s->mem_cache = 0; /* default: do not load db to cache */
144
		s->default_country_code = buffer_init();
141 145
		s->gi = NULL;
142 146

  
143 147
		cv[0].destination = s->db_name;
144 148
		cv[1].destination = &(s->mem_cache);
149
		cv[2].destination = s->default_country_code;
145 150

  
146 151
		p->config_storage[i] = s;
147 152
	
......
159 164
				mode = GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE;
160 165

  
161 166
			if (NULL == (s->gi = GeoIP_open(s->db_name->ptr, mode))) {
162
				log_error_write(srv, __FILE__, __LINE__, "s",
163
					"failed to open GeoIP database!!!");
167
				log_error_write(srv, __FILE__, __LINE__, "ss",
168
					"failed to open GeoIP database: ", s->db_name->ptr);
164 169

  
165 170
				return HANDLER_ERROR;
166 171
			}
......
216 221

  
217 222
URIHANDLER_FUNC(mod_geoip_subrequest) {
218 223
        plugin_data *p = p_d;
224
		plugin_config *s = p->config_storage[0];
219 225

  
220 226
        mod_geoip_patch_connection(srv, con, p);
221 227

  
......
238 245
					buffer_copy_string(ds->key, "GEOIP_COUNTRY_CODE");
239 246
					buffer_copy_string(ds->value, returnedCountry);
240 247
					array_insert_unique(con->environment, (data_unset *)ds);
248
				} else {
249
					if(s->default_country_code->used > 0) {
250
						if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
251
							ds = data_string_init();
252
						}
253
						
254
						buffer_copy_string(ds->key, "GEOIP_COUNTRY_CODE");
255
						buffer_copy_string(ds->value, s->default_country_code->ptr);
256
						array_insert_unique(con->environment, (data_unset *)ds);	
257
					}
241 258
				}
242 259
			}
243 260

  
......
406 423
	p->name        = buffer_init_string("geoip");
407 424
	
408 425
	p->init        = mod_geoip_init;
409
	p->handle_subrequest_start = mod_geoip_subrequest;
426
//	p->handle_subrequest_start = mod_geoip_subrequest;
427
	p->handle_uri_clean = mod_geoip_subrequest;
410 428
	p->set_defaults  = mod_geoip_set_defaults;
411 429
	p->cleanup     = mod_geoip_free;
412 430