(file) Return to WsmUtils.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WsmServer

  1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.4 //
  3 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.4 //
 10 martin 1.3 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.4 //
 17 martin 1.3 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.4 //
 20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.3 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.4 //
 28 martin 1.3 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.2 //
 30            //%////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <Pegasus/Common/String.h>
 33 rohini.deshpande 1.6 #include <Pegasus/Common/StringConversion.h>
 34 kumpf            1.2 #include <Pegasus/Common/PegasusAssert.h>
 35                      #include "WsmUtils.h"
 36 mike             1.5 #include "WsmConstants.h"
 37 kumpf            1.2 
 38                      PEGASUS_NAMESPACE_BEGIN
 39                      
 40                      XmlNamespace WsmNamespaces::supportedNamespaces[] =
 41                      {
 42                          {
 43                              "SOAP-ENV",
 44                              "http://www.w3.org/2003/05/soap-envelope",
 45                              SOAP_ENVELOPE,
 46                              0
 47                          },
 48                          {
 49                              "SOAP-ENC",
 50                              "http://www.w3.org/2003/05/soap-encoding",
 51                              SOAP_ENCODING,
 52                              0
 53                          },
 54                          {
 55                              "xml",
 56                              "http://www.w3.org/XML/1998/namespace",
 57                              XML_NAMESPACE,
 58 kumpf            1.2         0
 59                          },
 60                          {
 61                              "xsi",
 62                              "http://www.w3.org/2001/XMLSchema-instance",
 63                              XML_SCHEMA_INSTANCE,
 64                              0
 65                          },
 66                          {
 67                              "xsd",
 68                              "http://www.w3.org/2001/XMLSchema",
 69                              XML_SCHEMA,
 70                              0
 71                          },
 72                          {
 73                              "wsman",
 74                              "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd",
 75                              WS_MAN,
 76                              0
 77                          },
 78                          {
 79 kumpf            1.2         "wsmb",
 80                              "http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd",
 81                              WS_CIM_BINDING,
 82                              0
 83                          },
 84                          {
 85                              "wsa",
 86                              "http://schemas.xmlsoap.org/ws/2004/08/addressing",
 87                              WS_ADDRESSING,
 88                              0
 89                          },
 90                          {
 91                              "wxf",
 92                              "http://schemas.xmlsoap.org/ws/2004/09/transfer",
 93                              WS_TRANSFER,
 94                              0
 95                          },
 96                          {
 97                              "wsen",
 98                              "http://schemas.xmlsoap.org/ws/2004/09/enumeration",
 99                              WS_ENUMERATION,
100 kumpf            1.2         0
101                          },
102                          {
103                              "wse",
104                              "http://schemas.xmlsoap.org/ws/2004/08/eventing",
105                              WS_EVENTING,
106                              0
107                          },
108                          {
109                              "wsp",
110                              "http://schemas.xmlsoap.org/ws/2004/09/policy",
111                              WS_POLICY,
112                              0
113                          },
114                          {
115                              "wsdl",
116                              "http://schemas.xmlsoap.org/wsdl",
117                              WSDL,
118                              0
119                          },
120                          {
121 kumpf            1.2         "wscim",
122                              "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2",
123                              WS_CIM_SCHEMA,
124                              0
125                          },
126                          {0, 0, LAST, 0}
127                      };
128                      
129                      
130                      String WsmUtils::getMessageId()
131                      {
132                          // DSP0226 R5.4.4-1: The MessageID and RelatesTo URIs may be of any format,
133                          // as long as they are valid URIs according to RFC 3986.  Two URIs are
134                          // considered different even if the characters in the URIs differ only by
135                          // case.
136                          //
137                          // The following two formats are endorsed by this specification.  The first
138                          // is considered a best practice because it is backed by IETF RFC 4122:
139                          //     urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
140                          //     or
141                          //     uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
142 kumpf            1.2     //
143                          // In these formats, each x is an uppercase or lowercase hexadecimal digit
144                          // (lowercase is required by RFC 4122); there are no spaces or other
145                          // tokens.  The value may be a DCE-style universally unique identifier
146                          // (UUID) with provable uniqueness properties in this format, however, it
147                          // is not necessary to have provable uniqueness properties in the URIs
148                          // used in the wsa:MessageID and wsa:RelatesTo headers.
149                          //
150                          // Regardless of format, the URI should not exceed the maximum defined in
151                          // R13.1-6. [sic]
152                      
153                          // DSP0226 R5.4.4-2: The MessageID should be generated according to any
154                          // algorithm that ensures that no two MessageIDs are repeated.  Because
155                          // the value is treated as case-sensitive (R5.4.4-1), confusion can arise
156                          // if the same value is reused differing only in case.  As a result, the
157                          // service shall not create or employ MessageID values that differ only in
158                          // case.  For any message transmitted by the service, the MessageID shall
159                          // not be reused.
160                      
161                          // Note: This algorithm could be improved, but provable uniqueness is not
162                          // required (see above).
163 kumpf            1.2 
164                          char uuid[42];
165                          sprintf(uuid, "uuid:%08X-%04X-%04X-%04X-%08X%04X",
166                              rand(),
167                              rand() & 0xFFFF,
168                              rand() & 0xFFFF,
169                              rand() & 0xFFFF,
170                              rand(),
171                              rand() & 0xFFFF);
172                          return String(uuid, 41);
173                      }
174                      
175 mike             1.5 const char* WsmUtils::skipHostUri(const char* uri)
176                      {
177                          const char* p = uri;
178                      
179                          // Skip over "http://" part:
180                      
181                          if (p[0] != 'h')
182                              return &p[0];
183                          if (p[1] != 't')
184                              return &p[1];
185                          if (p[2] != 't')
186                              return &p[2];
187                          if (p[3] != 'p')
188                              return &p[3];
189                          if (p[4] != ':')
190                              return &p[4];
191                          if (p[5] != '/')
192                              return &p[5];
193                          if (p[6] != '/')
194                              return &p[6];
195                      
196 mike             1.5     p += 7;
197                      
198                          // Return the first character that is not a '/' (or return pointer to
199                          // zero terminator).
200                      
201                          while (*p && *p != '/')
202                              p++;
203                      
204                          return p;
205                      }
206                      
207                      String WsmUtils::getRootResourceUri(const String& resourceUri)
208                      {
209                          CString cstr(resourceUri.getCString());
210                          const char* start = cstr;
211                          const char* end = skipHostUri(start);
212                          const size_t n = sizeof(WSM_RESOURCEURI_CIMSCHEMAV2_SUFFIX) - 1;
213                      
214                          if (strncmp(end, WSM_RESOURCEURI_CIMSCHEMAV2_SUFFIX, n) == 0)
215                          {
216                              end += n;
217 mike             1.5         return String(start, end - start);
218                          }
219                      
220                          const int NS = WsmNamespaces::WS_CIM_SCHEMA;
221                          return String(WsmNamespaces::supportedNamespaces[NS].extendedName);
222                      }
223                      
224 rohini.deshpande 1.6 String WsmUtils::toMicroSecondString(const CIMDateTime &rep)
225                      {
226                          const Uint32 strDurationLength=26;
227                          Uint64 duration = rep.toMicroSeconds();
228                          Uint32 outputLength = 0;
229                          char buffer[strDurationLength];
230                          const char* output = Uint64ToString(buffer, duration, outputLength); 
231                          return String(output, outputLength);
232                      }
233                      
234 kumpf            1.2 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2