1 karl 1.22 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.12 //
|
3 karl 1.22 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.12 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.16 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.16 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.12 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.12 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Brasher (mbrasher@bmc.com)
27 //
28 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
|
32 sage 1.18 #include <Pegasus/Common/Config.h>
|
33 kumpf 1.19
34 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
35 sage 1.18 #include <unistd.h>
|
36 kumpf 1.19 #endif
37
|
38 mike 1.12 #include <cstdio>
39 #include <cstdlib>
40 #include "CGIQueryString.h"
41
|
42 karl 1.13 PEGASUS_USING_STD;
43
|
44 mike 1.12 PEGASUS_NAMESPACE_BEGIN
45
46 ////////////////////////////////////////////////////////////////////////////////
47 //
48 // CGIQueryString:
49 // This file provides the methods for the CIGQuery String class that
50 // parse a CGI query string of the following form:
51 //
52 // NameSpace=root%2Fcimv2&ClassName=&LocalOnly=true
53 //
54 ////////////////////////////////////////////////////////////////////////////////
55
56 static void _ExpandCGIQueryValue(char* value)
57 {
58 // Look for '%' characters followed by hex codes:
59
60 for (char* p = value; *p; p++)
61 {
62 if (*p == '%')
63 {
64 char hexString[3];
65 mike 1.12 sprintf(hexString, "%*.*s", 2, 2, p + 1);
66 char* end = 0;
67 long tmp = strtol(hexString, &end, 16);
68
69 if (*end)
70 throw BadlyFormedCGIQueryString();
71
|
72 sage 1.14 *p = char(tmp);
|
73 kumpf 1.17 #ifdef PEGASUS_HAVE_EBCDIC
|
74 sage 1.14 __atoe_l(p,1);
|
75 kumpf 1.17 #endif
|
76 sage 1.14 p++;
|
77 mike 1.12 memcpy(p, p + 2, strlen(p) - 2 + 1);
|
78 karl 1.13 // CORRECTION, KS. Add decrement. corrects problem with succesive
79 // % sequences
80 p--;
81
|
82 mike 1.12 }
83 else if (*p == '+')
84 *p = ' ';
85 }
86 }
87
88 void CGIQueryString::_ParseCGIQueryString(
89 char* queryString,
90 Array<CGIQueryStringEntry>& entries)
91 {
92 // First split about the '&' characters:
93
|
94 kumpf 1.21 #if defined(PEGASUS_OS_SOLARIS) || \
95 defined(PEGASUS_OS_HPUX) || \
96 defined(PEGASUS_OS_LINUX)
97 char *last;
|
98 keith.petley 1.20 for (char* p = strtok_r(queryString, "&", &last); p;
|
99 kumpf 1.21 p = strtok_r(NULL, "&", &last))
|
100 keith.petley 1.20 #else
|
101 mike 1.12 for (char* p = strtok(queryString, "&"); p; p = strtok(NULL, "&"))
|
102 keith.petley 1.20 #endif
|
103 mike 1.12 {
104 char* name = p;
105
106 // Find equal sign:
107 char* equalChar = strchr(p, '=');
108
109 if (!equalChar)
110 throw BadlyFormedCGIQueryString();
111
112 *equalChar++ = '\0';
113
114 char* value = equalChar;
115
116 _ExpandCGIQueryValue(value);
117
118 // cout << "name=[" << name << "]" << endl;
119 // cout << "value=[" << value << "]" << endl;
120
121 CGIQueryStringEntry entry = { name, value };
122 entries.append(entry);
123 }
124 mike 1.12 }
125
126 CGIQueryString::CGIQueryString(char* queryString)
127 {
128 _ParseCGIQueryString(queryString, _entries);
129 }
130
131 const char* CGIQueryString::findValue(const char* name) const
132 {
133 for (Uint32 i = 0, n = _entries.size(); i < n; i++)
134 {
135 if (strcmp(_entries[i].name, name) == 0)
136 return _entries[i].value;
137 }
138
139 return 0;
140 }
141
142 PEGASUS_NAMESPACE_END
|