source: trunk/zoo-project/zoo-kernel/server_internal.c @ 653

Last change on this file since 653 was 653, checked in by djay, 9 years ago

Small fixes for building on GNU/Linux.

  • Property svn:keywords set to Id
File size: 20.9 KB
Line 
1/*
2 * Author : Gérald Fenoy
3 *
4 *  Copyright 2008-2015 GeoLabs SARL. All rights reserved.
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 "server_internal.h"
26#include "response_print.h"
27#include "mimetypes.h"
28#ifndef WIN32
29#include <dlfcn.h>
30#endif
31#include <uuid/uuid.h>
32
33/**
34 * Detect WPS version used (1.0.0 or 2.0.0).
35 *
36 * @param version number as char* (1.0.0 or 2.0.0)
37 * @return 0 in case of version 1.0.0, 1 for 2.0.0, -1 in other case
38 */
39int getVersionId(const char* version){
40  int schemaId=0;
41  for(;schemaId<2;schemaId++){
42    if(strncasecmp(version,schemas[schemaId][0],5)==0)
43      return schemaId;
44  }
45  return -1;
46}
47
48/**
49 * Generate a UUID.
50 * ref: https://www.ietf.org/rfc/rfc4122.txt / 4.2
51 *
52 * @return a new char* containing the UUID, make sure to free the returned
53 *  ressource once used.
54 */
55char *get_uuid(){
56  char *res=(char*)malloc(37*sizeof(char));
57  uuid_t uuid;
58  uuid_generate_time(uuid);
59  char rest[128];
60  uuid_unparse(uuid,rest);
61  sprintf(res,"%s", rest);
62  return res;
63}
64
65/**
66 * Extract the service identifier from the full service identifier
67 * ie:
68 *  - Full service name: OTB.BandMath
69 *  - Service name: BandMath
70 *
71 * @param conf the maps containing the settings of the main.cfg file
72 * @param conf_dir the full path to the ZOO-Kernel directory
73 * @param identifier the full service name (potentialy including a prefix, ie:
74 *  Prefix.MyService)
75 * @param buffer the resulting service identifier (without any prefix)
76 */
77void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){
78  setMapInMaps(conf,"lenv","oIdentifier",identifier);
79  char *lid=zStrdup(identifier);
80  char *saveptr1;
81  char *tmps1=strtok_r(lid,".",&saveptr1);
82  int level=0;
83  char key[25];
84  char levels[18];
85  while(tmps1!=NULL){
86    char *test=zStrdup(tmps1);
87    char* tmps2=(char*)malloc((strlen(test)+2)*sizeof(char));
88    sprintf(key,"sprefix_%d",level);
89    sprintf(tmps2,"%s.",test);
90    sprintf(levels,"%d",level);
91    setMapInMaps(conf,"lenv","level",levels);
92    setMapInMaps(conf,"lenv",key,tmps2);
93    free(tmps2);
94    free(test);
95    level++;
96    tmps1=strtok_r(NULL,".",&saveptr1);
97  }
98  int i=0;
99  sprintf(buffer,"%s",conf_dir);
100  for(i=0;i<level;i++){
101    char *tmp0=zStrdup(buffer);
102    sprintf(key,"sprefix_%d",i);
103    map* tmp00=getMapFromMaps(conf,"lenv",key);
104    if(tmp00!=NULL)
105      sprintf(buffer,"%s/%s",tmp0,tmp00->value);
106    free(tmp0);
107    buffer[strlen(buffer)-1]=0;
108    if(i+1<level){ 
109      #ifdef IGNORE_METAPATH
110        map* tmpMap = createMap("metapath", "");
111      #else 
112        map* tmpMap=getMapFromMaps(conf,"lenv","metapath");
113      #endif     
114      if(tmpMap==NULL || strlen(tmpMap->value)==0){
115        char *tmp01=zStrdup(tmp00->value);
116        tmp01[strlen(tmp01)-1]=0;
117        setMapInMaps(conf,"lenv","metapath",tmp01);
118        free(tmp01);
119        tmp01=NULL;
120      }
121      else{
122        if(tmp00!=NULL && tmpMap!=NULL){
123          char *tmp00s=zStrdup(tmp00->value);
124          tmp00s[strlen(tmp00s)-1]=0;
125          char *value=(char*)malloc((strlen(tmp00s)+strlen(tmpMap->value)+2)*sizeof(char));
126          sprintf(value,"%s/%s",tmpMap->value,tmp00s);
127          setMapInMaps(conf,"lenv","metapath",value);
128          free(value);
129          free(tmp00s);
130          value=NULL;
131        }
132      }
133    }else{
134      char *tmp01=zStrdup(tmp00->value);
135      tmp01[strlen(tmp01)-1]=0;
136      setMapInMaps(conf,"lenv","Identifier",tmp01);
137      free(tmp01);
138    }
139  }
140  char *tmp0=zStrdup(buffer);
141  sprintf(buffer,"%s.zcfg",tmp0);
142  free(tmp0);
143  free(lid);
144}
145
146/**
147 * Converts a hex character to its integer value
148 *
149 * @param ch the char to convert
150 * @return the converted char
151 */
152char from_hex(char ch) {
153  return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
154}
155
156/**
157 * Converts an integer value to its hec character
158 *
159 * @param code the char to convert
160 * @return the converted char
161 */
162char to_hex(char code) {
163  static char hex[] = "0123456789abcdef";
164  return hex[code & 15];
165}
166
167/**
168 * URLEncode an url
169 *
170 * @param str the url to encode
171 * @return a url-encoded version of str
172 * @warning be sure to free() the returned string after use
173 */
174char *url_encode(char *str) {
175  char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf;
176  while (*pstr) {
177    if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') 
178      *pbuf++ = *pstr;
179    else if (*pstr == ' ') 
180      *pbuf++ = '+';
181    else 
182      *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
183    pstr++;
184  }
185  *pbuf = '\0';
186  return buf;
187}
188
189/**
190 * Decode an URLEncoded url
191 *
192 * @param str the URLEncoded url to decode
193 * @return a url-decoded version of str
194 * @warning be sure to free() the returned string after use
195 */
196char *url_decode(char *str) {
197  char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf;
198  while (*pstr) {
199    if (*pstr == '%') {
200      if (pstr[1] && pstr[2]) {
201        *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
202        pstr += 2;
203      }
204    } else if (*pstr == '+') { 
205      *pbuf++ = ' ';
206    } else {
207      *pbuf++ = *pstr;
208    }
209    pstr++;
210  }
211  *pbuf = '\0';
212  return buf;
213}
214
215/**
216 * Verify if a given language is listed in the lang list defined in the [main]
217 * section of the main.cfg file.
218 *
219 * @param conf the map containing the settings from the main.cfg file
220 * @param str the specific language
221 * @return 1 if the specific language is listed, -1 in other case.
222 */
223int isValidLang(maps* conf,const char *str){
224  map *tmpMap=getMapFromMaps(conf,"main","lang");
225  char *tmp=zStrdup(tmpMap->value);
226  char *pToken,*saveptr;
227  pToken=strtok_r(tmp,",",&saveptr);
228  int res=-1;
229  char *pToken1,*saveptr1;
230  pToken1=strtok_r(tmp,",",&saveptr1);
231  while(pToken1!=NULL){
232    while(pToken!=NULL){
233      if(strcasecmp(pToken1,pToken)==0){
234        res=1;
235        break;
236      }
237      pToken=strtok_r(NULL,",",&saveptr);
238    }
239    pToken1=strtok_r(NULL,",",&saveptr1);
240  }
241  free(tmp);
242  return res;
243}
244
245
246/**
247 * Access the value of the encoding key in a maps
248 *
249 * @param m the maps to search for the encoding key
250 * @return the value of the encoding key in a maps if encoding key exists,
251 *  "UTF-8" in other case.
252 */
253char* getEncoding(maps* m){
254  if(m!=NULL){
255    map* tmp=getMap(m->content,"encoding");
256    if(tmp!=NULL){
257      return tmp->value;
258    }
259    else
260      return (char*)"UTF-8";
261  }
262  else
263    return (char*)"UTF-8"; 
264}
265
266/**
267 * Access the value of the version key in a maps
268 *
269 * @param m the maps to search for the version key
270 * @return the value of the version key in a maps if encoding key exists,
271 *  "1.0.0" in other case.
272 */
273char* getVersion(maps* m){
274  if(m!=NULL){
275    map* tmp=getMap(m->content,"version");
276    if(tmp!=NULL){
277      return tmp->value;
278    }
279    else
280      return (char*)"1.0.0";
281  }
282  else
283    return (char*)"1.0.0";
284}
285
286/**
287 * Read a file generated by a service.
288 *
289 * @param m the conf maps
290 * @param content the output item
291 * @param filename the file to read
292 */
293void readGeneratedFile(maps* m,map* content,char* filename){
294  FILE * file=fopen(filename,"rb");
295  if(file==NULL){
296    fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);
297    setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later");
298    return ;
299  }
300  fseek(file, 0, SEEK_END);
301  long count = ftell(file);
302  rewind(file);
303  struct stat file_status; 
304  stat(filename, &file_status);
305  map* tmpMap1=getMap(content,"value");
306  if(tmpMap1==NULL){
307    addToMap(content,"value","");
308    tmpMap1=getMap(content,"value");
309  }
310  free(tmpMap1->value);
311  tmpMap1->value=(char*) malloc((count+1)*sizeof(char)); 
312  fread(tmpMap1->value,1,count,file);
313  tmpMap1->value[count]=0;
314  fclose(file);
315  char rsize[1000];
316  sprintf(rsize,"%ld",count);
317  addToMap(content,"size",rsize);
318}
319
320
321/**
322 * Write a file from value and length
323 *
324 * @param fname the file name
325 * @param val the value
326 * @param length the value length
327 */
328int writeFile(char* fname,char* val,int length){
329  FILE* of=fopen(fname,"wb");
330  if(of==NULL){
331    return -1;
332  }
333  size_t ret=fwrite(val,sizeof(char),length,of);
334  if(ret<length){
335    fprintf(stderr,"Write error occured!\n");
336    fclose(of);
337    return -1;
338  }
339  fclose(of);
340  return 1;
341}
342
343/**
344 * Dump all values in a maps as files
345 *
346 * @param main_conf the maps containing the settings of the main.cfg file
347 * @param in the maps containing values to dump as files
348 */
349void dumpMapsValuesToFiles(maps** main_conf,maps** in){
350  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
351  map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid");
352  maps* inputs=*in;
353  int length=0;
354  while(inputs!=NULL){
355    if(getMap(inputs->content,"mimeType")!=NULL &&
356       getMap(inputs->content,"cache_file")==NULL){
357      map* cMap=inputs->content;
358      if(getMap(cMap,"length")!=NULL){
359        map* tmpLength=getMap(cMap,"length");
360        int len=atoi(tmpLength->value);
361        int k=0;
362        for(k=0;k<len;k++){
363          map* cMimeType=getMapArray(cMap,"mimeType",k);
364          map* cValue=getMapArray(cMap,"value",k);
365          map* cSize=getMapArray(cMap,"size",k);
366          char file_ext[32];
367          getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
368          char* val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
369          sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,k,file_ext);
370          length=0;
371          if(cSize!=NULL){
372            length=atoi(cSize->value);
373          }
374          writeFile(val,cValue->value,length);
375          setMapArray(cMap,"cache_file",k,val);
376          free(val);
377        }
378      }else{
379        int length=0;
380        map* cMimeType=getMap(cMap,"mimeType");
381        map* cValue=getMap(cMap,"value");
382        map* cSize=getMap(cMap,"size");
383        char file_ext[32];
384        getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
385        char *val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
386        sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,0,file_ext);
387        if(cSize!=NULL){
388          length=atoi(cSize->value);
389        }
390        writeFile(val,cValue->value,length);
391        addToMap(cMap,"cache_file",val);
392        free(val);
393      }
394    }
395    inputs=inputs->next;
396  }
397}
398
399
400/**
401 * Base64 encoding of a char*
402 *
403 * @param input the value to encode
404 * @param length the value length
405 * @return the buffer containing the base64 value
406 * @warning make sure to free the returned value
407 */
408char *base64(const char *input, int length)
409{
410  BIO *bmem, *b64;
411  BUF_MEM *bptr;
412
413  b64 = BIO_new(BIO_f_base64());
414  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
415  bmem = BIO_new(BIO_s_mem());
416  b64 = BIO_push(b64, bmem);
417  BIO_write(b64, input, length);
418  BIO_flush(b64);
419  BIO_get_mem_ptr(b64, &bptr);
420
421  char *buff = (char *)malloc((bptr->length+1)*sizeof(char));
422  memcpy(buff, bptr->data, bptr->length);
423  buff[bptr->length] = 0;
424
425  BIO_free_all(b64);
426
427  return buff;
428}
429
430/**
431 * Base64 decoding of a char*
432 *
433 * @param input the value to decode
434 * @param length the value length
435 * @param red the value length
436 * @return the buffer containing the base64 value
437 * @warning make sure to free the returned value
438 */
439char *base64d(const char *input, int length,int* red)
440{
441  BIO *b64, *bmem;
442
443  char *buffer = (char *)malloc(length);
444  if(buffer){
445    memset(buffer, 0, length);
446    b64 = BIO_new(BIO_f_base64());
447    if(b64){
448      bmem = BIO_new_mem_buf((unsigned char*)input,length);
449      bmem = BIO_push(b64, bmem);
450      *red=BIO_read(bmem, buffer, length);
451      buffer[length-1]=0;
452      BIO_free_all(bmem);
453    }
454  }
455  return buffer;
456}
457
458/**
459 * Read Base64 value and split it value by lines of 64 char.
460 *
461 * @param in the map containing the value to split
462 */
463void readBase64(map **in){
464  char *res = NULL;
465  char *curs = (*in)->value;
466  int i = 0;
467  for (i = 0; i <= strlen ((*in)->value) / 64;
468       i++)
469    {
470      if (res == NULL)
471        res =
472          (char *) malloc (65 * sizeof (char));
473      else
474        res =
475          (char *) realloc (res,
476                            (((i + 1) * 65) +
477                             i) * sizeof (char));
478      int csize = i * 65;
479      strncpy (res + csize, curs, 64);
480      if (i == strlen ((*in)->value) / 64)
481        strcat (res, "\n\0");
482      else
483        {
484          strncpy (res + (((i + 1) * 64) + i),
485                   "\n\0", 2);
486          curs += 64;
487        }
488    }
489  free ((*in)->value);
490  (*in)->value = zStrdup (res);
491  free (res);
492}
493
494
495/**
496 * Add the default values defined in the zcfg to a maps.
497 *
498 * @param out the maps containing the inputs or outputs given in the initial
499 *  HTTP request
500 * @param in the description of all inputs or outputs available for a service
501 * @param m the maps containing the settings of the main.cfg file
502 * @param type 0 for inputs and 1 for outputs
503 * @param err the map to store potential missing mandatory input parameters or
504 *  wrong output names depending on the type.
505 * @return "" if no error was detected, the name of last input or output causing
506 *  an error.
507 */
508char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){
509  map *res=*err;
510  elements* tmpInputs=in;
511  maps* out1=*out;
512  char *result=NULL;
513  int nb=0;
514  if(type==1){
515    while(out1!=NULL){
516      if(getElements(in,out1->name)==NULL){
517        if(res==NULL){
518          res=createMap("value",out1->name);
519        }else{
520          setMapArray(res,"value",nb,out1->name);
521        }
522        nb++;
523        result=out1->name;
524      }
525      out1=out1->next;
526    }
527    if(res!=NULL){
528      *err=res;
529      return result;
530    }
531    out1=*out;
532  }
533  while(tmpInputs!=NULL){
534    maps *tmpMaps=getMaps(out1,tmpInputs->name);
535    if(tmpMaps==NULL){
536      maps* tmpMaps2=(maps*)malloc(MAPS_SIZE);
537      tmpMaps2->name=strdup(tmpInputs->name);
538      tmpMaps2->content=NULL;
539      tmpMaps2->next=NULL;
540     
541      if(type==0){
542        map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs");
543        if(tmpMapMinO!=NULL){
544          if(atoi(tmpMapMinO->value)>=1){
545            freeMaps(&tmpMaps2);
546            free(tmpMaps2);
547            if(res==NULL){
548              res=createMap("value",tmpInputs->name);
549            }else{
550              setMapArray(res,"value",nb,tmpInputs->name);
551            }
552            nb++;
553            result=tmpInputs->name;
554          }
555          else{
556            if(tmpMaps2->content==NULL)
557              tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value);
558            else
559              addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value);
560          }
561        }
562        if(res==NULL){
563          map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
564          if(tmpMaxO!=NULL){
565            if(tmpMaps2->content==NULL)
566              tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value);
567            else
568              addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value);
569          }
570          map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
571          if(tmpMaxMB!=NULL){
572            if(tmpMaps2->content==NULL)
573              tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value);
574            else
575              addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value);
576          }
577        }
578      }
579
580      if(res==NULL){
581        iotype* tmpIoType=tmpInputs->defaults;
582        if(tmpIoType!=NULL){
583          map* tmpm=tmpIoType->content;
584          while(tmpm!=NULL){
585            if(tmpMaps2->content==NULL)
586              tmpMaps2->content=createMap(tmpm->name,tmpm->value);
587            else
588              addToMap(tmpMaps2->content,tmpm->name,tmpm->value);
589            tmpm=tmpm->next;
590          }
591        }
592        addToMap(tmpMaps2->content,"inRequest","false");
593        if(type==0){
594          map *tmpMap=getMap(tmpMaps2->content,"value");
595          if(tmpMap==NULL)
596            addToMap(tmpMaps2->content,"value","NULL");
597        }
598        if(out1==NULL){
599          *out=dupMaps(&tmpMaps2);
600          out1=*out;
601        }
602        else
603          addMapsToMaps(&out1,tmpMaps2);
604        freeMap(&tmpMaps2->content);
605        free(tmpMaps2->content);
606        tmpMaps2->content=NULL;
607        freeMaps(&tmpMaps2);
608        free(tmpMaps2);
609        tmpMaps2=NULL;
610      }
611    }
612    else{
613      iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,
614                                             tmpMaps->content);
615      if(type==0) {
616        /**
617         * In case of an Input maps, then add the minOccurs and maxOccurs to the
618         * content map.
619         */
620        map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
621        if(tmpMap1!=NULL){
622          if(tmpMaps->content==NULL)
623            tmpMaps->content=createMap("minOccurs",tmpMap1->value);
624          else
625            addToMap(tmpMaps->content,"minOccurs",tmpMap1->value);
626        }
627        map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
628        if(tmpMaxO!=NULL){
629          if(tmpMaps->content==NULL)
630            tmpMaps->content=createMap("maxOccurs",tmpMaxO->value);
631          else
632            addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value);
633        }
634        map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
635        if(tmpMaxMB!=NULL){
636          if(tmpMaps->content==NULL)
637            tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
638          else
639            addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
640        }
641        /**
642         * Parsing BoundingBoxData, fill the following map and then add it to
643         * the content map of the Input maps:
644         * lowerCorner, upperCorner, srs and dimensions
645         * cf. parseBoundingBox
646         */
647        if(tmpInputs->format!=NULL && strcasecmp(tmpInputs->format,"BoundingBoxData")==0){
648          maps* tmpI=getMaps(*out,tmpInputs->name);
649          if(tmpI!=NULL){
650            map* tmpV=getMap(tmpI->content,"value");
651            if(tmpV!=NULL){
652              char *tmpVS=strdup(tmpV->value);
653              map* tmp=parseBoundingBox(tmpVS);
654              free(tmpVS);
655              map* tmpC=tmp;
656              while(tmpC!=NULL){
657                addToMap(tmpMaps->content,tmpC->name,tmpC->value);
658                tmpC=tmpC->next;
659              }
660              freeMap(&tmp);
661              free(tmp);
662            }
663          }
664        }
665      }
666
667      if(tmpIoType!=NULL){
668        map* tmpContent=tmpIoType->content;
669        map* cval=NULL;
670        int hasPassed=-1;
671        while(tmpContent!=NULL){
672          if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){
673#ifdef DEBUG
674            fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value);
675#endif
676            if(tmpMaps->content==NULL)
677              tmpMaps->content=createMap(tmpContent->name,tmpContent->value);
678            else
679              addToMap(tmpMaps->content,tmpContent->name,tmpContent->value);
680           
681            if(hasPassed<0 && type==0 && getMap(tmpMaps->content,"isArray")!=NULL){
682              map* length=getMap(tmpMaps->content,"length");
683              int i;
684              char *tcn=strdup(tmpContent->name);
685              for(i=1;i<atoi(length->value);i++){
686#ifdef DEBUG
687                dumpMap(tmpMaps->content);
688                fprintf(stderr,"addDefaultValues %s_%d => %s\n",tcn,i,tmpContent->value);
689#endif
690                int len=strlen((char*) tcn);
691                char *tmp1=(char *)malloc((len+10)*sizeof(char));
692                sprintf(tmp1,"%s_%d",tcn,i);
693#ifdef DEBUG
694                fprintf(stderr,"addDefaultValues %s => %s\n",tmp1,tmpContent->value);
695#endif
696                addToMap(tmpMaps->content,tmp1,tmpContent->value);
697                free(tmp1);
698                hasPassed=1;
699              }
700              free(tcn);
701            }
702          }
703          tmpContent=tmpContent->next;
704        }
705#ifdef USE_MS
706        /**
707         * check for useMapServer presence
708         */
709        map* tmpCheck=getMap(tmpIoType->content,"useMapServer");
710        if(tmpCheck!=NULL){
711          // Get the default value
712          tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL);
713          tmpCheck=getMap(tmpMaps->content,"mimeType");
714          addToMap(tmpMaps->content,"requestedMimeType",tmpCheck->value);
715          map* cursor=tmpIoType->content;
716          while(cursor!=NULL){
717            addToMap(tmpMaps->content,cursor->name,cursor->value);
718            cursor=cursor->next;
719          }
720         
721          cursor=tmpInputs->content;
722          while(cursor!=NULL){
723            if(strcasecmp(cursor->name,"Title")==0 ||
724               strcasecmp(cursor->name,"Abstract")==0)
725              addToMap(tmpMaps->content,cursor->name,cursor->value);
726           cursor=cursor->next;
727          }
728        }
729#endif
730      }
731      if(tmpMaps->content==NULL)
732        tmpMaps->content=createMap("inRequest","true");
733      else
734        addToMap(tmpMaps->content,"inRequest","true");
735
736    }
737    tmpInputs=tmpInputs->next;
738  }
739  if(res!=NULL){
740    *err=res;
741    return result;
742  }
743  return "";
744}
745
746/**
747 * Access the last error message returned by the OS when trying to dynamically
748 * load a shared library.
749 *
750 * @return the last error message
751 * @warning The character string returned from getLastErrorMessage resides
752 * in a static buffer. The application should not write to this
753 * buffer or attempt to free() it.
754 */ 
755char* getLastErrorMessage() {                                             
756#ifdef WIN32
757  LPVOID lpMsgBuf;
758  DWORD errCode = GetLastError();
759  static char msg[ERROR_MSG_MAX_LENGTH];
760  size_t i;
761 
762  DWORD length = FormatMessage(
763                               FORMAT_MESSAGE_ALLOCATE_BUFFER | 
764                               FORMAT_MESSAGE_FROM_SYSTEM |
765                               FORMAT_MESSAGE_IGNORE_INSERTS,
766                               NULL,
767                               errCode,
768                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
769                               (LPTSTR) &lpMsgBuf,
770                               0, NULL );       
771 
772#ifdef UNICODE         
773  wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
774              (wchar_t*) lpMsgBuf, _TRUNCATE );
775#else
776  strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
777            (char *) lpMsgBuf );               
778#endif 
779  LocalFree(lpMsgBuf);
780 
781  return msg;
782#else
783  return dlerror();
784#endif
785}
786
787
788
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png