void Transport::debuggerInfo(InfoVec &info) { Add(info, "Thread Type", getThreadTypeName()); Add(info, "URL", getCommand()); Add(info, "HTTP", getHTTPVersion()); Add(info, "Method", getMethodName()); if (getMethod() == Method::POST) { int size; getPostData(size); Add(info, "Post Data", FormatSize(size)); } }
void Transport::parsePostParams() { if (!m_postDataParsed) { assert(m_postData == nullptr); int size; const char *data = (const char *)getPostData(size); if (data && *data && size) { // Post data may be binary, but if parsePostParams() is called, it is // correct to handle it as a null-terminated string m_postData = strdup(data); parseQuery(m_postData, m_postParams); } m_postDataParsed = true; } }
void Transport::parsePostParams() { FiberWriteLock lock(this); ASSERT(!m_postDataParsed); ASSERT(m_postData == NULL); int size; const char *data = (const char *)getPostData(size); if (data && *data && size) { // Post data may be binary, but if parsePostParams() is called, it is // correct to handle it as a null-terminated string m_postData = strdup(data); parseQuery(m_postData, m_postParams); } m_postDataParsed = true; }
static int createFormData() { char *pat; decodeFormData(query); pat = "application/x-www-form-urlencoded"; if (mprStrcmpAnyCaseCount(contentType, pat, (int) strlen(pat)) == 0) { if (getPostData() < 0) { return EJS_ERR; } if (contentLength > 0) { pat = "application/x-www-form-urlencoded"; if (mprStrcmpAnyCaseCount(contentType, pat, (int) strlen(pat)) == 0) { decodeFormData(input); } } } return 0; }
int main(int argc, char **argv, char **envp) #endif { char *cp, *method; int i, j, err; err = 0; outputArgs = outputQuery = outputEnv = outputPost = 0; outputBytes = outputHeaderLines = responseStatus = 0; outputLocation = 0; nonParsedHeader = 0; responseMsg = 0; hasError = 0; timeout = 0; queryBuf = 0; queryLen = 0; numQueryKeys = numPostKeys = 0; originalArgc = argc; originalArgv = argv; #if _WIN32 && !WINCE _setmode(0, O_BINARY); _setmode(1, O_BINARY); _setmode(2, O_BINARY); #endif if (strstr(argv[0], "nph-") != 0) { nonParsedHeader++; } if (getArgv(&argc, &argv, originalArgc, originalArgv) < 0) { error("Can't read CGI input"); } for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } for (cp = &argv[i][1]; *cp; cp++) { switch (*cp) { case 'a': outputArgs++; break; case 'b': if (++i >= argc) { err = __LINE__; } else { outputBytes = atoi(argv[i]); } break; case 'e': outputEnv++; break; case 'h': if (++i >= argc) { err = __LINE__; } else { outputHeaderLines = atoi(argv[i]); nonParsedHeader++; } break; case 'l': if (++i >= argc) { err = __LINE__; } else { outputLocation = argv[i]; if (responseStatus == 0) { responseStatus = 302; } } break; case 'n': nonParsedHeader++; break; case 'p': outputPost++; break; case 'q': outputQuery++; break; case 's': if (++i >= argc) { err = __LINE__; } else { responseStatus = atoi(argv[i]); } break; case 't': if (++i >= argc) { err = __LINE__; } else { timeout = atoi(argv[i]); } break; default: err = __LINE__; break; } } } if (err) { fprintf(stderr, "usage: cgiProgram -aenp [-b bytes] [-h lines]\n" "\t[-l location] [-s status] [-t timeout]\n" "\tor set the HTTP_SWITCHES environment variable\n"); fprintf(stderr, "Error at cgiProgram:%d\n", __LINE__); exit(255); } if ((method = getenv("REQUEST_METHOD")) != 0 && strcmp(method, "POST") == 0) { if (getPostData(&postBuf, &postBufLen) < 0) { error("Can't read CGI input"); } if (strcmp(safeGetenv("CONTENT_TYPE"), "application/x-www-form-urlencoded") == 0) { numPostKeys = getVars(&postKeys, postBuf, postBufLen); } } if (hasError) { if (! nonParsedHeader) { printf("HTTP/1.0 %d %s\r\n\r\n", responseStatus, responseMsg); printf("<HTML><BODY><p>Error: %d -- %s</p></BODY></HTML>\r\n", responseStatus, responseMsg); } fprintf(stderr, "cgiProgram: ERROR: %s\n", responseMsg); exit(2); } if (nonParsedHeader) { if (responseStatus == 0) { printf("HTTP/1.0 200 OK\r\n"); } else { printf("HTTP/1.0 %d %s\r\n", responseStatus, responseMsg ? responseMsg: ""); } printf("Connection: close\r\n"); printf("X-CGI-CustomHeader: Any value at all\r\n"); } printf("Content-type: %s\r\n", "text/html"); if (outputHeaderLines) { for (i = 0; i < outputHeaderLines; i++) { printf("X-CGI-%d: A loooooooooooooooooooooooong string\r\n", i); } } if (outputLocation) { printf("Location: %s\r\n", outputLocation); } if (responseStatus) { printf("Status: %d\r\n", responseStatus); } printf("\r\n"); if ((outputBytes + outputArgs + outputEnv + outputQuery + outputPost + outputLocation + responseStatus) == 0) { outputArgs++; outputEnv++; outputQuery++; outputPost++; } if (outputBytes) { j = 0; for (i = 0; i < outputBytes; i++) { putchar('0' + j); j++; if (j > 9) { if (++outputBytes > 0) { putchar('\r'); } if (++outputBytes > 0) { putchar('\n'); } j = 0; } } } printf("<HTML><TITLE>cgiProgram: Output</TITLE><BODY>\r\n"); if (outputArgs) { #if _WIN32 printf("<P>CommandLine: %s</P>\r\n", GetCommandLine()); #endif printf("<H2>Args</H2>\r\n"); for (i = 0; i < argc; i++) { printf("<P>ARG[%d]=%s</P>\r\n", i, argv[i]); } } printEnv(envp); if (outputQuery) { printQuery(); } if (outputPost) { printPost(postBuf, postBufLen); } printf("</BODY></HTML>\r\n"); #if VXWORKS /* VxWorks pipes need an explicit eof string Must not call exit(0) in Vxworks as that will exit the task before the CGI handler can cleanup. Must use return 0. */ write(1, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN); write(2, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN); #endif fflush(stderr); fflush(stdout); return 0; }