// Renders the response void renderResponse(struct ns_connection *nc, const SharedMemory* sharedData, struct http_message *hm) { std::string responseJson = sharedMemoryRenderer.render(sharedData, getQueryString(hm)); std::string response; bool gzipResponse = shouldGzipResponse(hm, responseJson.size()); if (gzipResponse) { response = Utils::gzipString(responseJson); }else{ response = responseJson; } // build HTTP OK response with JSON response body ns_printf(nc, "HTTP/1.1 200 OK\r\n" "Content-Type: application/json\r\n" "Cache-Control: no-cache\r\n" "Access-Control-Allow-Origin: *\r\n"); if (gzipResponse) { ns_printf(nc, "Content-Encoding: gzip\r\n"); } ns_printf(nc, "Content-Length: %d\r\n\r\n", (int)response.size()); ns_send(nc, response.data(), response.size()); }
foreign_t pl_get_query_string(term_t t) { char* buf=(char*)malloc(sizeof(char)*100); getQueryString(t,buf); printf("\n"); PL_succeed; }
int setCgiEnv(char *message) { char msg[MESSAGE_MAX_LEN]; memcpy(msg, message, MESSAGE_MAX_LEN); setenv("REQUEST_METHOD", getMethod(msg), 1); setenv("CONTENT_LENGTH", getContentLength(msg), 1); setenv("QUERY_STRING", getQueryString(msg), 1); return 0; }
////////////////////////////////////////////////////////////////////////////// // WMIReferenceProvider::getReferenceQueryString - calls the BaseProvider method // to build the query string from the input parameters // // /////////////////////////////////////////////////////////////////////////// String WMIReferenceProvider::getReferenceQueryString( const CIMObjectPath &objectName, const String &resultClass, const String &role) { String sQuery; sQuery = qString(Q_REFERENCES); return getQueryString(objectName, sQuery, String::EMPTY, resultClass, role); }
////////////////////////////////////////////////////////////////////////////// // WMIAssociatorProvider::getAssocQueryString - calls the BaseProvider method // to build the query string from the input parameters // // /////////////////////////////////////////////////////////////////////////// String WMIAssociatorProvider::getAssocQueryString( const CIMObjectPath &objectName, const String &assocClass, const String &resultClass, const String &role, const String &resultRole) { String sQuery; sQuery = qString(Q_ASSOCIATORS); return getQueryString(objectName, sQuery, assocClass, resultClass, role, resultRole); }
String getProductVersion() { String productVersion; String binaryPath = getBinaryLocation(); DWORD dwSize = GetFileVersionInfoSize(binaryPath.c_str(), NULL); if (dwSize) { std::vector<BYTE> versionInfo(dwSize); BOOL status = GetFileVersionInfo(binaryPath.c_str(), NULL, dwSize, &versionInfo[0]); if (status) { productVersion = getQueryString(&versionInfo[0], "ProductVersion"); } } if (productVersion.empty()) { return "unknown"; } else { return productVersion; } }
/* If there is a HTTP_SWITCHES argument in the query string, examine that instead of the original argv */ static int getArgv(int *pargc, char ***pargv, int originalArgc, char **originalArgv) { char *switches, *next, sbuf[1024]; int i; *pargc = 0; if (getQueryString(&queryBuf, &queryLen) < 0) { return -1; } numQueryKeys = getVars(&queryKeys, queryBuf, queryLen); switches = 0; for (i = 0; i < numQueryKeys; i += 2) { if (strcmp(queryKeys[i], "HTTP_SWITCHES") == 0) { switches = queryKeys[i+1]; break; } } if (switches == 0) { switches = getenv("HTTP_SWITCHES"); } if (switches) { strncpy(sbuf, switches, sizeof(sbuf) - 1); descape(sbuf); next = strtok(sbuf, " \t\n"); i = 1; for (i = 1; next && i < (MAX_ARGV - 1); i++) { argvList[i] = next; next = strtok(0, " \t\n"); } argvList[0] = originalArgv[0]; *pargv = argvList; *pargc = i; } else { *pargc = originalArgc; *pargv = originalArgv; } return 0; }
foreign_t pl_dictionary_unify(term_t QueryCharList,control_t handle) { trieQuery* ctxt; char* queryString; // assuming that no word is longer than 100 chars const char* queryResult; switch(PL_foreign_control(handle)) { case PL_FIRST_CALL: queryString = (char*)malloc(sizeof(char)*1000); getQueryString(QueryCharList,queryString); init_new_dictionary_query(ctxt,queryString); free(queryString); if(!ctxt || !ctxt->next_match(queryResult)) { if(ctxt) clean_up_dictionary_query(ctxt); PL_fail; } else { PL_unify_list_chars(QueryCharList,queryResult); PL_retry_address(ctxt); } case PL_REDO: ctxt=(trieQuery*)PL_foreign_context_address(handle); if(!ctxt->next_match(queryResult)) { clean_up_dictionary_query(ctxt); PL_fail; } else { PL_unify_list_chars(QueryCharList,queryResult); PL_retry_address(ctxt); } case PL_CUTTED: ctxt==(trieQuery*)PL_foreign_context_address(handle); clean_up_dictionary_query(ctxt); PL_succeed; } }
foreign_t pl_dictionary_unify(term_t QueryCharList,control_t handle) { trieQuery* ctxt; char queryString[100]; // assuming that no word is longer than 100 chars char* queryResult; switch(PL_foreign_control(handle)) { case PL_FIRST_CALL: getQueryString(QueryCharList,queryString); init_new_dictionary_query(ctxt,queryString); if(!ctxt->next(queryResult)) { clean_up_dictionary_query(ctxt); PL_fail; } else { PL_unify_list_chars(QueryCharList,queryResult); PL_retry_address(ctxt); } case PL_REDO: ctxt=PL_foreign_context_address(handle); if(!ctxt->next(queryResult)) { clean_up_dictionary_query(ctxt); PL_fail; } else { PL_unify_list_chars(QueryCharList,queryResult); PL_retry_address(ctxt); } case PL_CUTTED: ctxt=PL_foreign_context_address(handle); clean_up_dictionary_query(ctxt); PL_succeed; } }
void parseURL(Request *req) { char *url; if (req->uri == NULL) { return; } if ((url = malloc((strlen(req->uri) + 1) * sizeof(char))) == NULL) { perror("malloc"); return; } strncpy(url, req->uri, strlen(req->uri) + 1); req->fragment = getFragment(url); req->queryString = getQueryString(url); req->path = getPath(url); req->filename = getFilename(req->path); free(url); }