/* * get_range_query * Parses the GET|POST request and extracts the 'range query' * string. * Args: * - FCGX_Request * (of the thread) * - char * (location where the 'range query' is written) * Returns: * - O (expand) * - 1 (list) */ static int get_range_query(FCGX_Request *rq, char *query) { char *method = FCGX_GetParam("REQUEST_METHOD", rq->envp); char *script_name = FCGX_GetParam("SCRIPT_NAME", rq->envp); int list = -1; /* list or expand? */ char *decoded_url; /* accept only GET && POST */ if(strcmp(method, "GET") != 0 && strcmp(method, "POST") != 0) { invalid_request(rq, "401", "Only GET || POST Request_Method Allowed"); } else if (strcmp(method, "GET") == 0) { decoded_url = curl_unescape(FCGX_GetParam("QUERY_STRING", rq->envp), 0); strcpy(query, decoded_url); curl_free(decoded_url); } else if (strcmp(method, "POST") == 0) { /* TODO: i might have to loop this in while and do a strcat + realloc if i need to increase string length at runtime */ FCGX_GetStr(query, QUERY_STR_SIZE, rq->in); } /* we have two cases here * - /range/list?(.*) * - /range/expand?(.*) * SCRIPT_NAME == /range/list || /range/expand * QUERY_STRING == (.*) (in our case query has it) * strtok() for SCRIPT_NAME and decide which kind it is, * for QUERY_STRING is passed as is. */ if (strlen(query) == 0) { invalid_request(rq, "402", "No Query String Found"); return 0; } /* list ? */ list = strcmp(script_name, "/range/list") == 0 ? 1 : -1; /* if not list, but is expand */ if (list != 1 && strcmp(script_name, "/range/expand") == 0) list = 0; /* neither list nor expand */ if (list == -1) { invalid_request(rq, "403", "Expects /range/list?... or /range/expand?..."); return 0; } /* FCGX_FPrintF(rq->out, "Content-type: text/plain\r\n" "foo: bar\r\n" "\r\n"); FCGX_FPrintF(rq->out, "List (%d) Query: (%s) Script: (%s)\n", list, query, script_name); */ return list; }
DBServer::endpoint_fn DBServer::identify_endpoint(const msgpack::object& request) { RequestData data(request.as<RequestData>()); msgpack::object endpoint_name; try { endpoint_name = data.at("endpoint"); } catch (std::out_of_range& e) { throw invalid_request("Missing endpoint name"); } if (endpoint_name.type != msgpack::type::STR) throw invalid_request("Invalid endpoint name"); DBServer::endpoint_fn endpoint; std::string name(endpoint_name.via.str.ptr, endpoint_name.via.str.size); try { endpoint = endpoints_[name]; } catch (std::out_of_range& e) { throw invalid_request("Unknown endpoint specified"); } return endpoint; }
void loadCommonFields(soap_in_t* req) { if(req == NULL) { throw invalid_request("Received NULL request parameter"); } if(req->requestToken == NULL) { throw invalid_request("FileStatusRequest has NULLrequestToken"); } // Validate request token if (!storm::token::valid(std::string(req->requestToken))){ throw invalid_request("invalid token"); } m_requestToken = sql_string(req->requestToken); if(req->authorizationID != NULL) { m_authorizationID = sql_string(req->authorizationID); } }