TSG-22258 HTTP/2解析层不在扫描HTTP Method为CONNECT的请求,提供edit_element_tool工具获取HTML/JSON的层级关系
This commit is contained in:
100
plugin/business/tsg-http/test/edit_element_tool.cpp
Normal file
100
plugin/business/tsg-http/test/edit_element_tool.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <sys/types.h>//fstat
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "edit_element.h"
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
printf("Edit element help\n");
|
||||
printf("-i Input File Name\n");
|
||||
printf("-f Find KeyWords\n");
|
||||
printf("-d Distance From Matching\n");
|
||||
printf("-t File Content Type, 0: html 1: json\n");
|
||||
}
|
||||
|
||||
char *edit_element_read_file(const char *filename, size_t *input_sz)
|
||||
{
|
||||
struct stat file_info;
|
||||
stat(filename, &file_info);
|
||||
*input_sz=file_info.st_size;
|
||||
|
||||
FILE* fp=fopen(filename,"r");
|
||||
char* input=(char*)malloc(*input_sz);
|
||||
fread(input,1,*input_sz,fp);
|
||||
fclose(fp);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int distane_from_matching = 0, option=0;
|
||||
const char* find=NULL, *filename=NULL;
|
||||
|
||||
int oc=0;
|
||||
if(argc<3)
|
||||
{
|
||||
print_help();
|
||||
return -1;
|
||||
}
|
||||
while((oc=getopt(argc,argv,"f:d:t:i:"))!=-1)
|
||||
{
|
||||
switch(oc)
|
||||
{
|
||||
case 'i':
|
||||
filename=strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
option=atoi(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
find=strdup(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
distane_from_matching=atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
printf("Invalid parameter.\n");
|
||||
print_help();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(distane_from_matching > 128)
|
||||
{
|
||||
printf("Distance From Matching supports up to 128.\n");
|
||||
print_help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *output=NULL, *input=NULL;
|
||||
size_t input_sz=0, n_got_rule=0;
|
||||
|
||||
input=edit_element_read_file(filename, &input_sz);
|
||||
|
||||
struct edit_element_rule rules[128];
|
||||
memset(rules, 0, sizeof(rules));
|
||||
for(int i = 0; i <= distane_from_matching; i++)
|
||||
{
|
||||
rules[i].debug_for_log=1;
|
||||
rules[i].scope=kScopeInside;
|
||||
rules[i].distane_from_matching=i;
|
||||
rules[i].start_indicator=(char *)"log";
|
||||
rules[i].element_treatment=(char *)"mark";
|
||||
rules[i].contained_keyword=(char *)find;
|
||||
|
||||
n_got_rule=1;
|
||||
printf("distane_from_matching: %d\n", i);
|
||||
execute_edit_element_rule(input, strlen(input), &rules[i], n_got_rule, &output, option);
|
||||
free(output);
|
||||
}
|
||||
free(input);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user