📄 htp.c
字号:
{ if(printMsg) { HtpMsg(MSG_INFO, task->infile, "image pre-processing turned ON"); } } else { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "image pre-processing turned OFF"); } } } if(stricmp(name, OPT_N_DEPEND) == 0) { if(stricmp(value, OPT_V_TRUE) == 0) { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "dependency checking turned ON"); } } else { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "dependency checking turned OFF"); } } } if(stricmp(name, OPT_N_PRECIOUS) == 0) { if(stricmp(value, OPT_V_TRUE) == 0) { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "precious output turned ON"); } } else { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "precious output turned OFF"); } } } if(stricmp(name, OPT_N_CONDENSE) == 0) { if(stricmp(value, OPT_V_TRUE) == 0) { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "output will be condensed"); } if(task != NULL) { SuppressLinefeeds(task->outfile); } } else { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "output will not be condensed"); } if(task != NULL) { AllowLinefeeds(task->outfile); } } } if(stricmp(name, OPT_N_KEEP_TEMP) == 0) { if(stricmp(value, OPT_V_TRUE) == 0) { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "DEBUG: keeping temporary files"); } } else { if(printMsg) { HtpMsg(MSG_INFO, task->infile, "DEBUG: not keeping temporary files"); } } } if(stricmp(name, OPT_N_SET_DELIM) == 0) { if(stricmp(value, OPT_V_DELIM_HTML) == 0) { htpOpenMarkup = '<'; htpCloseMarkup = '>'; } else if(stricmp(value, OPT_V_DELIM_SQUARE) == 0) { htpOpenMarkup = '['; htpCloseMarkup = ']'; } else if(stricmp(value, OPT_V_DELIM_CURLY) == 0) { htpOpenMarkup = '{'; htpCloseMarkup = '}'; } if(printMsg) { HtpMsg(MSG_INFO, task->infile, "markup delimiter set to \"%s\"", value); } } return TRUE;}uint OptionProcessor(TASK *task, HTML_MARKUP *htmlMarkup, char **newPlaintext){ UNREF_PARAM(newPlaintext); if(ParseMarkupOption(htmlMarkup, OptionCallback, (ulong) task) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "error parsing markup options (out of memory?)"); return MARKUP_ERROR; } return DISCARD_MARKUP;} uint ExternalFileProcessor(TASK *task, HTML_MARKUP *htmlMarkup, const char *externalName, char **newPlaintext){ struct stat fileStat; struct tm *fileTime; uint precision; const char *attribValue; const char *precisionString; const char *value; assert(externalName != NULL); assert(htmlMarkup != NULL); /* get information on the file itself */ if(stat(externalName, &fileStat) != 0) { HtpMsg(MSG_ERROR, task->infile, "unable to retrieve file information on \"%s\"", externalName); return MARKUP_ERROR; } /* get the precision attribute value, if present */ /* (this is only valid for SIZE attribute, but not checking for simplicity */ /* ignored for other types of FILE attributes) */ precision = DEFAULT_PRECISION; if(IsAttributeInMarkup(htmlMarkup, "PRECISION")) { precisionString = MarkupAttributeValue(htmlMarkup, "PRECISION"); if(precisionString != NULL) { precision = atoi(precisionString); } else { HtpMsg(MSG_WARNING, task->infile, "precision attribute needs a value"); } } /* allocate room for the replacment plaintext */ if((*newPlaintext = AllocMemory(MAX_TIME_DATE_SIZE)) == NULL) { HtpMsg(MSG_ERROR, task->infile, "unable to allocate memory for expansion"); return MARKUP_ERROR; } /* create new plaintext depending on what extra information is specified */ /* !! this is technically not correct ... SIZE, TIME, and DATE are */ /* not allowed in the same markup but not checking that only one is */ /* present and not any others */ if(IsAttributeInMarkup(htmlMarkup, "SIZE")) { attribValue = MarkupAttributeValue(htmlMarkup, "SIZE"); /* expand markup depending on how SIZE should be represented */ if((attribValue == NULL) || (stricmp(attribValue, "BYTE") == 0)) { /* byte representation is default */ sprintf(*newPlaintext, "%lu", fileStat.st_size); } else if(stricmp(attribValue, "KBYTE") == 0) { sprintf(*newPlaintext, "%.*f", (int) precision, (double) ((double) fileStat.st_size / (double) KBYTE)); } else if(stricmp(attribValue, "MBYTE") == 0) { sprintf(*newPlaintext, "%.*f", (int) precision, (double) ((double) fileStat.st_size / (double) MBYTE)); } else if(stricmp(attribValue, "GBYTE") == 0) { sprintf(*newPlaintext, "%.*f", (int) precision, (double) ((double) fileStat.st_size / (double) GBYTE)); } else { /* free the plaintext memory before returning */ HtpMsg(MSG_ERROR, task->infile, "unknown SIZE specifier"); FreeMemory(*newPlaintext); *newPlaintext = NULL; return MARKUP_ERROR; } } else if(IsAttributeInMarkup(htmlMarkup, "TIME")) { const char *value; /* convert into an ANSI time structure */ fileTime = localtime(&fileStat.st_mtime); /* see if the attribute has a value ... if so, let it be the */ /* strftime() formatter */ if((value = MarkupAttributeValue(htmlMarkup, "TIME")) != NULL) { strftime(*newPlaintext, MAX_TIME_DATE_SIZE, value, fileTime); } else { strftime(*newPlaintext, MAX_TIME_DATE_SIZE, "%I:%M:%S %p", fileTime); } } else if(IsAttributeInMarkup(htmlMarkup, "DATE")) { /* convert into an ANSI time structure */ fileTime = localtime(&fileStat.st_mtime); /* see if the attribute has a value ... if so, let it be the */ /* strftime() formatter */ if((value = MarkupAttributeValue(htmlMarkup, "DATE")) != NULL) { strftime(*newPlaintext, MAX_TIME_DATE_SIZE, value, fileTime); } else { strftime(*newPlaintext, MAX_TIME_DATE_SIZE, "%a %b %d, %Y", fileTime); } } else { /* free the plaintext, unused */ FreeMemory(*newPlaintext); *newPlaintext = NULL; HtpMsg(MSG_ERROR, task->infile, "bad file information specifier"); return MARKUP_ERROR; } /* the new plaintext was created successfully */ return NEW_MARKUP;}uint FileExecuteProcessor(TASK *task, HTML_MARKUP *htmlMarkup){ const char *cmdline; const char *output; char newCmdline[MAX_CMDLINE_LEN]; char tempFilename[MAX_PATHNAME_LEN]; BOOL redirect; TEXTFILE infile; TASK newTask; BOOL result; uint exitCode; assert(task != NULL); assert(htmlMarkup != NULL); if((cmdline = MarkupAttributeValue(htmlMarkup, "EXECUTE")) == NULL) { HtpMsg(MSG_ERROR, task->infile,"FILE EXECUTE must specify a command-line"); return MARKUP_ERROR; } output = MarkupAttributeValue(htmlMarkup, "OUTPUT"); redirect = IsAttributeInMarkup(htmlMarkup, "REDIRECT"); /* either output or redirect, but not both, must be specified */ if((output == NULL) && (redirect == FALSE)) { HtpMsg(MSG_ERROR, task->infile, "Either REDIRECT or OUTPUT must be specified for FILE EXECUTE"); return MARKUP_ERROR; } if((output != NULL) && (redirect == TRUE)) { HtpMsg(MSG_ERROR, task->infile, "REDIRECT and OUTPUT cannot both be specified for FILE EXECUTE"); return MARKUP_ERROR; } StringCopy(newCmdline, cmdline, MAX_CMDLINE_LEN); /* if redirection required, append to the command-line a redirector to */ /* a temporary file */ if(redirect) { if(CreateTempFilename(tempFilename, MAX_PATHNAME_LEN) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "unable to create a temporary file for redirection"); return MARKUP_ERROR; } strncat(newCmdline, " > ", MAX_PATHNAME_LEN); strncat(newCmdline, tempFilename, MAX_PATHNAME_LEN); } else { /* the specified output file is the "temporary" filename */ StringCopy(tempFilename, output, MAX_PATHNAME_LEN); } HtpMsg(MSG_INFO, task->infile, "Executing command \"%s\" ...", newCmdline); /* execute the command */ exitCode = system(newCmdline); if(exitCode != 0) { if(IsAttributeInMarkup(htmlMarkup, "NOERROR") == FALSE) { /* the program has exited with an error condition */ HtpMsg(MSG_ERROR, task->infile, "Command \"%s\" exited with an error code of %u", newCmdline, exitCode); /* remove the temporary file, in case it was partially created */ remove(tempFilename); return MARKUP_ERROR; } } /* include the output file like it was anything else */ /* first, open it */ if(OpenFile(tempFilename, tempFilename, "r", &infile) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "unable to open execute result file"); return MARKUP_ERROR; } /* build a new task */ newTask.infile = &infile; newTask.outfile = task->outfile; newTask.varstore = task->varstore; newTask.sourceFilename = task->sourceFilename; /* process the file */ result = ProcessTask(&newTask); /* close and destroy the output file */ CloseFile(&infile); remove(tempFilename); return (result == TRUE) ? DISCARD_MARKUP : MARKUP_ERROR;}uint FileTemplateProcessor(TASK *task, HTML_MARKUP *htmlMarkup){ const char *templateFile; assert(task != NULL); assert(htmlMarkup != NULL); if((templateFile = MarkupAttributeValue(htmlMarkup, "TEMPLATE")) == NULL) { HtpMsg(MSG_ERROR, task->infile, "a template file must be specified"); return MARKUP_ERROR; } /* the template file is not actually processed now, but rather when the */ /* rest of the file is completed ... to postpone processing, the template */ /* name is kept in the variable store under a special name and retrieved */ /* later */ if(StoreVariable(task->varstore, VAR_TEMPLATE_NAME, templateFile, VAR_TYPE_INTERNAL, 0, NULL, NULL) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "unable to store template filename for post-processing (out of memory?)"); return MARKUP_ERROR; } return DISCARD_MARKUP;}uint FileIncludeProcessor(TASK *task, HTML_MARKUP *htmlMarkup){ TEXTFILE incfile; BOOL result; TASK newTask; char fullPathname[MAX_PATHNAME_LEN]; const char *attribValue; VARSTORE varstore; VARSTORE *topVarstore; uint ctr; uint flag; /* get the filename to include */ attribValue = MarkupAttributeValue(htmlMarkup, "INCLUDE"); if(attribValue == NULL) { HtpMsg(MSG_ERROR, task->infile, "include filename not specified"); return MARKUP_ERROR; } /* open the include file as input */ if(OpenFile(attribValue, attribValue, "r", &incfile) == FALSE) { /* use the search path to find the file */ if(SearchForFile(attribValue, fullPathname, MAX_PATHNAME_LEN) == FALSE) { /* could not find the file in the search path either */ HtpMsg(MSG_ERROR, task->infile, "unable to open include file \"%s\"", attribValue); return MARKUP_ERROR; } if(OpenFile(fullPathname, fullPathname, "r", &incfile) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "unable to open include file \"%s\"", fullPathname); return MARKUP_ERROR; } } else { StringCopy(fullPathname, attribValue, MAX_PATHNAME_LEN); } /* if additional parameters exist in the tag, build a local varstore */ /* and push it onto the context */ if(htmlMarkup->attribCount > 1) { if(InitializeVariableStore(&varstore) == FALSE) { HtpMsg(MSG_ERROR, task->infile, "unable to initialize context for include file"); CloseFile(&incfile); return MARKUP_ERROR; } /* start including the parameters as local macros */ for(ctr = 1; ctr < htmlMarkup->attribCount; ctr++) { flag = (htmlMarkup->attrib[ctr].quoted == TRUE) ? VAR_FLAG_QUOTED : VAR_FLAG_NONE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -