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 "SAMLConfig.h"
25 #include "binding/URLEncoder.h"
26 #include "util/CGIParser.h"
28 using namespace opensaml;
32 CGIParser::CGIParser(const HTTPRequest& request)
35 if (!strcmp(request.getMethod(),"POST"))
36 pch=request.getRequestBody();
38 pch=request.getQueryString();
39 size_t cl=pch ? strlen(pch) : 0;
41 URLEncoder* dec = SAMLConfig::getConfig().getURLEncoder();
45 value=fmakeword('&',&cl,&pch);
48 name=makeword(value,'=');
49 kvp_map.insert(pair<string,char*>(name,value));
54 CGIParser::~CGIParser()
56 for (multimap<string,char*>::iterator i=kvp_map.begin(); i!=kvp_map.end(); i++)
60 pair<CGIParser::walker,CGIParser::walker> CGIParser::getParameters(const char* name) const
62 return kvp_map.equal_range(name);
65 /* Parsing routines modified from NCSA source. */
66 char* CGIParser::makeword(char *line, char stop)
69 char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
71 for(x=0;((line[x]) && (line[x] != stop));x++)
80 line[y++] = line[x++];
85 char* CGIParser::fmakeword(char stop, size_t *cl, const char** ppch)
93 word = (char *) malloc(sizeof(char) * (wsize + 1));
97 word[ll] = *((*ppch)++);
102 word = (char *)realloc(word,sizeof(char)*(wsize+1));
105 if((word[ll] == stop) || word[ll] == EOF || (!(*cl)))
116 void CGIParser::plustospace(char *str)
121 if(str[x] == '+') str[x] = ' ';