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

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

Better concurrency gesture for asynchronous requests, add db backend support for status informations.

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