2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * CGI GET/POST parameter parsing
24 #include "util/CGIParser.h"
26 #include <xmltooling/XMLToolingConfig.h>
27 #include <xmltooling/util/URLEncoder.h>
29 using namespace shibsp;
30 using namespace xmltooling;
34 CGIParser::CGIParser(const HTTPRequest& request)
37 if (!strcmp(request.getMethod(),"POST"))
38 pch=request.getRequestBody();
40 pch=request.getQueryString();
41 size_t cl=pch ? strlen(pch) : 0;
43 const URLEncoder* dec = XMLToolingConfig::getConfig().getURLEncoder();
47 value=fmakeword('&',&cl,&pch);
50 name=makeword(value,'=');
51 kvp_map.insert(pair<const string,char*>(name,value));
56 CGIParser::~CGIParser()
58 for (multimap<string,char*>::iterator i=kvp_map.begin(); i!=kvp_map.end(); i++)
62 pair<CGIParser::walker,CGIParser::walker> CGIParser::getParameters(const char* name) const
64 return kvp_map.equal_range(name);
67 /* Parsing routines modified from NCSA source. */
68 char* CGIParser::makeword(char *line, char stop)
71 char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
73 for(x=0;((line[x]) && (line[x] != stop));x++)
82 line[y++] = line[x++];
87 char* CGIParser::fmakeword(char stop, size_t *cl, const char** ppch)
95 word = (char *) malloc(sizeof(char) * (wsize + 1));
99 word[ll] = *((*ppch)++);
104 word = (char *)realloc(word,sizeof(char)*(wsize+1));
107 if((word[ll] == stop) || word[ll] == EOF || (!(*cl)))
118 void CGIParser::plustospace(char *str)
123 if(str[x] == '+') str[x] = ' ';