/** A DesktopQuery basically just looks like @desktop "term1", "term2", ... **/ bool DesktopQuery::parse() { if (!parseQueryString(queryString, CONTAINER_STRING, NULL, memoryLimit)) { syntaxErrorDetected = finished = true; ok = false; } else { if (statisticsQuery == NULL) statisticsQuery = containerQuery; processQuery(); ok = true; } return ok; } // end of parse()
int initGet(void) { int query_string_len; const char *query_string; query_string = getenv("QUERY_STRING"); if (query_string == NULL) { cgi_errno = CGIERR_NULQSTR; return false; } query_string_len = strlen(query_string); if (query_string_len != 0) return (parseQueryString(query_string, query_string_len)); return true; }
bool HttpParser::completeRequest() { Finally f([this]() { request_ = HttpRequest(); }); switch(parser_.method) { #define _(x) case HTTP_##x: request_.method_ = HttpRequest::x; break _(GET); _(HEAD); _(POST); #undef _ default: request_.method_ = HttpRequest::OTHER; } if(parser_.http_minor != 0) // treat as HTTP 1.1 { request_.http11_ = true; } request_.upgrade_ = !!parser_.upgrade; request_.keepAlive_ = !!http_should_keep_alive(&parser_); if(!parseRequestTarget(request_.rawTarget_, request_.target_, request_.queries_)) { return false; } try { // TODO: Content-Type parameters (charset, ...) if(parser_.method == HttpRequest::POST && boost::iequals(request_.headers_.at("Content-Type"), "application/x-www-form-urlencoded")) { if(!parseQueryString(request_.rawBody_, request_.queries_)) { return false; } } } catch(const std::out_of_range &) { } return currentCallback_(request_); }
void testQueryString() { void* ctx; parseQueryString(&ctx, "width=640&height=360&video=bigbunny.ogg"); const char* width = getParameter(ctx, "width"); const char* height = getParameter(ctx, "height"); const char* video = getParameter(ctx, "video"); if(!strcmp(width,"640")) { printf("Querystring width esperado:%s - recebido:%s\n", "640", width); } if(!strcmp(height,"360")) { printf("Querystring height esperado:%s - recebido:%s\n", "360", height); } if(!strcmp(video,"bigbunny.ogg")) { printf("Querystring video esperado:%s - recebido:%s\n", "bigbunny.ogg", video); } releaseContext(ctx); }
/** * Return paramter value for the given name. If returned string is empty, it means that the parameter was not present. * If the returned string is SSOAgentRequest::EMPTY_PARAM, it means that the parameter is present, without a value. */ string SSOAgentRequest::getParameter(string pName) { if (params.empty()) { string qryStr = this->getQueryString(); if (!qryStr.empty()) { // Read and parse query string into parameters. parseQueryString(qryStr); } else if (!strcmp(getMethod().c_str(), "POST")) { // Read and parse request body into parametsers. DWORD bodySz = this->getBodySize(); if (bodySz > 0) { LPBYTE body = this->getBody(); jk_log(logger, JK_LOG_DEBUG, "POST Request has a body, type=[%s] size=%d", getContentType().c_str(), bodySz); parsePostData(body, bodySz, this->getContentType()); } else { jk_log(logger, JK_LOG_DEBUG, "POST Request has no body"); } } else { jk_log(logger, JK_LOG_TRACE, "GET Request has no parameters, method [%s]", getMethod().c_str()); } // Just for debugging purposes map<string, string>::iterator i; for (i = params.begin() ; i != params.end() ; i++) { pair <string, string> p = *i; jk_log(logger, JK_LOG_DEBUG, "Populating request with param %s=[%s]", p.first.c_str(), p.second.c_str()); } } map<string, string>::const_iterator params_it; params_it = params.find(pName); // Did we find the parameter ?! if (params_it == params.end()) { return SSOAgentRequest::EMPTY_STR; } else { return params_it->second; } }
bool SSOAgentRequest::parsePostData(LPBYTE body, DWORD bodySize, string contentType) { jk_log(logger, JK_LOG_TRACE, "Parsing [%d] bytes of type %s as parameters", bodySize, contentType.c_str()); char * b = (char*) body; string sBody; sBody.assign(b, bodySize); jk_log(logger, JK_LOG_TRACE, "Body type[%s]\n%s", contentType.c_str(), sBody.c_str()); if (strcmp(contentType.c_str(), "application/x-www-form-urlencoded") == 0) { return parseQueryString(sBody); } else if (contentType.find("multipart/form-data;") == 0) { return parseMimeString(contentType, sBody); } else { jk_log(logger, JK_LOG_ERROR, "POST Data content type unknown : [%s]", contentType.c_str()); return false; } }
bool CDRQuery::parse() { // if no container is given, assume default container char defaultContainer[MAX_CONFIG_VALUE_LENGTH]; if (!getConfigurationValue("DEFAULT_RETRIEVAL_SET", defaultContainer)) strcpy(defaultContainer, DOC_QUERY); if (!parseQueryString(queryString, defaultContainer, NULL, memoryLimit)) { syntaxErrorDetected = finished = true; ok = false; } else if (((elementCount < 1) || (elementCount > CDR_MAX_SCORER_COUNT)) && (maxLevel > 1)) { // @cdr queries may not contain more than CDR_MAX_SCORER_COUNT query terms syntaxErrorDetected = finished = true; ok = false; } else { if (statisticsQuery == NULL) if (visibleExtents != NULL) statisticsQuery = new GCLQuery(index, visibleExtents->getExtentList()); processQuery(); ok = true; } return ok; } // end of parse()
int initPost(void) { const char *str; const char *mpfd="multipart/form-data"; unsigned int content_length; /* get/check content length */ str = getenv("CONTENT_LENGTH"); if (str == NULL) { cgi_errno = CGIERR_ICONTLEN; return false; } if (!miscStringToUInt(str, &content_length)) { cgi_errno = CGIERR_ICONTLEN; return false; } if (content_length == 0) return(true); /* get/check content type */ str = getenv("CONTENT_TYPE"); if (str == NULL) { cgi_errno = CGIERR_UCONTT; return 0; } /* multipart encoded ? */ if (!strncasecmp(str, mpfd, strlen(mpfd))) return(initMultiPart(str)); /* "normal" url encoded ? */ if (!strcasecmp(str, "application/x-www-form-urlencoded")) return(parseQueryString(NULL, content_length)); cgi_errno = CGIERR_UCONTT; return false; }
void handleRequest(session_t* session, int connectFd, char* resource, char* postData) { gchar** data = g_strsplit(resource, "?", 2); gchar* file = data[0]; GHashTable* query = parseQueryString(data[1]); bool hasBG = false; bool isSlashTest = false; if (data[1] == NULL && (g_strcmp0(data[0], "/") == 0)) { generateResponse(session, connectFd, resource, NULL, false, "200", isSlashTest, query, postData); } else { if (g_strcmp0(file, "/color") == 0) { gchar* color = g_hash_table_lookup(query, "bg"); if (color != NULL) { // URI contains /color?bg=x hasBG = true; generateResponse(session, connectFd, resource, color, hasBG, "200", isSlashTest, query, postData); } else { // URI does not contains bg=(...) // Check if request contains cookie gchar* cookie = g_hash_table_lookup(session->headers, "Cookie"); if (cookie == NULL) { generateResponse(session, connectFd, resource, NULL, hasBG, "200", isSlashTest, query, postData); } else { gchar **pairs = g_strsplit(cookie, "; ", 100); gchar** pair; int size = g_strv_length(pairs), i; for (i = 0; i < size; i++) { pair = g_strsplit(pairs[i], "=", 2); if (g_strcmp0(pair[0], "color") == 0) { generateResponse(session, connectFd, resource, pair[1], 1, "200", isSlashTest, query, postData); break; } } } } } else if (g_strcmp0(file, "/test") == 0) { isSlashTest = true; generateResponse(session, connectFd, resource, NULL, hasBG, "200", isSlashTest, query, postData); } else { generateResponse(session, connectFd, resource, NULL, false, "404", isSlashTest, query, postData); } } }
if ( EqualLiteralLength( key, keyLength, "info_hash" ) ) { ScrapeCallbackData *cbd = data; if ( !cbd->top ) { cbd->top = ScrapeData_new( ); if ( !cbd->top ) return ScrapeError_unknown; cbd->last->next = cbd->top; } if ( dualDecodeInfoHash( value, valueLength, cbd->top->compactHash, cbd->top->infoHash ) != 40 ) return ScrapeError_malformedInfoHash; // ugh. cbd->last = cbd->top; cbd->top = cbd->last->next; } else return ScrapeError_invalidRequest; return ScrapeError_okay; } ScrapeError ScrapeData_fromQuery( ScrapeData *scrape, const char *query, size_t queryLength ) { ScrapeCallbackData data = { .top = scrape }; int e = parseQueryString( query, queryLength, ScrapeData_parse, &data ); if ( e ) return e; // this will only be true if no info_hash keys are encountered in the // query. if ( data.last == NULL ) return 1; ScrapeData_dump( scrape ); return ScrapeError_okay; }
bool checkArgs(int argc, char* argv[], char** inFile, outFormat &out, int &rowStart, int &rowEnd) { char env[256]; if (argc < 2) { std::string tmpFile; //printf("No input file specified\n"); //#ifdef _DEBUG #if 1 *inFile = _strdup("c:\\Users\\David\\Documents\\packets.txt"); if (GetEnvironmentVariableA("QUERY_STRING", env, 256)) { //printf("<query>%s</query>\n", env); parseQueryString(env, rowStart, rowEnd); } out = XML; #else std::cout << "Filename: "; std::getline(std::cin, tmpFile); *inFile = _strdup(tmpFile.c_str()); #endif #ifdef _DEBUG printf("inFile is %s\n", *inFile); #endif return true; //return false; //needs an input file } if (argc>2) { *inFile = _strdup(argv[1]); for (int i = 2; i <= argc; i++) { if (strcmp(argv[i], "-x") == 0) { if (out == CSV) { printf("-x cannot be specified along with -c\n"); return false; } else out = XML; continue; } if (strcmp(argv[i], "-c") == 0) { if (out == XML) { printf("-c cannot be specified along with -x\n"); return false; } else out = CSV; continue; } if (strncmp(argv[i], "-r", 2) == 0) { //TODO parse beginning and ending rows continue; } return false; } } return true; }
void testparseQueryString() { int rowStart=-1, rowEnd=-1; parseQueryString("rowStart=0&rowEnd=19", rowStart, rowEnd); assert(rowStart == 0 && rowEnd == 19); }