[621] | 1 | /* |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2015 GeoLabs SARL |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "request_parser.h" |
---|
| 26 | #include "service_internal.h" |
---|
[640] | 27 | #include "server_internal.h" |
---|
| 28 | #include "response_print.h" |
---|
| 29 | #include "caching.h" |
---|
[621] | 30 | |
---|
| 31 | /** |
---|
| 32 | * Apply XPath Expression on XML document. |
---|
| 33 | * |
---|
| 34 | * @param doc the XML Document |
---|
| 35 | * @param search the XPath expression |
---|
| 36 | * @return xmlXPathObjectPtr containing the resulting nodes set |
---|
| 37 | */ |
---|
| 38 | xmlXPathObjectPtr |
---|
| 39 | extractFromDoc (xmlDocPtr doc, const char *search) |
---|
| 40 | { |
---|
| 41 | xmlXPathContextPtr xpathCtx; |
---|
| 42 | xmlXPathObjectPtr xpathObj; |
---|
| 43 | xpathCtx = xmlXPathNewContext (doc); |
---|
| 44 | xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx); |
---|
| 45 | xmlXPathFreeContext (xpathCtx); |
---|
| 46 | return xpathObj; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * Create (or append to) an array valued maps value = "["",""]" |
---|
| 51 | * |
---|
| 52 | * @param m the conf maps containing the main.cfg settings |
---|
| 53 | * @param mo the map to update |
---|
| 54 | * @param mi the map to append |
---|
| 55 | * @param elem the elements containing default definitions |
---|
| 56 | * @return 0 on success, -1 on failure |
---|
| 57 | */ |
---|
| 58 | int appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem){ |
---|
| 59 | maps *tmpMaps = getMaps (mo, mi->name); |
---|
| 60 | map *tmap = getMapType (tmpMaps->content); |
---|
| 61 | elements *el = getElements (elem, mi->name); |
---|
[790] | 62 | elements *cursor = elem; |
---|
| 63 | while(cursor!=NULL && el==NULL){ |
---|
| 64 | if(cursor->child!=NULL) |
---|
| 65 | el = getElements (cursor->child, mi->name); |
---|
| 66 | cursor=cursor->next; |
---|
| 67 | } |
---|
[621] | 68 | int hasEl = 1; |
---|
| 69 | if (el == NULL) |
---|
| 70 | hasEl = -1; |
---|
[790] | 71 | |
---|
[621] | 72 | if (tmap == NULL) |
---|
| 73 | { |
---|
| 74 | if (hasEl > 0) |
---|
| 75 | tmap = getMapType (el->defaults->content); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | map *testMap = NULL; |
---|
| 79 | if (hasEl > 0) |
---|
| 80 | { |
---|
| 81 | testMap = getMap (el->content, "maxOccurs"); |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | testMap = createMap ("maxOccurs", "unbounded"); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if (testMap != NULL) |
---|
| 89 | { |
---|
| 90 | if (strncasecmp (testMap->value, "unbounded", 9) != 0 |
---|
| 91 | && atoi (testMap->value) > 1) |
---|
| 92 | { |
---|
| 93 | addMapsArrayToMaps (&mo, mi, tmap->name); |
---|
| 94 | map* nb=getMapFromMaps(mo,mi->name,"length"); |
---|
| 95 | if (nb!=NULL && atoi(nb->value)>atoi(testMap->value)) |
---|
| 96 | { |
---|
| 97 | char emsg[1024]; |
---|
| 98 | sprintf (emsg, |
---|
| 99 | _("The maximum allowed occurrences for <%s> (%i) was exceeded."), |
---|
| 100 | mi->name, atoi (testMap->value)); |
---|
| 101 | errorException (m, emsg, "InternalError", NULL); |
---|
| 102 | return -1; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | else |
---|
| 106 | { |
---|
| 107 | if (strncasecmp (testMap->value, "unbounded", 9) == 0) |
---|
| 108 | { |
---|
| 109 | if (hasEl < 0) |
---|
| 110 | { |
---|
| 111 | freeMap (&testMap); |
---|
| 112 | free (testMap); |
---|
| 113 | } |
---|
| 114 | if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0) |
---|
| 115 | { |
---|
| 116 | char emsg[1024]; |
---|
| 117 | map *tmpMap = getMap (mi->content, "length"); |
---|
| 118 | sprintf (emsg, |
---|
| 119 | _ |
---|
| 120 | ("ZOO-Kernel was unable to load your data for %s position %s."), |
---|
| 121 | mi->name, tmpMap->value); |
---|
| 122 | errorException (m, emsg, "InternalError", NULL); |
---|
| 123 | return -1; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
| 128 | char emsg[1024]; |
---|
| 129 | sprintf (emsg, |
---|
| 130 | _ |
---|
| 131 | ("The maximum allowed occurrences for <%s> is one."), |
---|
| 132 | mi->name); |
---|
| 133 | errorException (m, emsg, "InternalError", NULL); |
---|
| 134 | return -1; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | return 0; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
[640] | 142 | * Make sure that each value encoded in base64 in a maps is decoded. |
---|
| 143 | * |
---|
| 144 | * @param in the maps containing the values |
---|
| 145 | * @see readBase64 |
---|
| 146 | */ |
---|
| 147 | void ensureDecodedBase64(maps **in){ |
---|
| 148 | maps* cursor=*in; |
---|
| 149 | while(cursor!=NULL){ |
---|
| 150 | map *tmp=getMap(cursor->content,"encoding"); |
---|
| 151 | if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ |
---|
| 152 | tmp=getMap(cursor->content,"value"); |
---|
| 153 | readBase64(&tmp); |
---|
| 154 | addToMap(cursor->content,"base64_value",tmp->value); |
---|
| 155 | int size=0; |
---|
| 156 | char *s=strdup(tmp->value); |
---|
| 157 | free(tmp->value); |
---|
| 158 | tmp->value=base64d(s,strlen(s),&size); |
---|
| 159 | free(s); |
---|
| 160 | char sizes[1024]; |
---|
| 161 | sprintf(sizes,"%d",size); |
---|
| 162 | addToMap(cursor->content,"size",sizes); |
---|
| 163 | } |
---|
| 164 | map* length=getMap(cursor->content,"length"); |
---|
| 165 | if(length!=NULL){ |
---|
| 166 | int len=atoi(length->value); |
---|
| 167 | for(int i=1;i<len;i++){ |
---|
| 168 | tmp=getMapArray(cursor->content,"encoding",i); |
---|
| 169 | if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ |
---|
| 170 | char key[17]; |
---|
| 171 | sprintf(key,"base64_value_%d",i); |
---|
| 172 | tmp=getMapArray(cursor->content,"value",i); |
---|
| 173 | readBase64(&tmp); |
---|
| 174 | addToMap(cursor->content,key,tmp->value); |
---|
| 175 | int size=0; |
---|
| 176 | char *s=strdup(tmp->value); |
---|
| 177 | free(tmp->value); |
---|
| 178 | tmp->value=base64d(s,strlen(s),&size); |
---|
| 179 | free(s); |
---|
| 180 | char sizes[1024]; |
---|
| 181 | sprintf(sizes,"%d",size); |
---|
| 182 | sprintf(key,"size_%d",i); |
---|
| 183 | addToMap(cursor->content,key,sizes); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | } |
---|
[790] | 187 | if(cursor->child!=NULL) |
---|
| 188 | ensureDecodedBase64(&cursor->child); |
---|
[640] | 189 | cursor=cursor->next; |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /** |
---|
[621] | 194 | * Parse inputs provided as KVP and store them in a maps. |
---|
| 195 | * |
---|
| 196 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 197 | * @param s the service |
---|
| 198 | * @param request_inputs the map storing KVP raw value |
---|
| 199 | * @param request_output the maps to store the KVP pairs |
---|
| 200 | * @param hInternet the HINTERNET queue to add potential requests |
---|
| 201 | * @return 0 on success, -1 on failure |
---|
| 202 | */ |
---|
| 203 | int kvpParseInputs(maps** main_conf,service* s,map *request_inputs,maps** request_output,HINTERNET* hInternet){ |
---|
| 204 | // Parsing inputs provided as KVP |
---|
| 205 | maps *tmpmaps = *request_output; |
---|
| 206 | map* r_inputs = getMap (request_inputs, "DataInputs"); |
---|
| 207 | char* cursor_input; |
---|
| 208 | if (r_inputs != NULL){ |
---|
| 209 | //snprintf (cursor_input, 40960, "%s", r_inputs->value); |
---|
[625] | 210 | if(strstr(r_inputs->value,"=")==NULL) |
---|
| 211 | cursor_input = url_decode (r_inputs->value); |
---|
| 212 | else |
---|
| 213 | cursor_input = zStrdup (r_inputs->value); |
---|
[621] | 214 | int j = 0; |
---|
| 215 | |
---|
| 216 | // Put each DataInputs into the inputs_as_text array |
---|
| 217 | char *pToken; |
---|
| 218 | pToken = strtok (cursor_input, ";"); |
---|
| 219 | char **inputs_as_text = (char **) malloc (100 * sizeof (char *)); |
---|
| 220 | if (inputs_as_text == NULL) |
---|
| 221 | { |
---|
[626] | 222 | free(cursor_input); |
---|
[725] | 223 | return errorException (*main_conf, _("Unable to allocate memory"), |
---|
[621] | 224 | "InternalError", NULL); |
---|
| 225 | } |
---|
| 226 | int i = 0; |
---|
| 227 | while (pToken != NULL) |
---|
| 228 | { |
---|
| 229 | inputs_as_text[i] = |
---|
| 230 | (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); |
---|
| 231 | if (inputs_as_text[i] == NULL) |
---|
| 232 | { |
---|
[626] | 233 | free(cursor_input); |
---|
[725] | 234 | return errorException (*main_conf, _("Unable to allocate memory"), |
---|
[621] | 235 | "InternalError", NULL); |
---|
| 236 | } |
---|
| 237 | snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken); |
---|
| 238 | pToken = strtok (NULL, ";"); |
---|
| 239 | i++; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | for (j = 0; j < i; j++) |
---|
| 243 | { |
---|
| 244 | char *tmp = zStrdup (inputs_as_text[j]); |
---|
| 245 | free (inputs_as_text[j]); |
---|
| 246 | char *tmpc; |
---|
| 247 | tmpc = strtok (tmp, "@"); |
---|
| 248 | while (tmpc != NULL) |
---|
| 249 | { |
---|
| 250 | char *tmpv = strstr (tmpc, "="); |
---|
| 251 | char tmpn[256]; |
---|
| 252 | memset (tmpn, 0, 256); |
---|
| 253 | if (tmpv != NULL) |
---|
| 254 | { |
---|
| 255 | strncpy (tmpn, tmpc, |
---|
| 256 | (strlen (tmpc) - strlen (tmpv)) * sizeof (char)); |
---|
| 257 | tmpn[strlen (tmpc) - strlen (tmpv)] = 0; |
---|
| 258 | } |
---|
| 259 | else |
---|
| 260 | { |
---|
| 261 | strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char)); |
---|
| 262 | tmpn[strlen (tmpc)] = 0; |
---|
| 263 | } |
---|
| 264 | if (tmpmaps == NULL) |
---|
| 265 | { |
---|
[790] | 266 | tmpmaps = createMaps(tmpn); |
---|
[621] | 267 | if (tmpmaps == NULL) |
---|
| 268 | { |
---|
[626] | 269 | free(cursor_input); |
---|
[621] | 270 | return errorException (*main_conf, |
---|
[725] | 271 | _("Unable to allocate memory"), |
---|
[621] | 272 | "InternalError", NULL); |
---|
| 273 | } |
---|
| 274 | if (tmpv != NULL) |
---|
| 275 | { |
---|
| 276 | char *tmpvf = url_decode (tmpv + 1); |
---|
| 277 | tmpmaps->content = createMap ("value", tmpvf); |
---|
| 278 | free (tmpvf); |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | tmpmaps->content = createMap ("value", "Reference"); |
---|
| 282 | tmpmaps->next = NULL; |
---|
| 283 | } |
---|
| 284 | tmpc = strtok (NULL, "@"); |
---|
| 285 | while (tmpc != NULL) |
---|
| 286 | { |
---|
| 287 | char *tmpv1 = strstr (tmpc, "="); |
---|
| 288 | char tmpn1[1024]; |
---|
| 289 | memset (tmpn1, 0, 1024); |
---|
| 290 | if (tmpv1 != NULL) |
---|
| 291 | { |
---|
| 292 | strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1)); |
---|
| 293 | tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0; |
---|
| 294 | addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | strncpy (tmpn1, tmpc, strlen (tmpc)); |
---|
| 299 | tmpn1[strlen (tmpc)] = 0; |
---|
| 300 | map *lmap = getLastMap (tmpmaps->content); |
---|
| 301 | char *tmpValue = |
---|
| 302 | (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) * |
---|
| 303 | sizeof (char)); |
---|
| 304 | sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc); |
---|
| 305 | free (lmap->value); |
---|
| 306 | lmap->value = zStrdup (tmpValue); |
---|
| 307 | free (tmpValue); |
---|
| 308 | tmpc = strtok (NULL, "@"); |
---|
| 309 | continue; |
---|
| 310 | } |
---|
| 311 | if (strcmp (tmpn1, "xlink:href") != 0) |
---|
| 312 | addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); |
---|
| 313 | else if (tmpv1 != NULL) |
---|
| 314 | { |
---|
| 315 | char *tmpx2 = url_decode (tmpv1 + 1); |
---|
| 316 | if (strncasecmp (tmpx2, "http://", 7) != 0 && |
---|
| 317 | strncasecmp (tmpx2, "ftp://", 6) != 0 && |
---|
| 318 | strncasecmp (tmpx2, "https://", 8) != 0) |
---|
| 319 | { |
---|
| 320 | char emsg[1024]; |
---|
| 321 | sprintf (emsg, |
---|
| 322 | _ |
---|
| 323 | ("Unable to find a valid protocol to download the remote file %s"), |
---|
| 324 | tmpv1 + 1); |
---|
[626] | 325 | free(cursor_input); |
---|
[621] | 326 | return errorException (*main_conf, emsg, "InternalError", NULL); |
---|
| 327 | } |
---|
| 328 | addToMap (tmpmaps->content, tmpn1, tmpx2); |
---|
| 329 | { |
---|
| 330 | if (loadRemoteFile |
---|
| 331 | (&*main_conf, &tmpmaps->content, hInternet, tmpx2) < 0) |
---|
| 332 | { |
---|
[626] | 333 | free(cursor_input); |
---|
[781] | 334 | return errorException (*main_conf, "Unable to fetch any resource", "InternalError", NULL); |
---|
[626] | 335 | } |
---|
[621] | 336 | } |
---|
| 337 | free (tmpx2); |
---|
[627] | 338 | addIntToMap (tmpmaps->content, "Order", hInternet->nb); |
---|
[621] | 339 | addToMap (tmpmaps->content, "Reference", tmpv1 + 1); |
---|
| 340 | } |
---|
| 341 | tmpc = strtok (NULL, "@"); |
---|
| 342 | } |
---|
| 343 | if (*request_output == NULL) |
---|
| 344 | *request_output = dupMaps (&tmpmaps); |
---|
| 345 | else |
---|
| 346 | { |
---|
| 347 | maps *testPresence = |
---|
| 348 | getMaps (*request_output, tmpmaps->name); |
---|
| 349 | if (testPresence != NULL) |
---|
| 350 | { |
---|
| 351 | elements *elem = |
---|
| 352 | getElements (s->inputs, tmpmaps->name); |
---|
| 353 | if (elem != NULL) |
---|
| 354 | { |
---|
| 355 | if (appendMapsToMaps |
---|
| 356 | (*main_conf, *request_output, tmpmaps, |
---|
| 357 | elem) < 0) |
---|
| 358 | { |
---|
[626] | 359 | free(cursor_input); |
---|
[621] | 360 | return errorException (*main_conf, "Unable to append maps", "InternalError", NULL); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | else |
---|
[623] | 365 | addMapsToMaps (request_output, tmpmaps); |
---|
[621] | 366 | } |
---|
| 367 | freeMaps (&tmpmaps); |
---|
| 368 | free (tmpmaps); |
---|
| 369 | tmpmaps = NULL; |
---|
| 370 | free (tmp); |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | free (inputs_as_text); |
---|
[626] | 374 | free(cursor_input); |
---|
[621] | 375 | } |
---|
| 376 | return 1; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | /** |
---|
| 380 | * Parse outputs provided as KVP and store them in a maps. |
---|
| 381 | * |
---|
| 382 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 383 | * @param request_inputs the map storing KVP raw value |
---|
| 384 | * @param request_output the maps to store the KVP pairs |
---|
| 385 | * @return 0 on success, -1 on failure |
---|
| 386 | */ |
---|
| 387 | int kvpParseOutputs(maps** main_conf,map *request_inputs,maps** request_output){ |
---|
| 388 | /** |
---|
| 389 | * Parsing outputs provided as KVP |
---|
| 390 | */ |
---|
| 391 | map *r_inputs = NULL; |
---|
| 392 | r_inputs = getMap (request_inputs, "ResponseDocument"); |
---|
| 393 | if (r_inputs == NULL) |
---|
| 394 | r_inputs = getMap (request_inputs, "RawDataOutput"); |
---|
| 395 | |
---|
| 396 | if (r_inputs != NULL) |
---|
| 397 | { |
---|
| 398 | char *cursor_output = zStrdup (r_inputs->value); |
---|
| 399 | int j = 0; |
---|
| 400 | |
---|
| 401 | /** |
---|
| 402 | * Put each Output into the outputs_as_text array |
---|
| 403 | */ |
---|
| 404 | char *pToken; |
---|
| 405 | maps *tmp_output = NULL; |
---|
| 406 | pToken = strtok (cursor_output, ";"); |
---|
| 407 | char **outputs_as_text = (char **) malloc (128 * sizeof (char *)); |
---|
| 408 | if (outputs_as_text == NULL) |
---|
| 409 | { |
---|
[626] | 410 | free(cursor_output); |
---|
[621] | 411 | return errorException (*main_conf, _("Unable to allocate memory"), |
---|
| 412 | "InternalError", NULL); |
---|
| 413 | } |
---|
| 414 | int i = 0; |
---|
| 415 | while (pToken != NULL) |
---|
| 416 | { |
---|
| 417 | outputs_as_text[i] = |
---|
| 418 | (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); |
---|
| 419 | if (outputs_as_text[i] == NULL) |
---|
| 420 | { |
---|
[626] | 421 | free(cursor_output); |
---|
[621] | 422 | return errorException (*main_conf, _("Unable to allocate memory"), |
---|
| 423 | "InternalError", NULL); |
---|
| 424 | } |
---|
| 425 | snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s", |
---|
| 426 | pToken); |
---|
| 427 | pToken = strtok (NULL, ";"); |
---|
| 428 | i++; |
---|
| 429 | } |
---|
| 430 | for (j = 0; j < i; j++) |
---|
| 431 | { |
---|
| 432 | char *tmp = zStrdup (outputs_as_text[j]); |
---|
| 433 | free (outputs_as_text[j]); |
---|
| 434 | char *tmpc; |
---|
| 435 | tmpc = strtok (tmp, "@"); |
---|
| 436 | int k = 0; |
---|
| 437 | while (tmpc != NULL) |
---|
| 438 | { |
---|
| 439 | if (k == 0) |
---|
| 440 | { |
---|
| 441 | if (tmp_output == NULL) |
---|
| 442 | { |
---|
[790] | 443 | tmp_output = createMaps(tmpc); |
---|
[621] | 444 | if (tmp_output == NULL) |
---|
| 445 | { |
---|
[626] | 446 | free(cursor_output); |
---|
[621] | 447 | return errorException (*main_conf, |
---|
| 448 | _ |
---|
[725] | 449 | ("Unable to allocate memory"), |
---|
[621] | 450 | "InternalError", NULL); |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | { |
---|
| 456 | char *tmpv = strstr (tmpc, "="); |
---|
| 457 | char tmpn[256]; |
---|
| 458 | memset (tmpn, 0, 256); |
---|
| 459 | strncpy (tmpn, tmpc, |
---|
| 460 | (strlen (tmpc) - |
---|
| 461 | strlen (tmpv)) * sizeof (char)); |
---|
| 462 | tmpn[strlen (tmpc) - strlen (tmpv)] = 0; |
---|
| 463 | if (tmp_output->content == NULL) |
---|
| 464 | { |
---|
| 465 | tmp_output->content = createMap (tmpn, tmpv + 1); |
---|
| 466 | tmp_output->content->next = NULL; |
---|
| 467 | } |
---|
| 468 | else |
---|
| 469 | addToMap (tmp_output->content, tmpn, tmpv + 1); |
---|
| 470 | } |
---|
| 471 | k++; |
---|
| 472 | tmpc = strtok (NULL, "@"); |
---|
| 473 | } |
---|
| 474 | if (*request_output == NULL) |
---|
| 475 | *request_output = dupMaps (&tmp_output); |
---|
| 476 | else |
---|
[623] | 477 | addMapsToMaps (request_output, tmp_output); |
---|
[621] | 478 | freeMaps (&tmp_output); |
---|
| 479 | free (tmp_output); |
---|
| 480 | tmp_output = NULL; |
---|
| 481 | free (tmp); |
---|
| 482 | } |
---|
| 483 | free (outputs_as_text); |
---|
[626] | 484 | free(cursor_output); |
---|
[621] | 485 | } |
---|
| 486 | return 1; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | /** |
---|
[745] | 490 | * Create a "missingIdentifier" maps in case it is NULL. |
---|
| 491 | * |
---|
| 492 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 493 | * @param mymaps the maps to update |
---|
| 494 | * @return 0 on success, 4 on failure |
---|
| 495 | */ |
---|
| 496 | int defineMissingIdentifier(maps** main_conf,maps** mymaps){ |
---|
| 497 | if (*mymaps == NULL){ |
---|
[790] | 498 | *mymaps = createMaps("missingIndetifier"); |
---|
[745] | 499 | if (*mymaps == NULL){ |
---|
| 500 | return errorException (*main_conf, |
---|
| 501 | _("Unable to allocate memory"), |
---|
| 502 | "InternalError", NULL); |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | return 0; |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | /** |
---|
[621] | 509 | * Parse inputs from XML nodes and store them in a maps. |
---|
| 510 | * |
---|
| 511 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 512 | * @param s the service |
---|
| 513 | * @param request_output the maps to store the KVP pairs |
---|
| 514 | * @param doc the xmlDocPtr containing the original request |
---|
| 515 | * @param nodes the input nodes array |
---|
| 516 | * @param hInternet the HINTERNET queue to add potential requests |
---|
| 517 | * @return 0 on success, -1 on failure |
---|
| 518 | */ |
---|
| 519 | int xmlParseInputs(maps** main_conf,service* s,maps** request_output,xmlDocPtr doc,xmlNodeSet* nodes,HINTERNET* hInternet){ |
---|
[622] | 520 | int k = 0; |
---|
| 521 | int l = 0; |
---|
[654] | 522 | map* version=getMapFromMaps(*main_conf,"main","rversion"); |
---|
| 523 | int vid=getVersionId(version->value); |
---|
[622] | 524 | for (k=0; k < nodes->nodeNr; k++) |
---|
[621] | 525 | { |
---|
| 526 | maps *tmpmaps = NULL; |
---|
| 527 | xmlNodePtr cur = nodes->nodeTab[k]; |
---|
| 528 | |
---|
| 529 | if (nodes->nodeTab[k]->type == XML_ELEMENT_NODE) |
---|
| 530 | { |
---|
| 531 | // A specific Input node. |
---|
[654] | 532 | if(vid==1){ |
---|
| 533 | xmlChar *val = xmlGetProp (cur, BAD_CAST "id"); |
---|
[790] | 534 | tmpmaps = createMaps((char *) val); |
---|
[654] | 535 | } |
---|
| 536 | |
---|
[621] | 537 | xmlNodePtr cur2 = cur->children; |
---|
| 538 | while (cur2 != NULL) |
---|
| 539 | { |
---|
| 540 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 541 | cur2 = cur2->next; |
---|
| 542 | if (cur2 == NULL) |
---|
| 543 | break; |
---|
| 544 | // Indentifier |
---|
| 545 | if (xmlStrncasecmp |
---|
| 546 | (cur2->name, BAD_CAST "Identifier", |
---|
| 547 | xmlStrlen (cur2->name)) == 0) |
---|
| 548 | { |
---|
| 549 | xmlChar *val = |
---|
| 550 | xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); |
---|
[745] | 551 | if (tmpmaps == NULL && val!=NULL) |
---|
[621] | 552 | { |
---|
[790] | 553 | tmpmaps = createMaps((char*)val); |
---|
[621] | 554 | if (tmpmaps == NULL) |
---|
| 555 | { |
---|
| 556 | return errorException (*main_conf, |
---|
| 557 | _ |
---|
[725] | 558 | ("Unable to allocate memory"), |
---|
[621] | 559 | "InternalError", NULL); |
---|
| 560 | } |
---|
[745] | 561 | xmlFree (val); |
---|
[621] | 562 | } |
---|
| 563 | } |
---|
| 564 | // Title, Asbtract |
---|
| 565 | if (xmlStrncasecmp |
---|
| 566 | (cur2->name, BAD_CAST "Title", |
---|
| 567 | xmlStrlen (cur2->name)) == 0 |
---|
| 568 | || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract", |
---|
| 569 | xmlStrlen (cur2->name)) == 0) |
---|
| 570 | { |
---|
| 571 | xmlChar *val = |
---|
| 572 | xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); |
---|
[745] | 573 | defineMissingIdentifier(main_conf,&tmpmaps); |
---|
| 574 | if(val!=NULL){ |
---|
| 575 | if (tmpmaps->content != NULL) |
---|
| 576 | addToMap (tmpmaps->content, |
---|
| 577 | (char *) cur2->name, (char *) val); |
---|
| 578 | else |
---|
[621] | 579 | tmpmaps->content = |
---|
| 580 | createMap ((char *) cur2->name, (char *) val); |
---|
[745] | 581 | xmlFree (val); |
---|
| 582 | } |
---|
[621] | 583 | } |
---|
[790] | 584 | // InputDataFormChoice (Reference or Data ?) / 2.0.0 DataInputType / Input |
---|
| 585 | if (xmlStrcasecmp (cur2->name, BAD_CAST "Input") == 0) |
---|
[621] | 586 | { |
---|
[790] | 587 | char *xpathExpr=(char*)malloc(61+strlen(tmpmaps->name)); |
---|
| 588 | sprintf(xpathExpr,"/*/*[local-name()='Input' and @id='%s']/*[local-name()='Input']",tmpmaps->name); |
---|
| 589 | xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr); |
---|
| 590 | xmlNodeSet *tmps = tmpsptr->nodesetval; |
---|
| 591 | if(tmps!=NULL){ |
---|
| 592 | maps* request_output1=NULL; |
---|
| 593 | if(xmlParseInputs(main_conf,s,&request_output1,doc,tmps,hInternet)<0) |
---|
| 594 | return -1; |
---|
| 595 | if(tmpmaps->child==NULL) |
---|
| 596 | tmpmaps->child=dupMaps(&request_output1); |
---|
| 597 | else |
---|
| 598 | addMapsToMaps(&tmpmaps->child,request_output1); |
---|
| 599 | freeMaps(&request_output1); |
---|
| 600 | free(request_output1); |
---|
| 601 | } |
---|
| 602 | while(cur2->next!=NULL) |
---|
| 603 | cur2=cur2->next; |
---|
| 604 | } |
---|
| 605 | else if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0) |
---|
| 606 | { |
---|
[745] | 607 | defineMissingIdentifier(main_conf,&tmpmaps); |
---|
[621] | 608 | // Get every attribute from a Reference node |
---|
| 609 | // mimeType, encoding, schema, href, method |
---|
| 610 | // Header and Body gesture should be added here |
---|
| 611 | const char *refs[5] = |
---|
| 612 | { "mimeType", "encoding", "schema", "method", |
---|
| 613 | "href" |
---|
| 614 | }; |
---|
[622] | 615 | for (l = 0; l < 5; l++) |
---|
[621] | 616 | { |
---|
| 617 | xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]); |
---|
| 618 | if (val != NULL && xmlStrlen (val) > 0) |
---|
| 619 | { |
---|
| 620 | if (tmpmaps->content != NULL) |
---|
| 621 | addToMap (tmpmaps->content, refs[l], |
---|
| 622 | (char *) val); |
---|
| 623 | else |
---|
| 624 | tmpmaps->content = |
---|
| 625 | createMap (refs[l], (char *) val); |
---|
| 626 | |
---|
| 627 | map *ltmp = getMap (tmpmaps->content, "method"); |
---|
| 628 | if (l == 4 ) |
---|
| 629 | { |
---|
| 630 | if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0)) |
---|
| 631 | { |
---|
| 632 | if (loadRemoteFile |
---|
[623] | 633 | (main_conf, &tmpmaps->content, hInternet, |
---|
[621] | 634 | (char *) val) != 0) |
---|
| 635 | { |
---|
| 636 | return errorException (*main_conf, |
---|
| 637 | _("Unable to add a request in the queue."), |
---|
| 638 | "InternalError", |
---|
| 639 | NULL); |
---|
| 640 | } |
---|
[628] | 641 | addIntToMap (tmpmaps->content, "Order", hInternet->nb); |
---|
[621] | 642 | } |
---|
[627] | 643 | addToMap (tmpmaps->content, "Reference", (char*) val); |
---|
[621] | 644 | } |
---|
| 645 | } |
---|
| 646 | xmlFree (val); |
---|
| 647 | } |
---|
| 648 | // Parse Header and Body from Reference |
---|
| 649 | xmlNodePtr cur3 = cur2->children; |
---|
| 650 | while (cur3 != NULL) |
---|
| 651 | { |
---|
| 652 | while (cur3 != NULL |
---|
| 653 | && cur3->type != XML_ELEMENT_NODE) |
---|
| 654 | cur3 = cur3->next; |
---|
| 655 | if (cur3 == NULL) |
---|
| 656 | break; |
---|
| 657 | if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") == |
---|
| 658 | 0) |
---|
| 659 | { |
---|
| 660 | const char *ha[2]; |
---|
| 661 | ha[0] = "key"; |
---|
| 662 | ha[1] = "value"; |
---|
| 663 | int hai; |
---|
[695] | 664 | char *has=NULL; |
---|
[621] | 665 | char *key; |
---|
| 666 | for (hai = 0; hai < 2; hai++) |
---|
| 667 | { |
---|
| 668 | xmlChar *val = |
---|
| 669 | xmlGetProp (cur3, BAD_CAST ha[hai]); |
---|
| 670 | #ifdef POST_DEBUG |
---|
| 671 | fprintf (stderr, "%s = %s\n", ha[hai], |
---|
| 672 | (char *) val); |
---|
| 673 | #endif |
---|
| 674 | if (hai == 0) |
---|
| 675 | { |
---|
| 676 | key = zStrdup ((char *) val); |
---|
| 677 | } |
---|
| 678 | else |
---|
| 679 | { |
---|
| 680 | has = |
---|
| 681 | (char *) |
---|
| 682 | malloc ((4 + xmlStrlen (val) + |
---|
| 683 | strlen (key)) * |
---|
| 684 | sizeof (char)); |
---|
| 685 | if (has == NULL) |
---|
| 686 | { |
---|
| 687 | return errorException (*main_conf, |
---|
| 688 | _ |
---|
[725] | 689 | ("Unable to allocate memory"), |
---|
[621] | 690 | "InternalError", |
---|
| 691 | NULL); |
---|
| 692 | } |
---|
| 693 | snprintf (has, |
---|
| 694 | (3 + xmlStrlen (val) + |
---|
| 695 | strlen (key)), "%s: %s", key, |
---|
| 696 | (char *) val); |
---|
| 697 | free (key); |
---|
| 698 | } |
---|
| 699 | xmlFree (val); |
---|
| 700 | } |
---|
[695] | 701 | if (has != NULL){ |
---|
| 702 | hInternet->ihandle[hInternet->nb].header = NULL; |
---|
| 703 | hInternet->ihandle[hInternet->nb].header = |
---|
| 704 | curl_slist_append (hInternet->ihandle |
---|
| 705 | [hInternet->nb].header, |
---|
| 706 | has); |
---|
[621] | 707 | free (has); |
---|
[695] | 708 | } |
---|
[621] | 709 | } |
---|
| 710 | else |
---|
| 711 | { |
---|
| 712 | #ifdef POST_DEBUG |
---|
| 713 | fprintf (stderr, |
---|
| 714 | "Try to fetch the body part of the request ...\n"); |
---|
| 715 | #endif |
---|
| 716 | if (xmlStrcasecmp (cur3->name, BAD_CAST "Body") |
---|
| 717 | == 0) |
---|
| 718 | { |
---|
| 719 | #ifdef POST_DEBUG |
---|
| 720 | fprintf (stderr, "Body part found (%s) !!!\n", |
---|
| 721 | (char *) cur3->content); |
---|
| 722 | #endif |
---|
| 723 | char *tmp = NULL; |
---|
| 724 | xmlNodePtr cur4 = cur3->children; |
---|
| 725 | while (cur4 != NULL) |
---|
| 726 | { |
---|
| 727 | while (cur4 && cur4 != NULL && cur4->type && cur4->type != XML_ELEMENT_NODE){ |
---|
| 728 | if(cur4->next) |
---|
| 729 | cur4 = cur4->next; |
---|
| 730 | else |
---|
| 731 | cur4 = NULL; |
---|
| 732 | } |
---|
| 733 | if(cur4 != NULL) { |
---|
| 734 | xmlDocPtr bdoc = |
---|
| 735 | xmlNewDoc (BAD_CAST "1.0"); |
---|
| 736 | bdoc->encoding = |
---|
| 737 | xmlCharStrdup ("UTF-8"); |
---|
| 738 | xmlDocSetRootElement (bdoc, cur4); |
---|
| 739 | xmlChar *btmps; |
---|
| 740 | int bsize; |
---|
| 741 | // TODO : check for encoding defined in the input |
---|
| 742 | xmlDocDumpFormatMemoryEnc(bdoc, &btmps, &bsize, "UTF-8", 0); |
---|
| 743 | if (btmps != NULL){ |
---|
| 744 | tmp = (char *) malloc ((bsize + 1) * sizeof (char)); |
---|
| 745 | |
---|
| 746 | sprintf (tmp, "%s", (char*) btmps); |
---|
[745] | 747 | |
---|
| 748 | //xmlFreeDoc (bdoc); |
---|
[621] | 749 | |
---|
| 750 | map *btmp = |
---|
| 751 | getMap (tmpmaps->content, "Reference"); |
---|
| 752 | if (btmp != NULL) |
---|
| 753 | { |
---|
[623] | 754 | addRequestToQueue(main_conf,hInternet,(char *) btmp->value,false); |
---|
[621] | 755 | InternetOpenUrl (hInternet, |
---|
| 756 | btmp->value, |
---|
| 757 | tmp, |
---|
| 758 | xmlStrlen(btmps), |
---|
| 759 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 760 | 0); |
---|
[627] | 761 | addIntToMap (tmpmaps->content, "Order", hInternet->nb); |
---|
[621] | 762 | } |
---|
| 763 | xmlFree (btmps); |
---|
| 764 | free (tmp); |
---|
| 765 | break; |
---|
| 766 | } |
---|
| 767 | } |
---|
| 768 | cur4 = cur4->next; |
---|
| 769 | } |
---|
| 770 | } |
---|
| 771 | else |
---|
| 772 | if (xmlStrcasecmp |
---|
| 773 | (cur3->name, |
---|
| 774 | BAD_CAST "BodyReference") == 0) |
---|
| 775 | { |
---|
| 776 | xmlChar *val = |
---|
| 777 | xmlGetProp (cur3, BAD_CAST "href"); |
---|
| 778 | HINTERNET bInternet, res1, res; |
---|
| 779 | bInternet = InternetOpen ( |
---|
| 780 | #ifndef WIN32 |
---|
| 781 | (LPCTSTR) |
---|
| 782 | #endif |
---|
| 783 | "ZooWPSClient\0", |
---|
| 784 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 785 | NULL, NULL, 0); |
---|
| 786 | if (!CHECK_INET_HANDLE (bInternet)) |
---|
| 787 | fprintf (stderr, |
---|
| 788 | "WARNING : bInternet handle failed to initialize"); |
---|
| 789 | bInternet.waitingRequests[0] = |
---|
| 790 | strdup ((char *) val); |
---|
| 791 | res1 = |
---|
| 792 | InternetOpenUrl (&bInternet, |
---|
| 793 | bInternet.waitingRequests |
---|
| 794 | [0], NULL, 0, |
---|
| 795 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 796 | 0); |
---|
| 797 | processDownloads (&bInternet); |
---|
| 798 | char *tmp = |
---|
| 799 | (char *) |
---|
| 800 | malloc ((bInternet.ihandle[0].nDataLen + |
---|
| 801 | 1) * sizeof (char)); |
---|
| 802 | if (tmp == NULL) |
---|
| 803 | { |
---|
| 804 | return errorException (*main_conf, |
---|
| 805 | _ |
---|
[725] | 806 | ("Unable to allocate memory"), |
---|
[621] | 807 | "InternalError", |
---|
| 808 | NULL); |
---|
| 809 | } |
---|
| 810 | size_t bRead; |
---|
| 811 | InternetReadFile (bInternet.ihandle[0], |
---|
| 812 | (LPVOID) tmp, |
---|
| 813 | bInternet. |
---|
| 814 | ihandle[0].nDataLen, |
---|
| 815 | &bRead); |
---|
| 816 | tmp[bInternet.ihandle[0].nDataLen] = 0; |
---|
| 817 | InternetCloseHandle (&bInternet); |
---|
| 818 | map *btmp = |
---|
| 819 | getMap (tmpmaps->content, "href"); |
---|
| 820 | if (btmp != NULL) |
---|
| 821 | { |
---|
[623] | 822 | addRequestToQueue(main_conf,hInternet,(char *) btmp->value,false); |
---|
[621] | 823 | |
---|
| 824 | res = |
---|
| 825 | InternetOpenUrl (hInternet, |
---|
| 826 | btmp->value, |
---|
| 827 | tmp, |
---|
| 828 | strlen(tmp), |
---|
| 829 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 830 | 0); |
---|
[627] | 831 | addIntToMap (tmpmaps->content, "Order", hInternet->nb); |
---|
[621] | 832 | } |
---|
| 833 | free (tmp); |
---|
| 834 | } |
---|
| 835 | } |
---|
| 836 | cur3 = cur3->next; |
---|
| 837 | } |
---|
| 838 | } |
---|
| 839 | else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0) |
---|
| 840 | { |
---|
[745] | 841 | defineMissingIdentifier(main_conf,&tmpmaps); |
---|
[621] | 842 | xmlNodePtr cur4 = cur2->children; |
---|
[654] | 843 | if(vid==1){ |
---|
| 844 | // Get every dataEncodingAttributes from a Data node: |
---|
| 845 | // mimeType, encoding, schema |
---|
| 846 | const char *coms[3] = |
---|
| 847 | { "mimeType", "encoding", "schema" }; |
---|
| 848 | for (l = 0; l < 3; l++){ |
---|
| 849 | xmlChar *val = |
---|
| 850 | xmlGetProp (cur4, BAD_CAST coms[l]); |
---|
| 851 | if (val != NULL && strlen ((char *) val) > 0){ |
---|
| 852 | if (tmpmaps->content != NULL) |
---|
| 853 | addToMap (tmpmaps->content,coms[l],(char *) val); |
---|
| 854 | else |
---|
| 855 | tmpmaps->content = |
---|
| 856 | createMap (coms[l],(char *) val); |
---|
| 857 | } |
---|
| 858 | xmlFree (val); |
---|
| 859 | } |
---|
| 860 | while (cur4 != NULL){ |
---|
| 861 | while(cur4 != NULL && |
---|
| 862 | cur4->type != XML_CDATA_SECTION_NODE && |
---|
| 863 | cur4->type != XML_TEXT_NODE) |
---|
| 864 | cur4=cur4->next; |
---|
| 865 | if(cur4!=NULL){ |
---|
[790] | 866 | if(cur4->content!=NULL){ |
---|
[654] | 867 | if (tmpmaps->content != NULL) |
---|
| 868 | addToMap (tmpmaps->content, "value", |
---|
| 869 | (char *) cur4->content); |
---|
| 870 | else |
---|
| 871 | tmpmaps->content = |
---|
| 872 | createMap ("value", (char *) cur4->content); |
---|
[790] | 873 | } |
---|
[654] | 874 | cur4=cur4->next; |
---|
| 875 | } |
---|
| 876 | } |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | |
---|
[621] | 880 | while (cur4 != NULL) |
---|
| 881 | { |
---|
| 882 | while (cur4 != NULL |
---|
| 883 | && cur4->type != XML_ELEMENT_NODE) |
---|
| 884 | cur4 = cur4->next; |
---|
| 885 | if (cur4 == NULL) |
---|
| 886 | break; |
---|
| 887 | if (xmlStrcasecmp |
---|
| 888 | (cur4->name, BAD_CAST "LiteralData") == 0) |
---|
| 889 | { |
---|
| 890 | // Get every attribute from a LiteralData node |
---|
| 891 | // dataType , uom |
---|
| 892 | char *list[2]; |
---|
| 893 | list[0] = zStrdup ("dataType"); |
---|
| 894 | list[1] = zStrdup ("uom"); |
---|
[622] | 895 | for (l = 0; l < 2; l++) |
---|
[621] | 896 | { |
---|
| 897 | xmlChar *val = |
---|
| 898 | xmlGetProp (cur4, BAD_CAST list[l]); |
---|
| 899 | if (val != NULL |
---|
| 900 | && strlen ((char *) val) > 0) |
---|
| 901 | { |
---|
| 902 | if (tmpmaps->content != NULL) |
---|
| 903 | addToMap (tmpmaps->content, list[l], |
---|
| 904 | (char *) val); |
---|
| 905 | else |
---|
| 906 | tmpmaps->content = |
---|
| 907 | createMap (list[l], (char *) val); |
---|
| 908 | } |
---|
| 909 | xmlFree (val); |
---|
| 910 | free (list[l]); |
---|
| 911 | } |
---|
| 912 | } |
---|
| 913 | else |
---|
| 914 | if (xmlStrcasecmp |
---|
| 915 | (cur4->name, BAD_CAST "ComplexData") == 0) |
---|
| 916 | { |
---|
| 917 | // Get every attribute from a Reference node |
---|
| 918 | // mimeType, encoding, schema |
---|
| 919 | const char *coms[3] = |
---|
| 920 | { "mimeType", "encoding", "schema" }; |
---|
[622] | 921 | for (l = 0; l < 3; l++) |
---|
[621] | 922 | { |
---|
| 923 | xmlChar *val = |
---|
| 924 | xmlGetProp (cur4, BAD_CAST coms[l]); |
---|
| 925 | if (val != NULL |
---|
| 926 | && strlen ((char *) val) > 0) |
---|
| 927 | { |
---|
| 928 | if (tmpmaps->content != NULL) |
---|
| 929 | addToMap (tmpmaps->content, coms[l], |
---|
| 930 | (char *) val); |
---|
| 931 | else |
---|
| 932 | tmpmaps->content = |
---|
| 933 | createMap (coms[l], (char *) val); |
---|
| 934 | } |
---|
| 935 | xmlFree (val); |
---|
| 936 | } |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | map *test = getMap (tmpmaps->content, "encoding"); |
---|
| 940 | |
---|
| 941 | if (test == NULL) |
---|
| 942 | { |
---|
| 943 | if (tmpmaps->content != NULL) |
---|
| 944 | addToMap (tmpmaps->content, "encoding", |
---|
| 945 | "utf-8"); |
---|
| 946 | else |
---|
| 947 | tmpmaps->content = |
---|
| 948 | createMap ("encoding", "utf-8"); |
---|
| 949 | test = getMap (tmpmaps->content, "encoding"); |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | if (strcasecmp (test->value, "base64") != 0) |
---|
| 953 | { |
---|
| 954 | xmlChar *mv = xmlNodeListGetString (doc, |
---|
| 955 | cur4->xmlChildrenNode, |
---|
| 956 | 1); |
---|
| 957 | map *ltmp = |
---|
| 958 | getMap (tmpmaps->content, "mimeType"); |
---|
| 959 | if (mv == NULL |
---|
| 960 | || |
---|
| 961 | (xmlStrcasecmp |
---|
| 962 | (cur4->name, BAD_CAST "ComplexData") == 0 |
---|
| 963 | && (ltmp == NULL |
---|
| 964 | || strncasecmp (ltmp->value, |
---|
| 965 | "text/xml", 8) == 0))) |
---|
| 966 | { |
---|
| 967 | xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); |
---|
| 968 | int buffersize; |
---|
| 969 | xmlNodePtr cur5 = cur4->children; |
---|
| 970 | while (cur5 != NULL |
---|
| 971 | && cur5->type != XML_ELEMENT_NODE |
---|
[654] | 972 | && cur5->type != XML_CDATA_SECTION_NODE) |
---|
[621] | 973 | cur5 = cur5->next; |
---|
| 974 | if (cur5 != NULL |
---|
| 975 | && cur5->type != XML_CDATA_SECTION_NODE) |
---|
| 976 | { |
---|
| 977 | xmlDocSetRootElement (doc1, cur5); |
---|
| 978 | xmlDocDumpFormatMemoryEnc (doc1, &mv, |
---|
| 979 | &buffersize, |
---|
[703] | 980 | "utf-8", 0); |
---|
[621] | 981 | } |
---|
| 982 | else |
---|
| 983 | { |
---|
| 984 | if (cur5 != NULL |
---|
| 985 | && cur5->type == XML_CDATA_SECTION_NODE){ |
---|
[745] | 986 | xmlDocPtr doc2 = xmlReadMemory((const char*)cur5->content,xmlStrlen(cur5->content), |
---|
| 987 | "input_content.xml", NULL, XML_PARSE_RECOVER); |
---|
| 988 | xmlDocDumpFormatMemoryEnc (doc2, &mv, |
---|
[621] | 989 | &buffersize, |
---|
[703] | 990 | "utf-8", 0); |
---|
[621] | 991 | xmlFreeDoc (doc2); |
---|
| 992 | } |
---|
| 993 | } |
---|
[745] | 994 | addIntToMap (tmpmaps->content, "size", |
---|
| 995 | buffersize); |
---|
| 996 | xmlFreeDoc (doc1); |
---|
[621] | 997 | }else{ |
---|
| 998 | xmlNodePtr cur5 = cur4->children; |
---|
| 999 | while (cur5 != NULL |
---|
| 1000 | && cur5->type != XML_CDATA_SECTION_NODE) |
---|
| 1001 | cur5 = cur5->next; |
---|
| 1002 | if (cur5 != NULL |
---|
| 1003 | && cur5->type == XML_CDATA_SECTION_NODE){ |
---|
| 1004 | xmlFree(mv); |
---|
| 1005 | mv=xmlStrdup(cur5->content); |
---|
| 1006 | } |
---|
| 1007 | } |
---|
| 1008 | if (mv != NULL) |
---|
| 1009 | { |
---|
| 1010 | addToMap (tmpmaps->content, "value", |
---|
[703] | 1011 | (char*) mv); |
---|
[621] | 1012 | xmlFree (mv); |
---|
| 1013 | } |
---|
| 1014 | } |
---|
| 1015 | else |
---|
| 1016 | { |
---|
| 1017 | xmlChar *tmp = xmlNodeListGetRawString (doc, |
---|
| 1018 | cur4->xmlChildrenNode, |
---|
| 1019 | 0); |
---|
| 1020 | addToMap (tmpmaps->content, "value", |
---|
| 1021 | (char *) tmp); |
---|
| 1022 | xmlFree (tmp); |
---|
| 1023 | } |
---|
[703] | 1024 | |
---|
[621] | 1025 | cur4 = cur4->next; |
---|
| 1026 | } |
---|
| 1027 | } |
---|
| 1028 | cur2 = cur2->next; |
---|
[631] | 1029 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE){ |
---|
| 1030 | cur2 = cur2->next; |
---|
| 1031 | } |
---|
[621] | 1032 | } |
---|
| 1033 | { |
---|
[745] | 1034 | map* test=getMap(tmpmaps->content,"value"); |
---|
[790] | 1035 | if(test==NULL && tmpmaps->child==NULL) |
---|
[745] | 1036 | addToMap(tmpmaps->content,"value",""); |
---|
[790] | 1037 | maps *testPresence = getMaps (*request_output, tmpmaps->name); |
---|
| 1038 | maps *cursor=*request_output; |
---|
| 1039 | while(testPresence == NULL && cursor!=NULL){ |
---|
| 1040 | if(cursor->child!=NULL){ |
---|
| 1041 | testPresence = getMaps (cursor->child, tmpmaps->name); |
---|
| 1042 | } |
---|
| 1043 | cursor=cursor->next; |
---|
| 1044 | } |
---|
[621] | 1045 | if (testPresence != NULL) |
---|
| 1046 | { |
---|
| 1047 | elements *elem = getElements (s->inputs, tmpmaps->name); |
---|
[790] | 1048 | elements *cursor=s->inputs; |
---|
| 1049 | while(elem == NULL && cursor!=NULL){ |
---|
| 1050 | if(cursor->child!=NULL){ |
---|
| 1051 | elem = getElements (cursor->child, tmpmaps->name); |
---|
| 1052 | } |
---|
| 1053 | cursor=cursor->next; |
---|
| 1054 | } |
---|
[621] | 1055 | if (elem != NULL) |
---|
| 1056 | { |
---|
| 1057 | if (appendMapsToMaps |
---|
[790] | 1058 | (*main_conf, testPresence, tmpmaps, elem) < 0) |
---|
[621] | 1059 | { |
---|
| 1060 | return errorException (*main_conf, |
---|
| 1061 | _("Unable to append maps to maps."), |
---|
| 1062 | "InternalError", |
---|
| 1063 | NULL); |
---|
| 1064 | } |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | else |
---|
[623] | 1068 | addMapsToMaps (request_output, tmpmaps); |
---|
[621] | 1069 | } |
---|
| 1070 | freeMaps (&tmpmaps); |
---|
| 1071 | free (tmpmaps); |
---|
| 1072 | tmpmaps = NULL; |
---|
| 1073 | } |
---|
| 1074 | } |
---|
| 1075 | return 1; |
---|
| 1076 | } |
---|
| 1077 | |
---|
| 1078 | /** |
---|
[654] | 1079 | * Parse outputs from XML nodes and store them in a maps (WPS version 2.0.0). |
---|
| 1080 | * |
---|
| 1081 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 1082 | * @param request_inputs the map storing KVP raw value |
---|
| 1083 | * @param request_output the maps to store the KVP pairs |
---|
| 1084 | * @param doc the xmlDocPtr containing the original request |
---|
| 1085 | * @param cur the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node |
---|
| 1086 | * @param raw true if the node is RawDataOutput, false in case of ResponseDocument |
---|
| 1087 | * @return 0 on success, -1 on failure |
---|
| 1088 | */ |
---|
| 1089 | int xmlParseOutputs2(maps** main_conf,map** request_inputs,maps** request_output,xmlDocPtr doc,xmlNodeSet* nodes){ |
---|
| 1090 | int k = 0; |
---|
| 1091 | int l = 0; |
---|
| 1092 | for (k=0; k < nodes->nodeNr; k++){ |
---|
| 1093 | maps *tmpmaps = NULL; |
---|
| 1094 | xmlNodePtr cur = nodes->nodeTab[k]; |
---|
| 1095 | if (cur->type == XML_ELEMENT_NODE){ |
---|
[790] | 1096 | maps *tmpmaps = NULL; |
---|
[654] | 1097 | xmlChar *val = xmlGetProp (cur, BAD_CAST "id"); |
---|
| 1098 | if(val!=NULL) |
---|
[790] | 1099 | tmpmaps = createMaps((char *)val); |
---|
[654] | 1100 | else |
---|
[790] | 1101 | tmpmaps = createMaps("unknownIdentifier"); |
---|
[654] | 1102 | const char ress[4][13] = |
---|
| 1103 | { "mimeType", "encoding", "schema", "transmission" }; |
---|
| 1104 | for (l = 0; l < 4; l++){ |
---|
| 1105 | val = xmlGetProp (cur, BAD_CAST ress[l]); |
---|
| 1106 | if (val != NULL && strlen ((char *) val) > 0) |
---|
| 1107 | { |
---|
| 1108 | if (tmpmaps->content != NULL) |
---|
| 1109 | addToMap (tmpmaps->content, ress[l], |
---|
| 1110 | (char *) val); |
---|
| 1111 | else |
---|
| 1112 | tmpmaps->content = |
---|
| 1113 | createMap (ress[l], (char *) val); |
---|
| 1114 | if(l==3 && strncasecmp((char*)val,"reference",xmlStrlen(val))==0) |
---|
| 1115 | addToMap (tmpmaps->content,"asReference","true"); |
---|
| 1116 | } |
---|
| 1117 | xmlFree (val); |
---|
| 1118 | } |
---|
[790] | 1119 | if(cur->children!=NULL){ |
---|
| 1120 | xmlNodePtr ccur = cur->children; |
---|
| 1121 | while (ccur != NULL){ |
---|
| 1122 | if(ccur->type == XML_ELEMENT_NODE){ |
---|
| 1123 | char *xpathExpr=(char*)malloc(65+strlen(tmpmaps->name)); |
---|
| 1124 | sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name); |
---|
| 1125 | xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr); |
---|
| 1126 | xmlNodeSet* cnodes = tmpsptr->nodesetval; |
---|
| 1127 | xmlParseOutputs2(main_conf,request_inputs,&tmpmaps->child,doc,cnodes); |
---|
| 1128 | break; |
---|
| 1129 | } |
---|
| 1130 | ccur = ccur->next; |
---|
| 1131 | } |
---|
| 1132 | } |
---|
| 1133 | if (*request_output == NULL){ |
---|
[654] | 1134 | *request_output = dupMaps(&tmpmaps); |
---|
[790] | 1135 | } |
---|
| 1136 | else{ |
---|
[654] | 1137 | addMapsToMaps(request_output,tmpmaps); |
---|
[790] | 1138 | } |
---|
| 1139 | freeMaps(&tmpmaps); |
---|
| 1140 | free(tmpmaps); |
---|
[654] | 1141 | } |
---|
| 1142 | } |
---|
[680] | 1143 | return 0; |
---|
[654] | 1144 | } |
---|
| 1145 | |
---|
| 1146 | /** |
---|
[621] | 1147 | * Parse outputs from XML nodes and store them in a maps. |
---|
| 1148 | * |
---|
| 1149 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 1150 | * @param request_inputs the map storing KVP raw value |
---|
| 1151 | * @param request_output the maps to store the KVP pairs |
---|
| 1152 | * @param doc the xmlDocPtr containing the original request |
---|
| 1153 | * @param cur the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node |
---|
| 1154 | * @param raw true if the node is RawDataOutput, false in case of ResponseDocument |
---|
| 1155 | * @return 0 on success, -1 on failure |
---|
| 1156 | */ |
---|
| 1157 | int xmlParseOutputs(maps** main_conf,map** request_inputs,maps** request_output,xmlDocPtr doc,xmlNodePtr cur,bool raw){ |
---|
[622] | 1158 | int l=0; |
---|
[621] | 1159 | if( raw == true) |
---|
| 1160 | { |
---|
| 1161 | addToMap (*request_inputs, "RawDataOutput", ""); |
---|
| 1162 | if (cur->type == XML_ELEMENT_NODE) |
---|
| 1163 | { |
---|
| 1164 | |
---|
[790] | 1165 | maps *tmpmaps = createMaps("unknownIdentifier"); |
---|
[621] | 1166 | if (tmpmaps == NULL) |
---|
| 1167 | { |
---|
[725] | 1168 | return errorException (*main_conf, _("Unable to allocate memory"), |
---|
[621] | 1169 | "InternalError", NULL); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | // Get every attribute from a RawDataOutput node |
---|
| 1173 | // mimeType, encoding, schema, uom |
---|
| 1174 | const char *outs[4] = |
---|
| 1175 | { "mimeType", "encoding", "schema", "uom" }; |
---|
[622] | 1176 | for (l = 0; l < 4; l++) |
---|
[621] | 1177 | { |
---|
| 1178 | xmlChar *val = xmlGetProp (cur, BAD_CAST outs[l]); |
---|
| 1179 | if (val != NULL) |
---|
| 1180 | { |
---|
| 1181 | if (strlen ((char *) val) > 0) |
---|
| 1182 | { |
---|
| 1183 | if (tmpmaps->content != NULL) |
---|
| 1184 | addToMap (tmpmaps->content, outs[l], |
---|
| 1185 | (char *) val); |
---|
| 1186 | else |
---|
| 1187 | tmpmaps->content = |
---|
| 1188 | createMap (outs[l], (char *) val); |
---|
| 1189 | } |
---|
| 1190 | xmlFree (val); |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | xmlNodePtr cur2 = cur->children; |
---|
| 1194 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 1195 | cur2 = cur2->next; |
---|
| 1196 | while (cur2 != NULL) |
---|
| 1197 | { |
---|
| 1198 | if (xmlStrncasecmp |
---|
| 1199 | (cur2->name, BAD_CAST "Identifier", |
---|
| 1200 | xmlStrlen (cur2->name)) == 0) |
---|
| 1201 | { |
---|
| 1202 | xmlChar *val = |
---|
| 1203 | xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1); |
---|
| 1204 | free (tmpmaps->name); |
---|
| 1205 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 1206 | xmlFree (val); |
---|
| 1207 | } |
---|
| 1208 | cur2 = cur2->next; |
---|
| 1209 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 1210 | cur2 = cur2->next; |
---|
| 1211 | } |
---|
| 1212 | if (*request_output == NULL) |
---|
| 1213 | *request_output = dupMaps (&tmpmaps); |
---|
| 1214 | else |
---|
[623] | 1215 | addMapsToMaps (request_output, tmpmaps); |
---|
[621] | 1216 | if (tmpmaps != NULL) |
---|
| 1217 | { |
---|
| 1218 | freeMaps (&tmpmaps); |
---|
| 1219 | free (tmpmaps); |
---|
| 1220 | tmpmaps = NULL; |
---|
| 1221 | } |
---|
| 1222 | } |
---|
| 1223 | } |
---|
| 1224 | else |
---|
| 1225 | { |
---|
| 1226 | addToMap (*request_inputs, "ResponseDocument", ""); |
---|
| 1227 | |
---|
| 1228 | if (cur->type == XML_ELEMENT_NODE) { |
---|
| 1229 | // Get every attribute: storeExecuteResponse, lineage, status |
---|
| 1230 | const char *ress[3] = |
---|
| 1231 | { "storeExecuteResponse", "lineage", "status" }; |
---|
| 1232 | xmlChar *val; |
---|
[622] | 1233 | for (l = 0; l < 3; l++) |
---|
[621] | 1234 | { |
---|
| 1235 | val = xmlGetProp (cur, BAD_CAST ress[l]); |
---|
| 1236 | if (val != NULL && strlen ((char *) val) > 0) |
---|
| 1237 | { |
---|
| 1238 | addToMap (*request_inputs, ress[l], (char *) val); |
---|
| 1239 | } |
---|
| 1240 | xmlFree (val); |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | xmlNodePtr cur1 = cur->children; |
---|
| 1244 | while (cur1 != NULL) // iterate over Output nodes |
---|
| 1245 | { |
---|
| 1246 | if (cur1->type != XML_ELEMENT_NODE || |
---|
| 1247 | xmlStrncasecmp(cur1->name, BAD_CAST "Output", |
---|
| 1248 | xmlStrlen (cur1->name)) != 0) { |
---|
| 1249 | cur1 = cur1->next; |
---|
| 1250 | continue; |
---|
| 1251 | } |
---|
| 1252 | |
---|
[790] | 1253 | maps *tmpmaps = createMaps("unknownIdentifier"); // one per Output node |
---|
[621] | 1254 | if (tmpmaps == NULL) { |
---|
| 1255 | return errorException (*main_conf, |
---|
| 1256 | _ |
---|
[725] | 1257 | ("Unable to allocate memory"), |
---|
[621] | 1258 | "InternalError", NULL); |
---|
| 1259 | } |
---|
| 1260 | |
---|
| 1261 | xmlNodePtr elems = cur1->children; |
---|
| 1262 | |
---|
| 1263 | while (elems != NULL) { |
---|
| 1264 | |
---|
| 1265 | // Identifier |
---|
| 1266 | if (xmlStrncasecmp |
---|
| 1267 | (elems->name, BAD_CAST "Identifier", |
---|
| 1268 | xmlStrlen (elems->name)) == 0) |
---|
| 1269 | { |
---|
| 1270 | xmlChar *val = |
---|
| 1271 | xmlNodeListGetString (doc, elems->xmlChildrenNode, 1); |
---|
| 1272 | |
---|
| 1273 | free(tmpmaps->name); |
---|
| 1274 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 1275 | if (tmpmaps->content == NULL) { |
---|
| 1276 | tmpmaps->content = createMap("Identifier", zStrdup ((char *) val)); |
---|
| 1277 | } |
---|
| 1278 | else { |
---|
| 1279 | addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val)); |
---|
| 1280 | } |
---|
| 1281 | |
---|
| 1282 | map* tt = getMap (*request_inputs, "ResponseDocument"); |
---|
| 1283 | if (strlen(tt->value) == 0) { |
---|
| 1284 | addToMap (*request_inputs, "ResponseDocument", |
---|
| 1285 | (char *) val); |
---|
| 1286 | } |
---|
| 1287 | else { |
---|
| 1288 | char* tmp = (char*) malloc((strlen(tt->value) + 1 |
---|
| 1289 | + strlen((char*) val) + 1) * sizeof(char)); |
---|
| 1290 | sprintf (tmp, "%s;%s", tt->value, (char *) val); |
---|
| 1291 | free(tt->value); |
---|
| 1292 | tt->value = tmp; |
---|
| 1293 | } |
---|
| 1294 | xmlFree (val); |
---|
| 1295 | } |
---|
| 1296 | |
---|
| 1297 | // Title, Abstract |
---|
| 1298 | else if (xmlStrncasecmp(elems->name, BAD_CAST "Title", |
---|
| 1299 | xmlStrlen (elems->name)) == 0 |
---|
| 1300 | || xmlStrncasecmp(elems->name, BAD_CAST "Abstract", |
---|
| 1301 | xmlStrlen (elems->name)) == 0) |
---|
| 1302 | { |
---|
| 1303 | xmlChar *val = |
---|
| 1304 | xmlNodeListGetString (doc, elems->xmlChildrenNode, 1); |
---|
| 1305 | |
---|
| 1306 | if (tmpmaps->content == NULL) { |
---|
| 1307 | tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val)); |
---|
| 1308 | } |
---|
| 1309 | else { |
---|
| 1310 | addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val)); |
---|
| 1311 | } |
---|
| 1312 | xmlFree (val); |
---|
| 1313 | } |
---|
| 1314 | elems = elems->next; |
---|
| 1315 | } |
---|
| 1316 | |
---|
| 1317 | // Get every attribute from an Output node: |
---|
| 1318 | // mimeType, encoding, schema, uom, asReference |
---|
| 1319 | const char *outs[5] = |
---|
| 1320 | { "mimeType", "encoding", "schema", "uom", "asReference" }; |
---|
| 1321 | |
---|
[622] | 1322 | for (l = 0; l < 5; l++) { |
---|
[621] | 1323 | xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]); |
---|
| 1324 | if (val != NULL && xmlStrlen(val) > 0) { |
---|
| 1325 | if (tmpmaps->content != NULL) { |
---|
| 1326 | addToMap (tmpmaps->content, outs[l], (char *) val); |
---|
| 1327 | } |
---|
| 1328 | else { |
---|
| 1329 | tmpmaps->content = createMap (outs[l], (char *) val); |
---|
| 1330 | } |
---|
| 1331 | } |
---|
| 1332 | xmlFree (val); |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | if (*request_output == NULL) { |
---|
| 1336 | *request_output = tmpmaps; |
---|
| 1337 | } |
---|
| 1338 | else if (getMaps(*request_output, tmpmaps->name) != NULL) { |
---|
| 1339 | return errorException (*main_conf, |
---|
| 1340 | _ |
---|
| 1341 | ("Duplicate <Output> elements in WPS Execute request"), |
---|
| 1342 | "InternalError", NULL); |
---|
| 1343 | } |
---|
| 1344 | else { |
---|
| 1345 | maps* mptr = *request_output; |
---|
| 1346 | while (mptr->next != NULL) { |
---|
| 1347 | mptr = mptr->next; |
---|
| 1348 | } |
---|
| 1349 | mptr->next = tmpmaps; |
---|
| 1350 | } |
---|
| 1351 | cur1 = cur1->next; |
---|
| 1352 | } |
---|
| 1353 | } |
---|
| 1354 | } |
---|
| 1355 | return 1; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | /** |
---|
[781] | 1359 | * Parse XML request and store information in maps. |
---|
[621] | 1360 | * |
---|
| 1361 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 1362 | * @param post the string containing the XML request |
---|
| 1363 | * @param request_inputs the map storing KVP raw value |
---|
| 1364 | * @param s the service |
---|
| 1365 | * @param inputs the maps to store the KVP pairs |
---|
| 1366 | * @param outputs the maps to store the KVP pairs |
---|
| 1367 | * @param hInternet the HINTERNET queue to add potential requests |
---|
| 1368 | * @return 0 on success, -1 on failure |
---|
| 1369 | */ |
---|
| 1370 | int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){ |
---|
[654] | 1371 | |
---|
| 1372 | map* version=getMapFromMaps(*main_conf,"main","rversion"); |
---|
| 1373 | int vid=getVersionId(version->value); |
---|
| 1374 | |
---|
[621] | 1375 | xmlInitParser (); |
---|
[745] | 1376 | xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER); |
---|
[621] | 1377 | |
---|
| 1378 | /** |
---|
| 1379 | * Extract Input nodes from the XML Request. |
---|
| 1380 | */ |
---|
| 1381 | xmlXPathObjectPtr tmpsptr = |
---|
[654] | 1382 | extractFromDoc (doc, (vid==0?"/*/*/*[local-name()='Input']":"/*/*[local-name()='Input']")); |
---|
[621] | 1383 | xmlNodeSet *tmps = tmpsptr->nodesetval; |
---|
[654] | 1384 | if(tmps==NULL || xmlParseInputs(main_conf,s,inputs,doc,tmps,hInternet)<0){ |
---|
[621] | 1385 | xmlXPathFreeObject (tmpsptr); |
---|
| 1386 | xmlFreeDoc (doc); |
---|
| 1387 | xmlCleanupParser (); |
---|
| 1388 | return -1; |
---|
| 1389 | } |
---|
| 1390 | xmlXPathFreeObject (tmpsptr); |
---|
| 1391 | |
---|
[654] | 1392 | if(vid==1){ |
---|
| 1393 | tmpsptr = |
---|
| 1394 | extractFromDoc (doc, "/*[local-name()='Execute']"); |
---|
| 1395 | bool asRaw = false; |
---|
| 1396 | tmps = tmpsptr->nodesetval; |
---|
| 1397 | if(tmps->nodeNr > 0){ |
---|
| 1398 | int k = 0; |
---|
| 1399 | for (k=0; k < tmps->nodeNr; k++){ |
---|
| 1400 | maps *tmpmaps = NULL; |
---|
| 1401 | xmlNodePtr cur = tmps->nodeTab[k]; |
---|
| 1402 | if (cur->type == XML_ELEMENT_NODE){ |
---|
| 1403 | xmlChar *val = xmlGetProp (cur, BAD_CAST "mode"); |
---|
| 1404 | if(val!=NULL) |
---|
| 1405 | addToMap(*request_inputs,"mode",(char*)val); |
---|
| 1406 | else |
---|
| 1407 | addToMap(*request_inputs,"mode","auto"); |
---|
| 1408 | val = xmlGetProp (cur, BAD_CAST "response"); |
---|
| 1409 | if(val!=NULL){ |
---|
| 1410 | addToMap(*request_inputs,"response",(char*)val); |
---|
| 1411 | if(strncasecmp((char*)val,"raw",xmlStrlen(val))==0) |
---|
| 1412 | addToMap(*request_inputs,"RawDataOutput",""); |
---|
| 1413 | else |
---|
| 1414 | addToMap(*request_inputs,"ResponseDocument",""); |
---|
| 1415 | } |
---|
| 1416 | else{ |
---|
| 1417 | addToMap(*request_inputs,"response","document"); |
---|
| 1418 | addToMap(*request_inputs,"ResponseDocument",""); |
---|
| 1419 | } |
---|
| 1420 | } |
---|
| 1421 | } |
---|
[621] | 1422 | } |
---|
[654] | 1423 | xmlXPathFreeObject (tmpsptr); |
---|
| 1424 | tmpsptr = |
---|
| 1425 | extractFromDoc (doc, "/*/*[local-name()='Output']"); |
---|
| 1426 | tmps = tmpsptr->nodesetval; |
---|
| 1427 | if(tmps->nodeNr > 0){ |
---|
| 1428 | if(xmlParseOutputs2(main_conf,request_inputs,outputs,doc,tmps)<0){ |
---|
| 1429 | xmlXPathFreeObject (tmpsptr); |
---|
| 1430 | xmlFreeDoc (doc); |
---|
| 1431 | xmlCleanupParser (); |
---|
| 1432 | return -1; |
---|
| 1433 | } |
---|
[621] | 1434 | } |
---|
| 1435 | } |
---|
[654] | 1436 | else{ |
---|
| 1437 | // Extract ResponseDocument / RawDataOutput from the XML Request |
---|
| 1438 | tmpsptr = |
---|
| 1439 | extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); |
---|
| 1440 | bool asRaw = false; |
---|
| 1441 | tmps = tmpsptr->nodesetval; |
---|
| 1442 | if (tmps->nodeNr == 0) |
---|
| 1443 | { |
---|
| 1444 | xmlXPathFreeObject (tmpsptr); |
---|
| 1445 | tmpsptr = |
---|
| 1446 | extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); |
---|
| 1447 | tmps = tmpsptr->nodesetval; |
---|
| 1448 | asRaw = true; |
---|
| 1449 | } |
---|
| 1450 | if(tmps->nodeNr != 0){ |
---|
| 1451 | if(xmlParseOutputs(main_conf,request_inputs,outputs,doc,tmps->nodeTab[0],asRaw)<0){ |
---|
| 1452 | xmlXPathFreeObject (tmpsptr); |
---|
| 1453 | xmlFreeDoc (doc); |
---|
| 1454 | xmlCleanupParser (); |
---|
| 1455 | return -1; |
---|
| 1456 | } |
---|
| 1457 | } |
---|
| 1458 | } |
---|
[621] | 1459 | xmlXPathFreeObject (tmpsptr); |
---|
| 1460 | xmlFreeDoc (doc); |
---|
| 1461 | xmlCleanupParser (); |
---|
| 1462 | return 1; |
---|
| 1463 | } |
---|
| 1464 | |
---|
| 1465 | /** |
---|
[781] | 1466 | * Parse request and store information in maps. |
---|
[621] | 1467 | * |
---|
| 1468 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 1469 | * @param post the string containing the XML request |
---|
| 1470 | * @param request_inputs the map storing KVP raw value |
---|
| 1471 | * @param s the service |
---|
| 1472 | * @param inputs the maps to store the KVP pairs |
---|
| 1473 | * @param outputs the maps to store the KVP pairs |
---|
| 1474 | * @param hInternet the HINTERNET queue to add potential requests |
---|
| 1475 | * @return 0 on success, -1 on failure |
---|
| 1476 | * @see kvpParseOutputs,kvpParseInputs,xmlParseRequest |
---|
| 1477 | */ |
---|
| 1478 | int parseRequest(maps** main_conf,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){ |
---|
| 1479 | map *postRequest = NULL; |
---|
| 1480 | postRequest = getMap (*request_inputs, "xrequest"); |
---|
| 1481 | if (postRequest == NULLMAP) |
---|
| 1482 | { |
---|
| 1483 | if(kvpParseOutputs(main_conf,*request_inputs,outputs)<0){ |
---|
| 1484 | return -1; |
---|
| 1485 | } |
---|
| 1486 | if(kvpParseInputs(main_conf,s,*request_inputs,inputs,hInternet)<0){ |
---|
| 1487 | return -1; |
---|
| 1488 | } |
---|
| 1489 | } |
---|
| 1490 | else |
---|
| 1491 | { |
---|
| 1492 | //Parse XML request |
---|
| 1493 | if(xmlParseRequest(main_conf,postRequest->value,request_inputs,s,inputs,outputs,hInternet)<0){ |
---|
| 1494 | return -1; |
---|
| 1495 | } |
---|
| 1496 | } |
---|
| 1497 | return 1; |
---|
| 1498 | } |
---|
| 1499 | |
---|
| 1500 | /** |
---|
| 1501 | * Ensure that each requested arguments are present in the request |
---|
| 1502 | * DataInputs and ResponseDocument / RawDataOutput. Potentially run |
---|
| 1503 | * http requests from the queue in parallel. |
---|
| 1504 | * For optional inputs add default values defined in the ZCFG file. |
---|
| 1505 | * |
---|
| 1506 | * @param main_conf |
---|
| 1507 | * @param s |
---|
| 1508 | * @param original_request |
---|
| 1509 | * @param request_inputs |
---|
| 1510 | * @param request_outputs |
---|
| 1511 | * @param hInternet |
---|
| 1512 | * |
---|
| 1513 | * @see runHttpRequests |
---|
| 1514 | */ |
---|
| 1515 | int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet){ |
---|
| 1516 | |
---|
[797] | 1517 | map* errI0=NULL; |
---|
| 1518 | runHttpRequests (main_conf, request_inputs, hInternet,&errI0); |
---|
| 1519 | if(errI0!=NULL){ |
---|
| 1520 | printExceptionReportResponse (*main_conf, errI0); |
---|
| 1521 | InternetCloseHandle (hInternet); |
---|
| 1522 | return -1; |
---|
| 1523 | } |
---|
[621] | 1524 | InternetCloseHandle (hInternet); |
---|
| 1525 | |
---|
[797] | 1526 | |
---|
[621] | 1527 | map* errI=NULL; |
---|
| 1528 | char *dfv = addDefaultValues (request_inputs, s->inputs, *main_conf, 0,&errI); |
---|
| 1529 | |
---|
| 1530 | maps *ptr = *request_inputs; |
---|
| 1531 | while (ptr != NULL) |
---|
| 1532 | { |
---|
| 1533 | map *tmp0 = getMap (ptr->content, "size"); |
---|
| 1534 | map *tmp1 = getMap (ptr->content, "maximumMegabytes"); |
---|
| 1535 | if (tmp1 != NULL && tmp0 != NULL) |
---|
| 1536 | { |
---|
| 1537 | float i = atof (tmp0->value) / 1048576.0; |
---|
| 1538 | if (i >= atoi (tmp1->value)) |
---|
| 1539 | { |
---|
| 1540 | char tmps[1024]; |
---|
| 1541 | map *tmpe = createMap ("code", "FileSizeExceeded"); |
---|
| 1542 | snprintf (tmps, 1024, |
---|
| 1543 | _ |
---|
| 1544 | ("The <%s> parameter has a size limit (%s MB) defined in the ZOO ServicesProvider configuration file, but the reference you provided exceeds this limit (%f MB)."), |
---|
| 1545 | ptr->name, tmp1->value, i); |
---|
| 1546 | addToMap (tmpe, "locator", ptr->name); |
---|
| 1547 | addToMap (tmpe, "text", tmps); |
---|
| 1548 | printExceptionReportResponse (*main_conf, tmpe); |
---|
| 1549 | freeMap (&tmpe); |
---|
| 1550 | free (tmpe); |
---|
| 1551 | return -1; |
---|
| 1552 | } |
---|
| 1553 | } |
---|
| 1554 | ptr = ptr->next; |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | map* errO=NULL; |
---|
| 1558 | char *dfv1 = |
---|
| 1559 | addDefaultValues (request_outputs, s->outputs, *main_conf, 1,&errO); |
---|
[790] | 1560 | |
---|
[621] | 1561 | if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0) |
---|
| 1562 | { |
---|
| 1563 | char tmps[1024]; |
---|
| 1564 | map *tmpe = NULL; |
---|
| 1565 | if (strcmp (dfv, "") != 0) |
---|
| 1566 | { |
---|
| 1567 | tmpe = createMap ("code", "MissingParameterValue"); |
---|
| 1568 | int nb=0; |
---|
| 1569 | int length=1; |
---|
| 1570 | map* len=getMap(errI,"length"); |
---|
| 1571 | if(len!=NULL) |
---|
| 1572 | length=atoi(len->value); |
---|
| 1573 | for(nb=0;nb<length;nb++){ |
---|
| 1574 | map* errp=getMapArray(errI,"value",nb); |
---|
| 1575 | snprintf (tmps, 1024, |
---|
| 1576 | _ |
---|
| 1577 | ("The <%s> argument was not specified in DataInputs but is required according to the ZOO ServicesProvider configuration file."), |
---|
| 1578 | errp->value); |
---|
| 1579 | setMapArray (tmpe, "locator", nb , errp->value); |
---|
| 1580 | setMapArray (tmpe, "text", nb , tmps); |
---|
| 1581 | setMapArray (tmpe, "code", nb , "MissingParameterValue"); |
---|
| 1582 | } |
---|
| 1583 | } |
---|
| 1584 | if (strcmp (dfv1, "") != 0) |
---|
| 1585 | { |
---|
| 1586 | int ilength=0; |
---|
| 1587 | if(tmpe==NULL) |
---|
| 1588 | tmpe = createMap ("code", "InvalidParameterValue"); |
---|
| 1589 | else{ |
---|
| 1590 | map* len=getMap(tmpe,"length"); |
---|
| 1591 | if(len!=NULL) |
---|
| 1592 | ilength=atoi(len->value); |
---|
| 1593 | } |
---|
| 1594 | int nb=0; |
---|
| 1595 | int length=1; |
---|
| 1596 | map* len=getMap(errO,"length"); |
---|
| 1597 | if(len!=NULL) |
---|
| 1598 | length=atoi(len->value); |
---|
| 1599 | for(nb=0;nb<length;nb++){ |
---|
| 1600 | map* errp=getMapArray(errO,"value",nb); |
---|
| 1601 | snprintf (tmps, 1024, |
---|
| 1602 | _ |
---|
| 1603 | ("The <%s> argument specified as %s identifier was not recognized (not defined in the ZOO Configuration File)."), |
---|
| 1604 | errp->value, |
---|
| 1605 | ((getMap(original_request,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument")); |
---|
| 1606 | setMapArray (tmpe, "locator", nb+ilength , errp->value); |
---|
| 1607 | setMapArray (tmpe, "text", nb+ilength , tmps); |
---|
| 1608 | setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue"); |
---|
| 1609 | } |
---|
| 1610 | } |
---|
| 1611 | printExceptionReportResponse (*main_conf, tmpe); |
---|
| 1612 | if(errI!=NULL){ |
---|
| 1613 | freeMap(&errI); |
---|
| 1614 | free(errI); |
---|
| 1615 | } |
---|
| 1616 | if(errO!=NULL){ |
---|
| 1617 | freeMap(&errO); |
---|
| 1618 | free(errO); |
---|
| 1619 | } |
---|
| 1620 | freeMap (&tmpe); |
---|
| 1621 | free (tmpe); |
---|
| 1622 | return -1; |
---|
| 1623 | } |
---|
| 1624 | maps *tmpReqI = *request_inputs; |
---|
| 1625 | while (tmpReqI != NULL) |
---|
| 1626 | { |
---|
| 1627 | char name[1024]; |
---|
| 1628 | if (getMap (tmpReqI->content, "isFile") != NULL) |
---|
| 1629 | { |
---|
| 1630 | if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) == |
---|
| 1631 | cgiFormSuccess) |
---|
| 1632 | { |
---|
| 1633 | int BufferLen = 1024; |
---|
| 1634 | cgiFilePtr file; |
---|
| 1635 | int targetFile; |
---|
[794] | 1636 | char *storageNameOnServer; |
---|
| 1637 | char *fileNameOnServer; |
---|
[621] | 1638 | char contentType[1024]; |
---|
| 1639 | char buffer[1024]; |
---|
| 1640 | char *tmpStr = NULL; |
---|
| 1641 | int size; |
---|
| 1642 | int got, t; |
---|
| 1643 | map *path = getMapFromMaps (*main_conf, "main", "tmpPath"); |
---|
| 1644 | cgiFormFileSize (tmpReqI->name, &size); |
---|
| 1645 | cgiFormFileContentType (tmpReqI->name, contentType, |
---|
| 1646 | sizeof (contentType)); |
---|
| 1647 | if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess) |
---|
| 1648 | { |
---|
| 1649 | t = -1; |
---|
| 1650 | while (1) |
---|
| 1651 | { |
---|
| 1652 | tmpStr = strstr (name + t + 1, "\\"); |
---|
| 1653 | if (NULL == tmpStr) |
---|
| 1654 | tmpStr = strstr (name + t + 1, "/"); |
---|
| 1655 | if (NULL != tmpStr) |
---|
| 1656 | t = (int) (tmpStr - name); |
---|
| 1657 | else |
---|
| 1658 | break; |
---|
| 1659 | } |
---|
[794] | 1660 | fileNameOnServer=(char*)malloc((strlen(name) - t - 1 )*sizeof(char)); |
---|
[621] | 1661 | strcpy (fileNameOnServer, name + t + 1); |
---|
| 1662 | |
---|
[794] | 1663 | storageNameOnServer=(char*)malloc((strlen(path->value) + strlen(fileNameOnServer) + 2)*sizeof(char)); |
---|
[621] | 1664 | sprintf (storageNameOnServer, "%s/%s", path->value, |
---|
| 1665 | fileNameOnServer); |
---|
| 1666 | #ifdef DEBUG |
---|
| 1667 | fprintf (stderr, "Name on server %s\n", |
---|
| 1668 | storageNameOnServer); |
---|
| 1669 | fprintf (stderr, "fileNameOnServer: %s\n", |
---|
| 1670 | fileNameOnServer); |
---|
| 1671 | #endif |
---|
| 1672 | targetFile = |
---|
| 1673 | open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, |
---|
| 1674 | S_IRWXU | S_IRGRP | S_IROTH); |
---|
| 1675 | if (targetFile < 0) |
---|
| 1676 | { |
---|
| 1677 | #ifdef DEBUG |
---|
| 1678 | fprintf (stderr, "could not create the new file,%s\n", |
---|
| 1679 | fileNameOnServer); |
---|
| 1680 | #endif |
---|
| 1681 | } |
---|
| 1682 | else |
---|
| 1683 | { |
---|
| 1684 | while (cgiFormFileRead (file, buffer, BufferLen, &got) |
---|
| 1685 | == cgiFormSuccess) |
---|
| 1686 | { |
---|
| 1687 | if (got > 0) |
---|
| 1688 | write (targetFile, buffer, got); |
---|
| 1689 | } |
---|
| 1690 | } |
---|
| 1691 | addToMap (tmpReqI->content, "lref", storageNameOnServer); |
---|
| 1692 | cgiFormFileClose (file); |
---|
| 1693 | close (targetFile); |
---|
[794] | 1694 | free(fileNameOnServer); |
---|
| 1695 | free(storageNameOnServer); |
---|
[621] | 1696 | #ifdef DEBUG |
---|
| 1697 | fprintf (stderr, "File \"%s\" has been uploaded", |
---|
| 1698 | fileNameOnServer); |
---|
| 1699 | #endif |
---|
| 1700 | } |
---|
| 1701 | } |
---|
| 1702 | } |
---|
| 1703 | tmpReqI = tmpReqI->next; |
---|
| 1704 | } |
---|
| 1705 | |
---|
| 1706 | ensureDecodedBase64 (request_inputs); |
---|
| 1707 | return 1; |
---|
| 1708 | } |
---|
[640] | 1709 | |
---|
| 1710 | |
---|
| 1711 | /** |
---|
| 1712 | * Verify if a parameter value is valid. |
---|
| 1713 | * |
---|
| 1714 | * @param request the request map |
---|
| 1715 | * @param res the error map potentially generated |
---|
| 1716 | * @param toCheck the parameter to use |
---|
| 1717 | * @param avalues the acceptable values (or null if testing only for presence) |
---|
| 1718 | * @param mandatory verify the presence of the parameter if mandatory > 0 |
---|
| 1719 | */ |
---|
| 1720 | void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){ |
---|
| 1721 | map* lres=*res; |
---|
| 1722 | map* r_inputs = getMap (request,toCheck); |
---|
| 1723 | if (r_inputs == NULL){ |
---|
| 1724 | if(mandatory>0){ |
---|
| 1725 | char *replace=_("Mandatory parameter <%s> was not specified"); |
---|
| 1726 | char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char)); |
---|
| 1727 | sprintf(message,replace,toCheck); |
---|
| 1728 | if(lres==NULL){ |
---|
| 1729 | lres=createMap("code","MissingParameterValue"); |
---|
| 1730 | addToMap(lres,"text",message); |
---|
| 1731 | addToMap(lres,"locator",toCheck); |
---|
| 1732 | }else{ |
---|
| 1733 | int length=1; |
---|
| 1734 | map* len=getMap(lres,"length"); |
---|
| 1735 | if(len!=NULL){ |
---|
| 1736 | length=atoi(len->value); |
---|
| 1737 | } |
---|
| 1738 | setMapArray(lres,"text",length,message); |
---|
| 1739 | setMapArray(lres,"locator",length,toCheck); |
---|
[756] | 1740 | setMapArray(lres,"code",length,"MissingParameterValue"); |
---|
[640] | 1741 | } |
---|
| 1742 | free(message); |
---|
| 1743 | } |
---|
| 1744 | }else{ |
---|
| 1745 | if(avalues==NULL) |
---|
| 1746 | return; |
---|
| 1747 | int nb=0; |
---|
| 1748 | int hasValidValue=-1; |
---|
| 1749 | if(strncasecmp(toCheck,"Accept",6)==0){ |
---|
| 1750 | char *tmp=zStrdup(r_inputs->value); |
---|
| 1751 | char *pToken,*saveptr; |
---|
| 1752 | pToken=strtok_r(tmp,",",&saveptr); |
---|
| 1753 | while(pToken!=NULL){ |
---|
| 1754 | while(avalues[nb]!=NULL){ |
---|
| 1755 | if(strcasecmp(avalues[nb],pToken)==0){ |
---|
| 1756 | hasValidValue=1; |
---|
| 1757 | break; |
---|
| 1758 | } |
---|
| 1759 | nb++; |
---|
| 1760 | } |
---|
| 1761 | pToken=strtok_r(NULL,",",&saveptr); |
---|
| 1762 | } |
---|
| 1763 | free(tmp); |
---|
| 1764 | }else{ |
---|
| 1765 | while(avalues[nb]!=NULL){ |
---|
| 1766 | if(strcasecmp(avalues[nb],r_inputs->value)==0){ |
---|
| 1767 | hasValidValue=1; |
---|
| 1768 | break; |
---|
| 1769 | } |
---|
| 1770 | nb++; |
---|
| 1771 | } |
---|
| 1772 | } |
---|
| 1773 | if(hasValidValue<0){ |
---|
| 1774 | char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value."); |
---|
| 1775 | nb=0; |
---|
| 1776 | char *vvalues=NULL; |
---|
| 1777 | char* num=_("is"); |
---|
| 1778 | while(avalues[nb]!=NULL){ |
---|
| 1779 | char *tvalues; |
---|
| 1780 | if(vvalues==NULL){ |
---|
| 1781 | vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char)); |
---|
| 1782 | sprintf(vvalues,"%s",avalues[nb]); |
---|
| 1783 | } |
---|
| 1784 | else{ |
---|
| 1785 | tvalues=zStrdup(vvalues); |
---|
| 1786 | vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char)); |
---|
| 1787 | sprintf(vvalues,"%s, %s",tvalues,avalues[nb]); |
---|
| 1788 | free(tvalues); |
---|
| 1789 | num=_("are"); |
---|
| 1790 | } |
---|
| 1791 | nb++; |
---|
| 1792 | } |
---|
| 1793 | char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char)); |
---|
| 1794 | sprintf(message,replace,toCheck,vvalues,num); |
---|
| 1795 | const char *code="VersionNegotiationFailed"; |
---|
| 1796 | code="InvalidParameterValue"; |
---|
| 1797 | const char *locator=toCheck; |
---|
| 1798 | if( strncasecmp(toCheck,"version",7)==0 || |
---|
| 1799 | strncasecmp(toCheck,"AcceptVersions",14)==0 ) |
---|
| 1800 | code="VersionNegotiationFailed"; |
---|
| 1801 | if( strncasecmp(toCheck,"request",7)==0){ |
---|
| 1802 | code="OperationNotSupported"; |
---|
| 1803 | locator=r_inputs->value; |
---|
| 1804 | } |
---|
| 1805 | if(lres==NULL){ |
---|
[756] | 1806 | lres=createMap("code",code); |
---|
[640] | 1807 | addToMap(lres,"text",message); |
---|
| 1808 | addToMap(lres,"locator",locator); |
---|
| 1809 | }else{ |
---|
| 1810 | int length=1; |
---|
| 1811 | map* len=getMap(lres,"length"); |
---|
| 1812 | if(len!=NULL){ |
---|
| 1813 | length=atoi(len->value); |
---|
| 1814 | } |
---|
| 1815 | setMapArray(lres,"text",length,message); |
---|
| 1816 | setMapArray(lres,"locator",length,locator); |
---|
[756] | 1817 | setMapArray(lres,"code",length,code); |
---|
[640] | 1818 | } |
---|
| 1819 | } |
---|
| 1820 | } |
---|
| 1821 | if(lres!=NULL){ |
---|
| 1822 | *res=lres; |
---|
| 1823 | } |
---|
| 1824 | } |
---|