Index: trunk/debs/squid/redirector.c |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | */ |
11 | 11 | |
12 | 12 | #include <stdio.h> |
| 13 | +#include <string.h> |
13 | 14 | #include <stdlib.h> |
14 | 15 | #include <string.h> |
15 | 16 | #include <malloc.h> |
— | — | @@ -25,23 +26,15 @@ |
26 | 27 | }; |
27 | 28 | |
28 | 29 | int load_in_buff(char *buff, struct IN_BUFF *in_buff) { |
29 | | - int converted; |
30 | | - |
31 | | - strcpy(in_buff->url, ""); |
32 | | - strcpy(in_buff->src_address, ""); |
33 | | - strcpy(in_buff->ident, ""); |
34 | | - strcpy(in_buff->method, ""); |
| 30 | + in_buff->url = strtok(buff, " "); |
| 31 | + in_buff->src_address = strtok(NULL, " "); |
| 32 | + in_buff->ident= strtok(NULL, " "); |
| 33 | + in_buff->method= strtok(NULL, " \n");; |
35 | 34 | |
36 | | - converted = sscanf(buff, "%s %s %s %s\n", in_buff->url, in_buff->src_address, in_buff->ident, in_buff->method); |
37 | | - |
38 | | - if(converted != 4) { |
| 35 | + if (!in_buff->src_address || !in_buff->ident || !in_buff->method) { |
39 | 36 | return 1; |
40 | 37 | } |
41 | 38 | |
42 | | - if(strcmp(in_buff->src_address, "") == 0) { |
43 | | - return 1; |
44 | | - } |
45 | | - |
46 | 39 | if(strlen(in_buff->url) <= 4) { |
47 | 40 | return 1; |
48 | 41 | } |
— | — | @@ -63,10 +56,6 @@ |
64 | 57 | |
65 | 58 | struct IN_BUFF *in_buff = NULL; |
66 | 59 | in_buff = (struct IN_BUFF *)malloc(sizeof(struct IN_BUFF)); |
67 | | - in_buff->url = malloc(MAX_BUFF); |
68 | | - in_buff->src_address = malloc(MAX_BUFF); |
69 | | - in_buff->ident = malloc(MAX_BUFF); |
70 | | - in_buff->method = malloc(MAX_BUFF); |
71 | 60 | pattern = "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/(.*)"; |
72 | 61 | pcre_extra *pe; |
73 | 62 | |