Diederik has submitted this change and it was merged.
Change subject: Minor cleanup in various files
......................................................................
Minor cleanup in various files
Changed 1 to true in a couple of places that I missed earlier.
-- Add SimpleMake makefile to build without needing autoconf, automake and
friends.
-- countries.{h,c}: fix mismatch in array declaration and add const;
remove superfluous array size; include header in C file so that
mismatches can be caught by compiler.
-- udp-filter.h: remove explicit assignment of values since enums, by default
start at 0 and increment by 1; add last member to track number of values.
-- udp-filter.c: use MAX_FILTER instead of manifest constant; remove
superfluous variable num_predefined_filters; use bool type where appropriate;
remove unused variable found_multiple_ips.
-- utils.c: include header in C file
Change-Id: Id47ec9a4e4855d43e632ea0d71ef83323a30413f
---
A SimpleMake
M src/countries.c
M src/countries.h
M src/udp-filter.c
M src/udp-filter.h
M src/utils.c
6 files changed, 79 insertions(+), 39 deletions(-)
Approvals:
Diederik: Verified; Looks good to me, approved
diff --git a/SimpleMake b/SimpleMake
new file mode 100644
index 0000000..0239501
--- /dev/null
+++ b/SimpleMake
@@ -0,0 +1,40 @@
+CC = gcc
+CFLAGS = -std=gnu99 -O2 -Wall -Wextra
+LDFLAGS = -lGeoIP -lcidr -lanon
+
+TARGETS = udp-filter
+
+HDRS = src/udp-filter.h \
+ src/countries.h \
+ src/collector-output.h \
+ src/geo.h \
+ src/anonymize.h \
+ src/match.h \
+ src/utils.h
+
+SRCS = src/udp-filter.c \
+ src/countries.c \
+ src/collector-output.c \
+ src/geo.c \
+ src/anonymize.c \
+ src/match.c \
+ src/utils.c
+
+OBJS = $(SRCS:%.c=%.o)
+
+$(TARGETS): $(OBJS)
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+clean:
+ rm -f udp-filter $(OBJS)
+
+.PHONY: clean
+
+# dependencies
+src/udp-filter.o: src/udp-filter.c $(HDRS)
+src/countries.o: src/countries.c src/countries.h
+src/collector-output.o: src/collector-output.c src/collector-output.h
+src/geo.o: src/geo.c src/geo.h src/udp-filter.h src/utils.h
+src/anonymize.o: src/anonymize.c src/anonymize.h src/udp-filter.h
+src/match.o: src/match.c src/match.h src/udp-filter.h src/utils.h
+src/utils.o: src/utils.c src/utils.h
diff --git a/src/countries.c b/src/countries.c
index f9e7440..9e40fd1 100644
--- a/src/countries.c
+++ b/src/countries.c
@@ -19,9 +19,11 @@
#include <string.h>
#include <stdio.h>
+#include "countries.h"
+
// This is an array with valid country codes, the country codes that are
// supplied on the command line will be checked against this array.
-const char *country_code_array[253] = {
+const char *const country_code_array[] = {
"A1", //,Anonymous Proxy
"A2", //,Satellite Provider
"O1", //,Other Country
diff --git a/src/countries.h b/src/countries.h
index 320963c..36c3573 100644
--- a/src/countries.h
+++ b/src/countries.h
@@ -19,5 +19,4 @@
int verify_country_code(char *country_code);
-
-extern const char country_code_array[253];
+extern const char *const country_code_array[];
diff --git a/src/udp-filter.c b/src/udp-filter.c
index a7e7677..8c44f9d 100644
--- a/src/udp-filter.c
+++ b/src/udp-filter.c
@@ -68,8 +68,7 @@
-int params[7]; // Increase this when you add a new filter to ScreenType enum.
-const int num_predefined_filters = sizeof(params)/sizeof(int);
+bool params[ MAX_FILTER ];
int verbose_flag = 0; // this flag indicates whether we
should output detailed debug messages, default is off.
@@ -653,32 +652,32 @@
// DETERMINE NUMBER OF FILTERS
- for(n=0; n<num_predefined_filters; n++){
+ for(n=0; n<MAX_FILTER; n++){
switch (n) {
case DOMAIN_FILTER:
- if(params[n] == 1){
+ if(params[n] == true){
num_domain_filters =
determine_num_obs(domain_input,comma_delimiter);
required_hits+=1;
}
break;
case PATH_FILTER:
- if(params[n] ==1 ){
+ if(params[n] == true ){
num_path_filters =
determine_num_obs(path_input,comma_delimiter);
required_hits+=1;
}
break;
case IP_FILTER:
- if(params[n] == 1){
+ if(params[n] == true){
num_ipaddress_filters =
determine_num_obs(ipaddress_input, comma_delimiter);
required_hits+=1;
}
break;
case GEO_FILTER:
- if(params[n] == 1){
+ if(params[n] == true){
if(country_input != NULL &&
strlen(country_input) >1){
num_countries_filters =
determine_num_obs(country_input, comma_delimiter);
required_hits+=1;
@@ -687,14 +686,14 @@
break;
case REFERER_FILTER:
- if(params[n] == 1){
+ if(params[n] == true){
num_referer_filters =
determine_num_obs(referer_input, comma_delimiter);
required_hits+=1;
}
break;
case HTTP_STATUS_FILTER:
- if(params[n] ==1){
+ if(params[n] == true){
if(http_status_input != NULL &&
strlen(http_status_input) >1){
num_http_status_filters =
determine_num_obs(http_status_input, comma_delimiter);
required_hits+=1;
@@ -708,12 +707,12 @@
Filter filters[num_filters];
// GEO_FILTER INITIALIZATION
- GeoIP *gi;
+ GeoIP *gi = NULL;
char *countries[num_countries_filters];
char *area;
// FILTER INITIALIZATION
- for(n=0; n<num_predefined_filters; n++){
+ for(n=0; n<MAX_FILTER; n++){
switch (n) {
case DOMAIN_FILTER:
@@ -917,7 +916,6 @@
strncmp(x_forwarded_for,"-" ,1) != 0
) {
char *ix = x_forwarded_for;
- bool found_multiple_ips = false;
bool found_illegal_char = false;
// length of the first ip in x-forwarded-for header
@@ -925,7 +923,6 @@
for(;*ix != '\0';ix++) {
// we just take what we need which is everything up
until the comma
if(*ix == ',' || *ix == '%') {
- found_multiple_ips = true;
len = ix - x_forwarded_for;
int sz_copy = min(len,40);
strncpy(x_forwarded_client,x_forwarded_for, sz_copy);
@@ -1009,27 +1006,27 @@
if (url != NULL) {
- if (params[DOMAIN_FILTER] == 1){
+ if (params[DOMAIN_FILTER] == true){
found += match_domain(url, filters,
num_domain_filters,verbose_flag);
}
- if (params[PATH_FILTER] == 1){
+ if (params[PATH_FILTER] == true){
found += match_path(url, filters,
num_path_filters,verbose_flag);
}
- if (params[HTTP_STATUS_FILTER] == 1){
+ if (params[HTTP_STATUS_FILTER] == true){
found += match_http_status(http_status,
filters, num_http_status_filters,verbose_flag);
}
- if (params[IP_FILTER] == 1){
+ if (params[IP_FILTER] == true){
found += match_ip_address(ipaddr, filters,
num_ipaddress_filters,verbose_flag);
}
- if (params[REFERER_FILTER] == 1){
+ if (params[REFERER_FILTER] == true){
found += match_domain(referer, filters,
num_referer_filters,verbose_flag);
}
- if (params[GEO_FILTER] == 1){
+ if (params[GEO_FILTER] == true){
if(using_xforwarded_for_geoip) {
area = geo_lookup(gi,
x_forwarded_client, bird_int);
} else {
@@ -1235,7 +1232,7 @@
{
case 'a':
/* Indicate whether we should anonymize the log,
default is false */
- recode = (recode | ANONYMIZE);
+ recode |= ANONYMIZE;
// if optarg is NULL, then we will not be using
// libanon. No need to initialize the anon ip objects
@@ -1272,14 +1269,14 @@
case 'c':
/* Optional list of countries to restrict logging */
country_input = optarg;
- params[GEO_FILTER] = 1;
+ params[GEO_FILTER] = true;
break;
case 'd':
/* -d is set. This specifies the project: en.wikipedia,
commons.
* it should be a part of the domain name
*/
- params[DOMAIN_FILTER] = 1;
+ params[DOMAIN_FILTER] = true;
domain_input = optarg;
search=STRING;
break;
@@ -1287,7 +1284,7 @@
case 'f':
/* -f is set. This specificies to filter on the
referrer string.
*/
- params[REFERER_FILTER] = 1;
+ params[REFERER_FILTER] = true;
referer_input = optarg;
search=STRING;
break;
@@ -1306,7 +1303,7 @@
case 'g':
/* Indicate whether we should do geocode, default is
false */
recode = (recode | GEO);
- //params[GEO_FILTER] = 1;
+ //params[GEO_FILTER] = true;
break;
case 'h':
@@ -1318,7 +1315,7 @@
case 'i':
/* Enable filtering by ip-address or ip-range */
- params[IP_FILTER] =1;
+ params[IP_FILTER] = true;
ipaddress_input = optarg;
break;
@@ -1333,7 +1330,7 @@
case 's':
/* Enable filtering by HTTP response status code */
- params[HTTP_STATUS_FILTER] = 1;
+ params[HTTP_STATUS_FILTER] = true;
http_status_input = optarg;
break;
@@ -1346,7 +1343,7 @@
case 'p':
/* -p is set. Store the url that needs to be matched. */
- params[PATH_FILTER]= 1;
+ params[PATH_FILTER] = true;
path_input = optarg;
search=STRING;
break;
@@ -1384,7 +1381,7 @@
exit(EXIT_FAILURE);
}
- if (geo_param_supplied==-1 && params[GEO_FILTER] ==1){
+ if (geo_param_supplied==-1 && params[GEO_FILTER] == true){
fprintf(stderr,"You supplied the -g parameter without
specifying the -b parameter.\n");
exit(EXIT_FAILURE);
}
diff --git a/src/udp-filter.h b/src/udp-filter.h
index d5c9def..879cec7 100644
--- a/src/udp-filter.h
+++ b/src/udp-filter.h
@@ -26,14 +26,15 @@
#include <libanon.h>
-typedef enum ScreenType{
- NO_FILTER = 0, // no filtering, write all hits to
a file
- DOMAIN_FILTER = 1, // filter on domain
- PATH_FILTER = 2, // filter on path
- IP_FILTER = 3, // filter on ip address or ip range
- GEO_FILTER = 4, // filter on geographic area
- HTTP_STATUS_FILTER = 5, // filter on http response status
codes
- REFERER_FILTER = 6, // filter on referer url
+typedef enum ScreenType{ // by default, enums start at 0, increment by 1
+ NO_FILTER, // no filtering, write all hits to a file
+ DOMAIN_FILTER, // filter on domain
+ PATH_FILTER, // filter on path
+ IP_FILTER, // filter on ip address or ip range
+ GEO_FILTER, // filter on geographic area
+ HTTP_STATUS_FILTER, // filter on http response status codes
+ REFERER_FILTER, // filter on referer url
+ MAX_FILTER // number of filters (not a valid value)
} ScreenType;
typedef enum IpMatchType {
diff --git a/src/utils.c b/src/utils.c
index 8c39ef6..33e69e3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include "utils.h"
/*
Copyright (C) 2012 <Diederik van Liere / Wikimedia Foundation>
--
To view, visit https://gerrit.wikimedia.org/r/60091
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id47ec9a4e4855d43e632ea0d71ef83323a30413f
Gerrit-PatchSet: 2
Gerrit-Project: analytics/udp-filters
Gerrit-Branch: master
Gerrit-Owner: Ram <[email protected]>
Gerrit-Reviewer: Diederik <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>
Gerrit-Reviewer: Ram <[email protected]>
Gerrit-Reviewer: Stefan.petrea <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits