Commit f278fe30 authored by 's avatar
Browse files

just replaced shift1...shift7 and skip1....skip7 with an array

code reduced by 50 lines :)



git-svn-id: file:///home/svn/mapi/trunk@264 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent f88560c2
......@@ -40,7 +40,6 @@ struct filters {
unsigned int daddr;
uint16_t sp;
uint16_t dp;
struct filters *next;
};
......@@ -49,96 +48,44 @@ struct list{
struct filters *tail;
};
struct mapid_gnutella {
int *shift1; /* Boyer-Moore Shift table */
int *skip1; /* Boyer-Moore Skip table */
int *shift2; /* Boyer-Moore Shift table */
int *skip2; /* Boyer-Moore Skip table */
int *shift3; /* Boyer-Moore Shift table */
int *skip3; /* Boyer-Moore Skip table */
int *shift4; /* Boyer-Moore Shift table */
int *skip4; /* Boyer-Moore Skip table */
int *shift5; /* Boyer-Moore Shift table */
int *skip5; /* Boyer-Moore Skip table */
int *shift6; /* Boyer-Moore Shift table */
int *skip6; /* Boyer-Moore Skip table */
int *shift7; /* Boyer-Moore Shift table */
int *skip7; /* Boyer-Moore Skip table */
char *gnutella_strings[7]={"GET /uri-res/","GNUTELLA CONNECT/","GNUTELLA/","GET /get/","GND","GNUTELLA","GIV"};
struct mapid_gnutella {
int *shift[7];
int *skip[7];
struct list *gnulist;
};
static int gnutella_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flits)
{
int i=0;
//printf("in init\n");
instance->internal_data = malloc(sizeof(struct mapid_gnutella));
((struct mapid_gnutella*)instance->internal_data)->gnulist = (struct list*)malloc(sizeof(struct list));
((struct mapid_gnutella*)instance->internal_data)->gnulist->head = NULL;
((struct mapid_gnutella*)instance->internal_data)->gnulist->head = NULL;
((struct mapid_gnutella*)instance->internal_data)->shift1 = make_shift("GET /uri-res/",strlen("GET /uri-res/"));
((struct mapid_gnutella*)instance->internal_data)->skip1 = make_skip("GET /uri-res/", strlen("GET /uri-res/"));
((struct mapid_gnutella*)instance->internal_data)->shift2 = make_shift("GNUTELLA CONNECT/",strlen("GNUTELLA CONNECT/"));
((struct mapid_gnutella*)instance->internal_data)->skip2 = make_skip("GNUTELLA CONNECT/", strlen("GNUTELLA CONNECT/"));
((struct mapid_gnutella*)instance->internal_data)->shift3 = make_shift("GNUTELLA/",strlen("GNUTELLA/"));
((struct mapid_gnutella*)instance->internal_data)->skip3 = make_skip("GNUTELLA/", strlen("GNUTELLA/"));
((struct mapid_gnutella*)instance->internal_data)->shift4 = make_shift("GET /get/",strlen("GET /get/"));
((struct mapid_gnutella*)instance->internal_data)->skip4 = make_skip("GET /get/", strlen("GET /get/"));
((struct mapid_gnutella*)instance->internal_data)->shift5 = make_shift("GND",strlen("GND"));
((struct mapid_gnutella*)instance->internal_data)->skip5 = make_skip("GND", strlen("GND"));
((struct mapid_gnutella*)instance->internal_data)->shift6 = make_shift("GNUTELLA",strlen("GNUTELLA"));
((struct mapid_gnutella*)instance->internal_data)->skip6 = make_skip("GNUTELLA", strlen("GNUTELLA"));
((struct mapid_gnutella*)instance->internal_data)->shift7 = make_shift("GIV",strlen("GIV"));
((struct mapid_gnutella*)instance->internal_data)->skip7 = make_skip("GIV", strlen("GIV"));
for(i=0;i<7;i++) {
((struct mapid_gnutella*)instance->internal_data)->shift[i] = make_shift(gnutella_strings[i],strlen(gnutella_strings[i]));
((struct mapid_gnutella*)instance->internal_data)->skip[i] = make_skip(gnutella_strings[i], strlen(gnutella_strings[i]));
}
//printf("out init\n");
return 0;
}
int isGnutella(mapidflib_function_instance_t *instance, const unsigned char *pkt, int len)
{
if(mSearch((unsigned char *)(pkt), len, "GET /uri-res/", strlen("GET /uri-res/"),
((struct mapid_gnutella *)instance->internal_data)->skip1,
((struct mapid_gnutella *)instance->internal_data)->shift1))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GNUTELLA CONNECT/", strlen("GNUTELLA CONNECT/"),
((struct mapid_gnutella *)instance->internal_data)->skip2,
((struct mapid_gnutella *)instance->internal_data)->shift2))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GNUTELLA/", strlen("GNUTELLA/"),
((struct mapid_gnutella *)instance->internal_data)->skip3,
((struct mapid_gnutella *)instance->internal_data)->shift3))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GET /get/", strlen("GET /get/"),
((struct mapid_gnutella *)instance->internal_data)->skip4,
((struct mapid_gnutella *)instance->internal_data)->shift4))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GND", strlen("GND"),
((struct mapid_gnutella *)instance->internal_data)->skip5,
((struct mapid_gnutella *)instance->internal_data)->shift5))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GNUTELLA", strlen("GNUTELLA"),
((struct mapid_gnutella *)instance->internal_data)->skip6,
((struct mapid_gnutella *)instance->internal_data)->shift6))
{
return 1;
}
else if(mSearch((unsigned char *)(pkt), len, "GIV", strlen("GIV"),
((struct mapid_gnutella *)instance->internal_data)->skip7,
((struct mapid_gnutella *)instance->internal_data)->shift7))
{
return 1;
}
int i=0;
for(i=0;i<7;i++) {
if(mSearch((unsigned char *)(pkt), len, gnutella_strings[i], strlen(gnutella_strings[i]),
((struct mapid_gnutella *)instance->internal_data)->skip[i],
((struct mapid_gnutella *)instance->internal_data)->shift[i]))
{
return 1;
}
}
return 0;
}
......@@ -185,10 +132,6 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p += iph->ihl * 4;
new = (struct filters*)malloc(sizeof(struct filters));
if(new == NULL)
printf("new = NULL\n");
if(iph->protocol == 6) // TCP
{
......@@ -215,6 +158,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
if(isGnutella(instance,pkt,len) == 1)
{
new = (struct filters*)malloc(sizeof(struct filters));
if(new == NULL)
printf("new = NULL\n");
new->protocol = iph->protocol;
new->saddr = saddr;
new->daddr = daddr;
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment