summaryrefslogtreecommitdiff
path: root/plugin/business/tsg-http/test/edit_element_tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/business/tsg-http/test/edit_element_tool.cpp')
-rw-r--r--plugin/business/tsg-http/test/edit_element_tool.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/plugin/business/tsg-http/test/edit_element_tool.cpp b/plugin/business/tsg-http/test/edit_element_tool.cpp
new file mode 100644
index 0000000..74d27ee
--- /dev/null
+++ b/plugin/business/tsg-http/test/edit_element_tool.cpp
@@ -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;
+}
+
+