/**used by DoHTML for scanning some values in http-files and insert DATA and send them to browser**/ int handle_get(char *data, FILE *write_f) { char *var_index; char *sel_value='\0'; int if_prm = 1; static int loop_counter = 0; // used if loops exissted if(loop_counter > 10){ fprintf(write_f, "max loop counter reached\n"); return 0; } loop_counter++; // alarm(TIMEOUT);//RAW // free_page_mem(); //free memory of page includes //in search used parsestr1() char *search[] = {"<!--/ if=\"/[/*/]\"/ -->/,\n,", //0 "<!--/ else/ -->/,\n,", //1 "<!--/ //if/ -->/,\n,", //2 "<!--/ CGI:/ /[/*/]END_CGI/ -->", //3 "??/[/*/]??", //4 "<!--/ #include/ /[/*/]-->/,\n,", "<!--/ TABLE:/ /[/*/]END_TABLE/ -->", //6 // "<input/ type=\"/[/*/]\"", //maybe replace via 4 "<input/ type=\"radio\"", "<select/*name=\"/[/*/]\"", //8 "<option/*value=\"/[/*/]\"", "<!--/*-->", NULL}; int i = 0; char *ptr, *file_head; while(*data){ if(*data == *search[i] && (var_index = parsestr1(data+1, search[i]+1))){ ptr = point[1]; //do something with i. switch(i){ case 0: if(cfg_arg_strcmp(var_index, 0)){ //compare WEB_NAME //not matching, skip if_prm = 0; } else // is matching, print if_prm = 1; break; case 1: if_prm = !if_prm; //invers break; case 2: //is matching, print if_prm = 1; break; } if(if_prm) switch(i){ case 3: //CGI script parse_cgi_script(var_index); point[1] = ptr; case 4: //show variables value file_head = get_var(NULL, var_index); if(file_head) print(write_f, file_head);/*fprintf(write_f,"%s", file_head);*/ #ifdef DEBUG printf(" Var_index %s file_head %s\n", var_index, file_head); #endif point[1] = ptr; break; case 5: //include descriptor include_(data, var_index, write_f); point[1] = ptr; break; case 6: //table parse_tbl(var_index); point[1] = ptr; break; case 7: //input-form-atribute /* if (!strcmp(var_index, "text") || !strcmp(var_index, "password") || !strcmp(var_index, "hidden")) //main used for def. input text text_value_insert(file_head, point[1], write_f); // text_value_insert(file_head, ptr, write_f); else */ // if (!strcmp(var_index, "radio")) radio_value_insert(data, point[1], write_f); // else fprintf(write_f,"%s\"", data); break; case 8: //select-form-attribute // find there is a 'select drop-down list' in this line and insert the value for displaying fprintf(write_f,"%s\"", data); sel_value = get_cfg_value(NULL, var_index, 0); break; case 9: //option-form-attribute fprintf(write_f,"%s\"", data); if(sel_value && strcmp(sel_value,var_index)==0) fprintf(write_f, " selected"); #ifdef DEBUG printf("select_value_insert: %s, =? value: %s\n", var_index, sel_value); #endif break; case 10: break;//comments not show!! } data = point[1]; i = 0; //printf("INDEX %d\n", i); } else { i++; // if(!if_prm && (i==4)) {i= 0;continue;}//if_prm ==0 =>check only first three lines if(search[i]) continue; i = 0; // if(if_prm) fprintf(write_f,"%c", *file_head); if(if_prm) putc(*data, write_f); data++; } } loop_counter--; // printf("Time to ALARM: %d\n", alarm(0));//RAW return 0; }
static void makecfg( FILE *ifp, FILE *ofp, FILE *ofp2) { char buffer[BUFSIZ]; MYDATA *p, *q; static const char *const table_1[] = { "/* This file is generated by MAKECFG */" ,"" ,"#ifndef TINCFG_H" ,"#define TINCFG_H 1" ,"" ,"/* Macros for defining symbolic offsets that can be ifdef'd */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#ifdef lint" ,"#\tdefine OINX(T, M) 0 /* 'lint -c' cannot be appeased */" ,"#\tdefine OVAL(T, M) char M;" ,"#\tdefine OEND(T, M) char M;" ,"#\tdefine OTYP struct" ,"#else" ,"#\tifdef CPP_DOES_CONCAT" ,"#\t\tdefine OINX(T, M) T ## M" ,"#\t\tdefine OVAL(T, M) T ## M," ,"#\t\tdefine OEND(T, M) T ## M" ,"#\t\tdefine OTYP enum" ,"#\telse" ,"#\t\tdefine OINX(T, M) \\" ,"\t\t\t(((int)&(((T*)0)->M))/ \\" ,"\t\t\t ((int)&(((T*)0)->Q1) - (int)&(((T*)0)->s_MAX)))" ,"#\t\tdefine OVAL(T, M) char M;" ,"#\t\tdefine OEND(T, M) char M;" ,"#\t\tdefine OTYP struct" ,"#\tendif /* CPP_DOES_CONCAT */" ,"#endif /* lint */" ,0 }; static const char *const table_2[] = { "" ,"/* We needed these only to make the table compile */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#endif /* TINCFG_H */" ,0 }; static const char *const table_3[] = { "/* This file is generated by MAKECFG */", "", "#ifndef OPTIONS_MENU_H", "#define OPTIONS_MENU_H 1", "", 0 }; static const char *const table_4[] = { "", "#endif /* OPTIONS_MENU_H */", 0 }; /* * Process the input file. */ line_no = 0; while (fgets(buffer, sizeof(buffer) - 1, ifp)) parse_tbl(buffer); fclose(ifp); /* * Generate the output file */ write_it(ofp, table_1); /* * For each type used in the table, generate a list of pointers to * that type. */ for (p = all_data; p != 0; p = p->link) { int found = FALSE; if (p->name[0] == '#') continue; if (type_is_int(p) || is_title(p)) continue; for (q = all_data; p != q; q = q->link) { if (!strcmp(p->type, q->type)) { found = TRUE; break; } } if (!found && !strncmp(p->type, "OPT_", 4)) { generate_ptr (ofp, p->type, typename_of(p), 0); generate_ptr (ofp, p->type, typename_of(p), 1); generate_ptr (ofp, p->type, typename_of(p), 2); } } generate_tbl(ofp); write_it(ofp, table_2); fclose(ofp); if (ofp2) { write_it(ofp2, table_3); generate_enum(ofp2); write_it(ofp2, table_4); fclose(ofp2); } }