两个功能
1. 注释
#define USE_FILE
执行的是字符串替换功能
2. 不注释
#define USE_FILE
执行的是文件中的字符串解析(分割)功能
其中字符串替换 使用 void strReplace
(char
* source
, char
* sub, char
* rep
);
该文档留作备用
- #include<stdlib.h>
- #include<stdio.h>
- #include <string.h>
- //#define USE_FILE
- #ifdef USE_FILE
- #define CHILLI_CONFIG "./test.txt"
- #endif
- void strReplace(char* source, char* sub, char* rep)
- {
- char* src = source;
- char* temp= strstr(source,sub);
- char end_result[256]="";
- char *result = NULL;
-
- temp = strstr(source,sub);
- if(temp)
- {
- result = malloc( sizeof(char *) * (strlen(source) + strlen(rep)) );
- strcpy(end_result,rep);
- strcpy(result,temp+strlen(sub));
- strReplace(result,sub,rep);
- strcat(end_result,result);
- source[strlen(source) - strlen(temp)] = '\0';
- strcpy(result,source);
- strcat(result,end_result);
- strcpy(source,result);
- free(result);
- }
- }
- int strOperate(char *str)
- {
- #ifdef USE_FILE
- FILE *fd;
- char seps[] = ";\n";
- #else
- char seps[] = ",\n";
- #endif
- char buffer[256] = {0};
- int IsFind=0;
-
- char name[32] = {0};
- char value[256] = {0};
-
- char ddd[]="*.brasiltelecom.com.br,*.fon.com,ssl.google-analytics.com,fon-en.custhelp.com,
- *.telemar.com.br,maps.gstatic.com,maps.google.com,!wifi.fon.com,a4.g.akamai.net,access.skype.com,
- *.paypal.com,*.paypalobjects.com,*.clickandbuy.com,mpsnare.iesnare.com,*.verisign.com,crl.comodoca.com,
- *.oi.net.br,*.ezconet.com.br,*.zendesk.com,gg.google.com,mt.l.google.com,mt0.google.com,mt1.google.com,
- ocsp.comodoca.com,ocsp.usertrust.com,*.oi.com.br,*.ig.com.br,*.btfon.com,*.nintendowifi.net,a248.e.akamai.net,*.wii.com,*.ss.*.com";
- char cmd[256] = "uamallowed ";
-
-
- char *token ;
- int i = 0;
- #ifdef USE_FILE
- if((fd=fopen(CHILLI_CONFIG,"r"))==NULL)
- {
- return 0;
- }
- while(fgets(buffer, 256, fd))
- {
- if( strlen(buffer) > 1 )
- {
- token = strtok( buffer, seps );
- #else
- token = strtok( ddd, seps );
- #endif
- //printf("!^wifi.fon.com$\n");
- while( token != NULL )
- {
- #ifdef USE_FILE
- sprintf(cmd,"uamallowed %s",token);
- //strcat(cmd,token);
- //strcat(cmd,"\n");
- #else
- char *tempString = NULL;
- tempString = malloc(strlen(token) * sizeof(char *) );
- strcpy(tempString,token);
- strReplace( tempString , "*." , "(.*\\.)?" );
- if( tempString[0] == '!')
- {
- sprintf(cmd,"!^%s$",tempString);
- }
- else
- {
- sprintf(cmd,"^%s$",tempString);
- }
- free(tempString);
- i++;
- #endif
- printf("%s\n",cmd);
- token = strtok( NULL, seps );
- }
- #ifdef USE_FILE
- }
- }
-
- fclose(fd);
-
- printf("\n\n\n\n",CHILLI_CONFIG);
- #endif
- return IsFind;
- }
- int main(void)
- {
- char *str1="START_CHILLI=1";
- int t1=0,t2=0;
- strOperate(str1);
- return 0;
- }
test.txt
- 213.134.44.0/23,www.paypal.com,www.paypalobjects.com;paypal.112.2o7.net;202.232.239.16/28,203.180.85.64/26,173.203.47.186;www.delta.fon.com,shop.delta.fon.com,maps.delta.fon.com;www.sandbox.paypal.com,sandbox.paypal.com,developer.paypal.com
阅读(1366) | 评论(0) | 转发(0) |