Changeset 967 for trunk/zoo-project
- Timestamp:
- Dec 18, 2020, 2:13:22 PM (4 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 1 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/HISTORY.txt
r966 r967 1 1 Version 1.8.0-dev 2 * Support raw response in OGC API - Processes 3 * Add a ZOO-API section to the howtos documentation 4 * OGC API - Processes support: 5 https://github.com/gfenoy/wps-rest-binding/tree/change-request/95 6 * Support two inputs/outputs syntaxes discussed (using json object 7 or array of json object) for ZOO-Kernel and the HTML client 2 8 * Fix issue in kvParseInput when memory!=load and handle session 3 9 from the OGC API - Processes -
trunk/zoo-project/zoo-kernel/Makefile.in
r962 r967 4 4 5 5 version.h: Makefile 6 echo "#define ZOO_VERSION \"1. 7.0`svnversion`\"" > version.h6 echo "#define ZOO_VERSION \"1.8.0-rc1 `svnversion`\"" > version.h 7 7 echo "@ETC_DEF@" >> version.h 8 8 echo "#define LOCALEDIR \"@localedir@\"" >> version.h … … 57 57 58 58 response_print.o: response_print.c response_print.h 59 g++ -fPIC ${ GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c59 g++ -fPIC ${JSON_CFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c 60 60 61 61 server_internal.o: server_internal.c server_internal.h service.h mimetypes.h -
trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in
r917 r967 4 4 INST_LIB=@libdir@ 5 5 INST_INCLUDE=@includedir@ 6 VERSION=1. 56 VERSION=1.8 7 7 REVISION=0 8 8 EXT=so -
trunk/zoo-project/zoo-kernel/configure.ac
r962 r967 1 AC_INIT([ZOO Kernel], [1. 7.0], [bugs@zoo-project.org])1 AC_INIT([ZOO Kernel], [1.8.0-rc1], [bugs@zoo-project.org]) 2 2 3 3 AC_CONFIG_MACRO_DIR([macros]) … … 1079 1079 WX_ISSUE="-D_WX_WXCRTVARARG_H_" 1080 1080 SAGA_DEFS="-D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -DMODULE_LIBRARY_PATH=\\\"$SAGAPATH/lib/saga\\\"" 1081 SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"1081 SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ -I$SAGAPATH/include/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE" 1082 1082 SAGA_LDFLAGS="-fPIC `$WXCFG --unicode=yes --static=no --libs` -lsaga_api" 1083 1083 SAGA_ENABLED="-DUSE_SAGA" -
trunk/zoo-project/zoo-kernel/oas.cfg
r962 r967 12 12 wsUrl=wss://demo.mapmint.com:4430/ 13 13 publisherUrl=http://127.0.0.1/cgi-bin3/publish.py?jobid= 14 io_as_array=true 14 15 15 16 [/] … … 24 25 tags=Home 25 26 tags_description= 26 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/LandingPage.yaml27 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/LandingPage.yaml 27 28 28 29 [/index.html] … … 53 54 rel=conformance 54 55 type=application/json 55 title= WPS 2.0 REST/JSON Binding Extensionconformance classes implemented by this server56 title=OGC API - Processes conformance classes implemented by this server 56 57 57 58 [conformance] … … 61 62 tags=Conformance 62 63 tags_description= 63 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ConformanceDeclaration.yaml64 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ConformanceDeclaration.yaml 64 65 65 66 [/conformance.html] … … 78 79 tags=GetCapabilities 79 80 tags_description= 80 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessList.yaml81 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ProcessList.yaml 81 82 82 83 [/processes.html] … … 90 91 tags=ProcessDescription 91 92 tags_description= 92 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessDescription.yaml93 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ProcessDescription.yaml 93 94 ecode=404 94 95 parameters=/components/parameters/id … … 107 108 tags=JobList 108 109 tags_description= 109 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/JobList.yaml110 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/JobList.yaml 110 111 parameters=/components/parameters/id 111 112 ecode=404,500 … … 115 116 tags_1=Execute Endpoint 116 117 tags_description_1= 117 schema_1=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteSync.yaml118 schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ExecuteSync.yaml 118 119 parameters_1=/components/parameters/id 119 120 ecode_1=400,404,500 120 eschema_1=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteAsync.yaml121 eschema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ExecuteAsync.yaml 121 122 ep=,/components/parameters/oas-header1 122 123 … … 124 125 abstract=Mandatory execute request in JSON format 125 126 type=application/json 126 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/schemas/execute.yaml127 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/execute.yaml 127 128 128 129 [/processes/{id}/jobs/{jobID}] … … 138 139 tags=GetStatus 139 140 tags_description= 140 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml141 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Status.yaml 141 142 parameters=/components/parameters/id,/components/parameters/jobID 142 143 method_1=delete … … 145 146 tags_1=Dismiss 146 147 tags_description_1=Cencel a job execution 147 schema_1=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml148 schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Status.yaml 148 149 parameters_1=/components/parameters/id,/components/parameters/jobID 149 150 ecode_1=404,500 … … 161 162 tags=GetResult 162 163 tags_description= 163 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/Results.yaml164 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Results.yaml 164 165 parameters=/components/parameters/id,/components/parameters/jobID 165 166 ecode=404,500 … … 177 178 tags=GetResult 178 179 tags_description= 179 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/schemas/valueType.yaml180 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/valueType.yaml 180 181 parameters=/components/parameters/id,/components/parameters/jobID,/components/parameters/resultID 181 182 ep=,/components/parameters/oas-header2 … … 226 227 abstract=Exception 227 228 type=application/json 228 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml229 default_schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml229 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotFound.yaml 230 default_schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ServerError.yaml 230 231 231 232 [responses] 232 233 length=5 233 234 code=404 234 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml235 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotFound.yaml 235 236 type=application/json 236 237 title=NotFound 237 238 code_1=500 238 schema_1=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml239 schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ServerError.yaml 239 240 type_1=application/json 240 241 title_1=ServerError 241 242 code_2=400 242 schema_2=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/InvalidParameter.yaml243 schema_2=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/InvalidParameter.yaml 243 244 type_2=appliction/json 244 245 title_2=InvalidParameter 245 246 code_3=405 246 schema_3=https:// github.com/opengeospatial/wps-rest-binding/blob/master/core/openapi/responses/NotAllowed.yaml247 schema_3=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/NotAllowed.yaml 247 248 type_3=appliction/json 248 249 title_3=NotAllowed 249 250 code_4=406 250 schema_4=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/responses/NotSupported.yaml251 schema_4=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotSupported.yaml 251 252 type_4=appliction/json 252 253 title_4=NotSupported … … 256 257 state=jobSuccess 257 258 uri=successUri 258 schema=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/schemas/result.yaml259 schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/result.yaml 259 260 type=application/json 260 261 title=Results received successfully 261 262 state_1=jobInProgress 262 263 uri_1=inProgressUri 263 schema_1=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/schemas/statusInfo.yaml264 schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/statusInfo.yaml 264 265 type_1=application/json 265 266 title_1=Results received successfully 266 267 state_2=jobFailed 267 268 uri_2=failedUrii 268 schema_2=https://raw.githubusercontent.com/ opengeospatial/wps-rest-binding/master/core/openapi/schemas/exception.yaml269 schema_2=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/exception.yaml 269 270 type_2=application/json 270 271 title_2=Exception received successfully -
trunk/zoo-project/zoo-kernel/request_parser.c
r966 r967 1689 1689 int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet){ 1690 1690 1691 map* errI0=NULL; 1692 runHttpRequests (main_conf, request_inputs, hInternet,&errI0); 1693 if(errI0!=NULL){ 1694 printExceptionReportResponse (*main_conf, errI0); 1691 if(hInternet!=NULL){ 1692 map* errI0=NULL; 1693 runHttpRequests (main_conf, request_inputs, hInternet,&errI0); 1694 if(errI0!=NULL){ 1695 printExceptionReportResponse (*main_conf, errI0); 1696 InternetCloseHandle (hInternet); 1697 return -1; 1698 } 1695 1699 InternetCloseHandle (hInternet); 1696 return -1;1697 1700 } 1698 InternetCloseHandle (hInternet);1699 1700 1701 1701 1702 map* errI=NULL; … … 1720 1721 addToMap (tmpe, "locator", ptr->name); 1721 1722 addToMap (tmpe, "text", tmps); 1722 1723 printExceptionReportResponse (*main_conf, tmpe); 1723 1724 freeMap (&tmpe); 1724 1725 free (tmpe); -
trunk/zoo-project/zoo-kernel/response_print.c
r966 r967 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-20 15GeoLabs SARL4 * Copyright (c) 2009-2020 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 41 41 42 42 #include "mimetypes.h" 43 #include "service_json.h" 43 44 44 45 /** 45 46 * Add prefix to the service name. 46 47 * 47 * @param conf the conf maps containing the main.cfg settings48 * @param level the map containing the level information49 * @param servthe service structure created from the zcfg file50 */ 51 void addPrefix(maps* conf,map* level,service* serv){52 if( level!=NULL){53 char key[25];54 char* p refix=NULL;55 int clevel=atoi(level->value);56 int cl=0;57 for( cl=0;cl<clevel;cl++){58 sprintf( key,"sprefix_%d",cl);59 map* tmp2=getMapFromMaps( conf,"lenv",key);48 * @param pmsConf the conf maps containing the main.cfg settings 49 * @param pmLevel the map containing the level information 50 * @param psService the service structure created from the zcfg file 51 */ 52 void addPrefix(maps* pmsConf,map* pmLevel,service* psService){ 53 if(pmLevel!=NULL){ 54 char acKey[25]; 55 char* pcaPrefix=NULL; 56 int iClevel=atoi(pmLevel->value); 57 int iCl=0; 58 for(iCl=0;iCl<iClevel;iCl++){ 59 sprintf(acKey,"sprefix_%d",iCl); 60 map* tmp2=getMapFromMaps(pmsConf,"lenv",acKey); 60 61 if(tmp2!=NULL){ 61 if(p refix==NULL)62 p refix=zStrdup(tmp2->value);62 if(pcaPrefix==NULL) 63 pcaPrefix=zStrdup(tmp2->value); 63 64 else{ 64 int plen=strlen(p refix);65 p refix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));66 memcpy(p refix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));67 p refix[plen+strlen(tmp2->value)]=0;68 } 69 } 70 } 71 if(p refix!=NULL){72 char* tmp0=zStrdup(serv->name);73 free( serv->name);74 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));75 sprintf( serv->name,"%s%s",prefix,tmp0);76 free( tmp0);77 free(p refix);78 p refix=NULL;65 int plen=strlen(pcaPrefix); 66 pcaPrefix=(char*)realloc(pcaPrefix,(plen+strlen(tmp2->value)+2)*sizeof(char)); 67 memcpy(pcaPrefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char)); 68 pcaPrefix[plen+strlen(tmp2->value)]=0; 69 } 70 } 71 } 72 if(pcaPrefix!=NULL){ 73 char* pcaTmp=zStrdup(psService->name); 74 free(psService->name); 75 psService->name=(char*)malloc((strlen(pcaPrefix)+strlen(pcaTmp)+1)*sizeof(char)); 76 sprintf(psService->name,"%s%s",pcaPrefix,pcaTmp); 77 free(pcaTmp); 78 free(pcaPrefix); 79 pcaPrefix=NULL; 79 80 } 80 81 } … … 84 85 * Print the HTTP headers based on a map. 85 86 * 86 * @param mthe map containing the headers information87 */ 88 void printHeaders(maps* m){89 maps * _tmp=getMaps(m,"headers");90 if( _tmp!=NULL){91 map* _tmp1=_tmp->content;92 while( _tmp1!=NULL){93 printf("%s: %s\r\n", _tmp1->name,_tmp1->value);94 _tmp1=_tmp1->next;95 } 96 } 97 printSessionHeaders( m);87 * @param pmsConf the map containing the headers information 88 */ 89 void printHeaders(maps* pmsConf){ 90 maps *pmsTmp=getMaps(pmsConf,"headers"); 91 if(pmsTmp!=NULL){ 92 map* pmTmp=pmsTmp->content; 93 while(pmTmp!=NULL){ 94 printf("%s: %s\r\n",pmTmp->name,pmTmp->value); 95 pmTmp=pmTmp->next; 96 } 97 } 98 printSessionHeaders(pmsConf); 98 99 } 99 100 … … 104 105 * The session file (sess_<SESSID>_.cfg where <SESSID> is the cookie value) is 105 106 * stored in the conf["main"]["tmpPath"] directory. 106 * @param m the main configuration map 107 */ 108 void printSessionHeaders(maps* m){ 109 maps* tmpSess=getMaps(m,"senv"); 110 if(tmpSess!=NULL){ 111 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 112 maps *tmps=getMaps(m,"senv"); 107 * @param pmsConf the main configuration map 108 */ 109 void printSessionHeaders(maps* pmsConf){ 110 maps* pmsSess=getMaps(pmsConf,"senv"); 111 if(pmsSess!=NULL){ 112 map *pmTmp=getMapFromMaps(pmsConf,"lenv","cookie"); 113 113 char* sessId=NULL; 114 if( _tmp!=NULL){115 printf("Set-Cookie: %s; HttpOnly\r\n", _tmp->value);116 map * _tmp1=getMapFromMaps(m,"senv","ecookie_length");117 if( _tmp1!=NULL){118 int len=atoi( _tmp1->value);114 if(pmTmp!=NULL){ 115 printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp->value); 116 map *pmTmp1=getMapFromMaps(pmsConf,"senv","ecookie_length"); 117 if(pmTmp1!=NULL){ 118 int len=atoi(pmTmp1->value); 119 119 int cnt=0; 120 120 for(cnt=0;cnt<len;cnt++){ 121 map* _tmp2=getMapArray(tmps->content,"ecookie",cnt);122 if( _tmp2!=NULL)123 printf("Set-Cookie: %s; HttpOnly\r\n", _tmp2->value);121 map* pmTmp2=getMapArray(pmsSess->content,"ecookie",cnt); 122 if(pmTmp2!=NULL) 123 printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp2->value); 124 124 } 125 125 } 126 126 printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 127 127 char session_file_path[100]; 128 char *tmp1=strtok( _tmp->value,";");128 char *tmp1=strtok(pmTmp->value,";"); 129 129 if(tmp1!=NULL) 130 130 sprintf(session_file_path,"%s",strstr(tmp1,"=")+1); 131 131 else 132 sprintf(session_file_path,"%s",strstr( _tmp->value,"=")+1);132 sprintf(session_file_path,"%s",strstr(pmTmp->value,"=")+1); 133 133 sessId=zStrdup(session_file_path); 134 134 }else{ 135 maps* t=getMaps( m,"senv");135 maps* t=getMaps(pmsConf,"senv"); 136 136 map*p=t->content; 137 137 while(p!=NULL){ … … 144 144 } 145 145 char session_file_path[1024]; 146 map *tmpPath=getMapFromMaps( m,"main","sessPath");146 map *tmpPath=getMapFromMaps(pmsConf,"main","sessPath"); 147 147 if(tmpPath==NULL) 148 tmpPath=getMapFromMaps( m,"main","tmpPath");148 tmpPath=getMapFromMaps(pmsConf,"main","tmpPath"); 149 149 sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId); 150 150 FILE* teste=fopen(session_file_path,"w"); … … 152 152 char tmpMsg[1024]; 153 153 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path); 154 errorException( m,tmpMsg,"InternalError",NULL);154 errorException(pmsConf,tmpMsg,"InternalError",NULL); 155 155 return; 156 156 } 157 157 else{ 158 158 fclose(teste); 159 dumpMapsToFile( tmpSess,session_file_path,1);159 dumpMapsToFile(pmsSess,session_file_path,1); 160 160 } 161 161 } … … 2096 2096 if(vid==0) 2097 2097 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 2098 else 2098 else 2099 2099 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 2100 2100 } … … 2535 2535 2536 2536 /** 2537 * Produce the status string used in HTTP headers. 2538 * 2539 * @param pmConf the maps containing the settings of the main.cfg file 2540 * @param pmCode the map containing the error code (or a map array of the same keys) 2541 */ 2542 const char* produceStatusString(maps* pmConf,map* pmCode){ 2543 if(pmCode!=NULL){ 2544 int iI=0; 2545 for(iI=0;iI<3;iI++){ 2546 int iJ=0; 2547 for(iJ=0;;iJ++){ 2548 if(aapccStatusCodes[iI][iJ]==NULL) 2549 break; 2550 else{ 2551 if(strcmp(aapccStatusCodes[iI][iJ],pmCode->value)==0) 2552 return aapccStatusCodes[iI][0]; 2553 } 2554 } 2555 } 2556 } 2557 else{ 2558 return aapccStatusCodes[3][0]; 2559 } 2560 } 2561 2562 /** 2537 2563 * Print an OWS ExceptionReport Document and HTTP headers (when required) 2538 2564 * depending on the code. … … 2542 2568 * @param s the map containing the text,code,locator keys (or a map array of the same keys) 2543 2569 */ 2544 void printExceptionReportResponse(maps* m,map* s){ 2545 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) 2546 return; 2570 void _printExceptionReportResponse(maps* m,map* s){ 2547 2571 int buffersize; 2548 2572 xmlDocPtr doc; … … 2557 2581 2558 2582 map* tmp=getMap(s,"code"); 2559 if(tmp!=NULL){ 2560 if(strcmp(tmp->value,"OperationNotSupported")==0 || 2561 strcmp(tmp->value,"NoApplicableCode")==0) 2562 exceptionCode="501 Not Implemented"; 2563 else 2564 if(strcmp(tmp->value,"MissingParameterValue")==0 || 2565 strcmp(tmp->value,"InvalidUpdateSequence")==0 || 2566 strcmp(tmp->value,"OptionNotSupported")==0 || 2567 strcmp(tmp->value,"VersionNegotiationFailed")==0 || 2568 strcmp(tmp->value,"InvalidParameterValue")==0) 2569 exceptionCode="400 Bad request"; 2570 else 2571 exceptionCode="501 Internal Server Error"; 2572 } 2573 else 2574 exceptionCode="501 Internal Server Error"; 2583 exceptionCode=produceStatusString(m,tmp); 2575 2584 tmp=getMapFromMaps(m,"lenv","status_code"); 2576 2585 if(tmp!=NULL) … … 2601 2610 zooXmlCleanupNs(); 2602 2611 if(m!=NULL) 2603 setMapInMaps(m,"lenv","hasPrinted","true"); 2612 setMapInMaps(m,"lenv","hasPrinted","true"); 2613 } 2614 2615 /** 2616 * Print an OWS ExceptionReport or exception.yaml Document and HTTP headers 2617 * (when required) depending on the code. 2618 * 2619 * @param pmsConf the maps containing the settings of the main.cfg file 2620 * @param psService the service 2621 */ 2622 void printExceptionReportResponse(maps* pmsConf,map* psService){ 2623 if(getMapFromMaps(pmsConf,"lenv","hasPrinted")!=NULL) 2624 return; 2625 map* pmExecutionType=getMapFromMaps(pmsConf,"main","executionType"); 2626 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0) 2627 _printExceptionReportResponse(pmsConf,psService); 2628 else 2629 printExceptionReportResponseJ(pmsConf,psService); 2604 2630 } 2605 2631 … … 2694 2720 int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 2695 2721 { 2722 map* pmExectionType=getMapFromMaps(m,"main","executionType"); 2696 2723 map* errormap = createMap("text", message); 2697 2724 addToMap(errormap,"code", errorcode); … … 2700 2727 else 2701 2728 addToMap(errormap,"locator", "NULL"); 2702 printExceptionReportResponse(m,errormap); 2729 if(pmExectionType!=NULL && strncasecmp(pmExectionType->value,"xml",3)==0) 2730 printExceptionReportResponse(m,errormap); 2731 else{ 2732 printExceptionReportResponseJ(m,errormap); 2733 setMapInMaps(m,"lenv","no-headers","true"); 2734 } 2703 2735 freeMap(&errormap); 2704 2736 free(errormap); 2705 2737 return -1; 2738 } 2739 2740 /** 2741 * Produce a copy file and the corresponding url in case it is required 2742 * Please, free the returned ressource while used 2743 * 2744 * @param pmConf maps* pointing to the main configuration file 2745 */ 2746 char* produceFileUrl(service* psService,maps* pmsConf,maps* pmsOutputs,const char* pccFormat, int itn){ 2747 // Create file for reference data if not existing 2748 map *pmGFile=getMap(pmsOutputs->content,"generated_file"); 2749 map *pmTmpPath=getMapFromMaps(pmsConf,"main","tmpPath"); 2750 map *pmTmpUrl=getMapFromMaps(pmsConf,"main","tmpUrl"); 2751 char *pcaFileName=NULL; 2752 char *pcaFilePath=NULL; 2753 char *pcaFileUrl=NULL; 2754 if(pmGFile!=NULL){ 2755 pmGFile=getMap(pmsOutputs->content,"expected_generated_file"); 2756 if(pmGFile==NULL){ 2757 pmGFile=getMap(pmsOutputs->content,"generated_file"); 2758 } 2759 if(strstr(pmGFile->value,pmTmpPath->value)!=NULL) 2760 pcaFileName=zStrdup(strstr(pmGFile->value,pmTmpPath->value)+strlen(pmTmpPath->value)); 2761 } 2762 // Create file for reference data 2763 map *pmUsid=getMapFromMaps(pmsConf,"lenv","usid"); 2764 map *pmExt=getMap(pmsOutputs->content,"extension"); 2765 if(pmGFile==NULL){ 2766 char acFileExt[32]; 2767 if( pmExt != NULL && pmExt->value != NULL) { 2768 strncpy(acFileExt, pmExt->value, 32); 2769 } 2770 else { 2771 // Obtain default file extension (see mimetypes.h). 2772 // If the MIME type is not recognized, txt is used as the default extension 2773 map* pmType=getMap(pmsOutputs->content,"mimeType"); 2774 getFileExtension(pmType != NULL ? pmType->value : NULL, acFileExt, 32); 2775 } 2776 if(pcaFileName!=NULL) 2777 free(pcaFileName); 2778 2779 pcaFileName=(char*)malloc((strlen(psService->name)+strlen(pmUsid->value)+strlen(acFileExt)+strlen(pmsOutputs->name)+45)*sizeof(char)); 2780 sprintf(pcaFileName,"ZOO_DATA_%s_%s_%s_%d.%s",psService->name,pmsOutputs->name,pmUsid->value,itn,acFileExt); 2781 2782 pcaFilePath=(char*)malloc((strlen(pmTmpPath->value)+strlen(pcaFileName)+2)*sizeof(char)); 2783 sprintf(pcaFilePath,"%s/%s",pmTmpPath->value,pcaFileName); 2784 }else{ 2785 pcaFilePath=(char*)malloc((strlen(pmGFile->value)+1)*sizeof(char)); 2786 sprintf(pcaFilePath,"%s",pmGFile->value); 2787 } 2788 2789 pcaFileUrl=(char*)malloc((strlen(pmTmpUrl->value)+ 2790 strlen(pcaFileName)+2)*sizeof(char)); 2791 sprintf(pcaFileUrl,"%s/%s",pmTmpUrl->value,pcaFileName); 2792 2793 if(pmGFile==NULL) { 2794 FILE *pfOfile=fopen(pcaFilePath,"wb"); 2795 if(pfOfile==NULL){ 2796 char acTmpMsg[1024]; 2797 sprintf(acTmpMsg, 2798 _("Unable to create the file \"%s\" for storing the %s final result."), 2799 pcaFileName,pmsOutputs->name); 2800 map* pmError=createMap("code","InternalError"); 2801 addToMap(pmError,"message",acTmpMsg); 2802 printExceptionReportResponseJ(pmsConf,pmError); 2803 free(pcaFileName); 2804 free(pcaFilePath); 2805 return NULL; 2806 } 2807 2808 map* pmValue=getMap(pmsOutputs->content,"value"); 2809 if(pmValue==NULL){ 2810 char acTmpMsg[1024]; 2811 sprintf(acTmpMsg, 2812 _("No value found for the requested output %s."), 2813 pmsOutputs->name); 2814 map* pmError=createMap("code","InternalError"); 2815 addToMap(pmError,"message",acTmpMsg); 2816 printExceptionReportResponseJ(pmsConf,pmError); 2817 fclose(pfOfile); 2818 free(pcaFileName); 2819 free(pcaFilePath); 2820 return NULL; 2821 } 2822 if(pccFormat==NULL || strcasecmp(pccFormat,"BoundingBoxData")!=0){ 2823 map* size=getMap(pmsOutputs->content,"size"); 2824 if(size!=NULL && pmValue!=NULL) 2825 fwrite(pmValue->value,1,(atoi(size->value))*sizeof(char),pfOfile); 2826 else 2827 if(pmValue!=NULL && pmValue->value!=NULL) 2828 fwrite(pmValue->value,1, 2829 strlen(pmValue->value)*sizeof(char),pfOfile); 2830 }else 2831 printBoundingBoxDocument(pmsConf,pmsOutputs,pfOfile); 2832 fclose(pfOfile); 2833 } 2834 free(pcaFileName); 2835 free(pcaFilePath); 2836 return pcaFileUrl; 2706 2837 } 2707 2838 … … 2724 2855 fprintf(stderr,"printProcessResponse\n"); 2725 2856 #endif 2726 map* toto=getMap(request_inputs1,"RawDataOutput");2857 map* pmRawData=getMap(request_inputs1,"RawDataOutput"); 2727 2858 int asRaw=0; 2728 if( toto!=NULL)2859 if(pmRawData!=NULL) 2729 2860 asRaw=1; 2730 2861 map* version=getMapFromMaps(m,"main","rversion"); … … 2776 2907 map* testMap=getMap(tmpI->content,"useMapserver"); 2777 2908 #endif 2778 map *gfile=getMap(tmpI->content,"generated_file");2909 /*map *gfile=getMap(tmpI->content,"generated_file"); 2779 2910 char *file_name=NULL; 2780 2911 if(gfile!=NULL){ … … 2785 2916 readGeneratedFile(m,tmpI->content,gfile->value); 2786 2917 file_name=zStrdup((gfile->value)+strlen(tmp1->value)); 2787 } 2788 toto=getMap(tmpI->content,"asReference"); 2918 }*/ 2919 char *pcaFileUrl=NULL; 2920 pmRawData=getMap(tmpI->content,"asReference"); 2789 2921 #ifdef USE_MS 2790 2922 map* geodatatype=getMap(tmpI->content,"geodatatype"); 2791 if( toto!=NULL && strcasecmp(toto->value,"true")==0 &&2923 if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0 && 2792 2924 (testMap==NULL || 2793 2925 strncasecmp(testMap->value,"true",4)!=0 || 2794 2926 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 2795 2927 #else 2796 if( toto!=NULL && strcasecmp(toto->value,"true")==0)2928 if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0) 2797 2929 #endif 2798 2930 { … … 2811 2943 addToMap(tmpI->content,"encoding","UTF-8"); 2812 2944 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2813 }2814 char *file_path=NULL;2815 if(gfile==NULL) {2816 map *ext=getMap(tmpI->content,"extension");2817 char file_ext[32];2818 2819 if( ext != NULL && ext->value != NULL) {2820 strncpy(file_ext, ext->value, 32);2821 }2822 else {2823 // Obtain default file extension (see mimetypes.h).2824 // If the MIME type is not recognized, txt is used as the default extension2825 map* mtype=getMap(tmpI->content,"mimeType");2826 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);2827 }2828 if(file_name!=NULL)2829 free(file_name);2830 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));2831 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);2832 itn++;2833 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));2834 sprintf(file_path,"%s/%s",tmp1->value,file_name);2835 2836 FILE *ofile=fopen(file_path,"wb");2837 if(ofile==NULL){2838 char tmpMsg[1024];2839 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);2840 errorException(m,tmpMsg,"InternalError",NULL);2841 free(file_name);2842 free(file_path);2843 return;2844 }2845 2846 toto=getMap(tmpI->content,"value");2847 if(toto==NULL){2848 char tmpMsg[1024];2849 sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);2850 errorException(m,tmpMsg,"InternalError",NULL);2851 fclose(ofile);2852 free(file_name);2853 free(file_path);2854 return;2855 }2856 if(strcasecmp(format,"BoundingBoxData")!=0){2857 map* size=getMap(tmpI->content,"size");2858 if(size!=NULL && toto!=NULL)2859 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);2860 else2861 if(toto!=NULL && toto->value!=NULL)2862 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);2863 }else{2864 printBoundingBoxDocument(m,tmpI,ofile);2865 }2866 fclose(ofile);2867 2945 } 2868 2869 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2870 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2871 char *file_url=NULL; 2872 if(strncasecmp(tmp2->value,"http://",7)==0 || 2873 strncasecmp(tmp2->value,"https://",8)==0){ 2874 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2875 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2876 }else{ 2877 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2878 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2879 } 2880 addToMap(tmpI->content,"Reference",file_url); 2881 if(file_name!=NULL) 2882 free(file_name); 2883 if(file_url!=NULL) 2884 free(file_url); 2885 file_name=NULL; 2946 pcaFileUrl=produceFileUrl(s,m,tmpI,format,itn); 2947 itn++; 2948 if(pcaFileUrl==NULL) 2949 return; 2950 addToMap(tmpI->content,"Reference",pcaFileUrl); 2886 2951 } 2887 2952 #ifdef USE_MS … … 2901 2966 } 2902 2967 #endif 2903 if( file_name!=NULL){2904 free( file_name);2905 file_name=NULL;2968 if(pcaFileUrl!=NULL){ 2969 free(pcaFileUrl); 2970 pcaFileUrl=NULL; 2906 2971 } 2907 2972 tmpI=tmpI->next; … … 2947 3012 printBoundingBoxDocument(m,tmpI,NULL); 2948 3013 }else{ 2949 map *gfile=getMap(tmpI->content,"generated_file"); 2950 if(gfile!=NULL){ 2951 gfile=getMap(tmpI->content,"expected_generated_file"); 2952 if(gfile==NULL){ 2953 gfile=getMap(tmpI->content,"generated_file"); 2954 } 2955 readGeneratedFile(m,tmpI->content,gfile->value); 2956 } 2957 toto=getMap(tmpI->content,"value"); 2958 if(toto==NULL){ 2959 char tmpMsg[1024]; 2960 sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name); 2961 errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput"); 2962 return; 2963 } 2964 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2965 if(fname!=NULL) 2966 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2967 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2968 if(rs!=NULL) 2969 printf("Content-Length: %s\r\n",rs->value); 2970 printHeaders(m); 2971 char mime[1024]; 2972 map* mi=getMap(tmpI->content,"mimeType"); 2973 #ifdef DEBUG 2974 fprintf(stderr,"SERVICE OUTPUTS\n"); 2975 dumpMaps(request_outputs); 2976 fprintf(stderr,"SERVICE OUTPUTS\n"); 2977 #endif 2978 map* en=getMap(tmpI->content,"encoding"); 2979 if(mi!=NULL && en!=NULL) 2980 sprintf(mime, 2981 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 2982 mi->value,en->value); 2983 else 2984 if(mi!=NULL) 2985 sprintf(mime, 2986 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2987 mi->value); 2988 else 2989 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2990 printf("%s",mime); 2991 if(rs!=NULL) 2992 fwrite(toto->value,1,atoi(rs->value),stdout); 2993 else 2994 fwrite(toto->value,1,strlen(toto->value),stdout); 2995 #ifdef DEBUG 2996 dumpMap(toto); 2997 #endif 2998 } 2999 } 3014 printRawdataOutput(m,tmpI); 3015 } 3016 } 3017 } 3018 3019 /** 3020 * Print one outputs as raw 3021 * 3022 * @param conf the main configuration maps 3023 * @param outputs the output to be print as raw 3024 */ 3025 void* printRawdataOutput(maps* conf,maps* outputs){ 3026 map *gfile=getMap(outputs->content,"generated_file"); 3027 if(gfile!=NULL){ 3028 gfile=getMap(outputs->content,"expected_generated_file"); 3029 if(gfile==NULL){ 3030 gfile=getMap(outputs->content,"generated_file"); 3031 } 3032 readGeneratedFile(conf,outputs->content,gfile->value); 3033 } 3034 map* toto=getMap(outputs->content,"value"); 3035 if(toto==NULL){ 3036 char tmpMsg[1024]; 3037 sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),outputs->name); 3038 map* pmExecutionType=getMapFromMaps(conf,"main","executionType"); 3039 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0) 3040 errorException(conf,tmpMsg,"InvalidParameterValue","RawDataOutput"); 3041 else{ 3042 setMapInMaps(conf,"lenv","error","true"); 3043 setMapInMaps(conf,"lenv","code","InvalidParameterValue"); 3044 setMapInMaps(conf,"lenv","message",tmpMsg); 3045 } 3046 return NULL; 3047 } 3048 map* fname=getMapFromMaps(outputs,outputs->name,"filename"); 3049 if(fname!=NULL) 3050 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 3051 map* rs=getMapFromMaps(outputs,outputs->name,"size"); 3052 if(rs!=NULL) 3053 printf("Content-Length: %s\r\n",rs->value); 3054 char mime[1024]; 3055 map* mi=getMap(outputs->content,"mimeType"); 3056 map* en=getMap(outputs->content,"encoding"); 3057 if(mi!=NULL && en!=NULL) 3058 sprintf(mime, 3059 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 3060 mi->value,en->value); 3061 else 3062 if(mi!=NULL) 3063 sprintf(mime, 3064 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 3065 mi->value); 3066 else 3067 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 3068 printf("%s",mime); 3069 if(rs!=NULL) 3070 fwrite(toto->value,1,atoi(rs->value),stdout); 3071 else 3072 fwrite(toto->value,1,strlen(toto->value),stdout); 3000 3073 } 3001 3074 -
trunk/zoo-project/zoo-kernel/response_print.h
r966 r967 194 194 }; 195 195 196 197 static const char* const aapccStatusCodes[][8] = { 198 { 199 "500 Not Implemented", 200 "OperationNotSupported", 201 "NoApplicableCode", 202 NULL 203 }, 204 { 205 "400 Bad request", 206 "MissingParameterValue" 207 "InvalidParameterValue", 208 "InvalidUpdateSequence", 209 "OptionNotSupported", 210 "VersionNegotiationFailed", 211 "NoSuchMode", 212 NULL 213 }, 214 { 215 "404 Not Found", 216 "NotFound", 217 "NoSuchProcess", 218 "NoSuchJob", 219 "ResultNotReady", 220 NULL 221 }, 222 { 223 "500 Not Implemented", 224 NULL 225 } 226 }; 227 196 228 void addLangAttr(xmlNodePtr,maps*); 197 229 … … 205 237 int zooXmlAddDoc(xmlNodePtr,const char*,const char*); 206 238 void zooXmlCleanupDocs(); 207 239 240 const char* produceStatusString(maps*,map*); 208 241 void printExceptionReportResponse(maps*,map*); 209 242 xmlNodePtr createExceptionReportNode(maps*,map*,int); … … 217 250 void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int); 218 251 void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int); 252 void* printRawdataOutput(maps*,maps*); 219 253 map* parseBoundingBox(const char*); 220 254 void printBoundingBox(xmlNsPtr,xmlNodePtr,map*); … … 225 259 void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int); 226 260 261 char* produceFileUrl(service*,maps*,maps*,const char*, int); 227 262 void outputResponse(service*,maps*,maps*,map*,int,maps*,int); 228 263 -
trunk/zoo-project/zoo-kernel/server_internal.c
r962 r967 377 377 sprintf(rsize,"%lld",f_status.st_size); 378 378 if(getMap(content,"storage")==NULL){ 379 map* memUse=getMapFromMaps(m,"main","memory"); 380 if(memUse==NULL || strncmp(memUse->value,"load",4)==0){ 381 map* tmpMap1=getMap(content,"value"); 382 if(tmpMap1==NULL){ 383 addToMap(content,"value",""); 384 tmpMap1=getMap(content,"value"); 385 } 386 free(tmpMap1->value); 387 tmpMap1->value=(char*) malloc((f_status.st_size+1)*sizeof(char)); 388 if(tmpMap1->value==NULL){ 389 setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file."); 390 return; 391 } 392 fread(&tmpMap1->value,1,f_status.st_size,file); 393 tmpMap1->value[f_status.st_size]=0; 394 } 379 map* tmpMap1=getMap(content,"value"); 380 if(tmpMap1==NULL){ 381 addToMap(content,"value",""); 382 tmpMap1=getMap(content,"value"); 383 } 384 free(tmpMap1->value); 385 tmpMap1->value=(char*) malloc((f_status.st_size+1)*sizeof(char)); 386 if(tmpMap1->value==NULL){ 387 setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file."); 388 return; 389 } 390 fread(tmpMap1->value,1,f_status.st_size,file); 391 tmpMap1->value[f_status.st_size]=0; 395 392 } 396 393 fclose(file); … … 994 991 void runGetStatus(maps* conf,char* pid,char* req){ 995 992 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 996 map* e_type = getMapFromMaps (conf, " lenv", "executionType");993 map* e_type = getMapFromMaps (conf, "main", "executionType"); 997 994 char *sid=getStatusId(conf,pid); 998 995 if(sid==NULL){ … … 1101 1098 void runDismiss(maps* conf,char* pid){ 1102 1099 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 1103 map* e_type = getMapFromMaps (conf, " lenv", "executionType");1100 map* e_type = getMapFromMaps (conf, "main", "executionType"); 1104 1101 char *sid=getStatusId(conf,pid); 1105 1102 if(sid==NULL){ -
trunk/zoo-project/zoo-kernel/service.c
r961 r967 39 39 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c 40 40 */ 41 int snprintf(char * buffer, size_t n, const char *format, ...)41 int snprintf(char *pcBuffer, size_t n, const char *pccFormat, ...) 42 42 { 43 43 va_list argp; 44 44 int ret; 45 va_start(argp, format);46 ret = _vscprintf( format, argp);47 vsnprintf_s( buffer, n, _TRUNCATE, format, argp);45 va_start(argp, pccFormat); 46 ret = _vscprintf(pccFormat, argp); 47 vsnprintf_s(pcBuffer, n, _TRUNCATE, pccFormat, argp); 48 48 va_end(argp); 49 49 return ret; … … 54 54 * Dump a map on stderr 55 55 * 56 * @param tthe map to dump57 */ 58 void _dumpMap(map* t){59 if( t!=NULL){60 fprintf(stderr,"%s: %s\n", t->name,t->value);56 * @param pmMap the map to dump 57 */ 58 void _dumpMap(map* pmMap){ 59 if(pmMap!=NULL){ 60 fprintf(stderr,"%s: %s\n",pmMap->name,pmMap->value); 61 61 fflush(stderr); 62 62 }else{ … … 69 69 * Dump a map on stderr, see _dumpMap() 70 70 * 71 * @param tthe map to dump72 */ 73 void dumpMap(map* t){74 map* tmp=t;75 while( tmp!=NULL){76 _dumpMap( tmp);77 tmp=tmp->next;71 * @param pmMap the map to dump 72 */ 73 void dumpMap(map* pmMap){ 74 map* pmTmp=pmMap; 75 while(pmTmp!=NULL){ 76 _dumpMap(pmTmp); 77 pmTmp=pmTmp->next; 78 78 } 79 79 } … … 82 82 * Dump a map to a file 83 83 * 84 * @param tthe map to dump to file85 * @param file the file pointer to store the map86 */ 87 void dumpMapToFile(map* t,FILE* file){88 map* tmp=t;89 while( tmp!=NULL){90 fprintf( file,"%s = %s\n",tmp->name,tmp->value);91 tmp=tmp->next;84 * @param pmMap the map to dump to file 85 * @param pfFile the file pointer to store the map 86 */ 87 void dumpMapToFile(map* pmMap,FILE* pfFile){ 88 map* pmTmp=pmMap; 89 while(pmTmp!=NULL){ 90 fprintf(pfFile,"%s = %s\n",pmTmp->name,pmTmp->value); 91 pmTmp=pmTmp->next; 92 92 } 93 93 } … … 96 96 * Dump a maps on stderr, see dumpMap(). 97 97 * 98 * @param mthe map to dump99 */ 100 void dumpMaps(maps* m){101 maps* tmp=m;102 while( tmp!=NULL){103 fprintf(stderr,"MAP => [%s] \n", tmp->name);104 fprintf(stderr," * CONTENT [%s] \n", tmp->name);105 dumpMap( tmp->content);106 if( tmp->child!=NULL){107 fprintf(stderr," * CHILD [%s] \n", tmp->name);108 dumpMaps( tmp->child);109 fprintf(stderr," * /CHILD [%s] \n", tmp->name);110 } 111 tmp=tmp->next;98 * @param pmMap the map to dump 99 */ 100 void dumpMaps(maps* pmMap){ 101 maps* pmTmp=pmMap; 102 while(pmTmp!=NULL){ 103 fprintf(stderr,"MAP => [%s] \n",pmTmp->name); 104 fprintf(stderr," * CONTENT [%s] \n",pmTmp->name); 105 dumpMap(pmTmp->content); 106 if(pmTmp->child!=NULL){ 107 fprintf(stderr," * CHILD [%s] \n",pmTmp->name); 108 dumpMaps(pmTmp->child); 109 fprintf(stderr," * /CHILD [%s] \n",pmTmp->name); 110 } 111 pmTmp=pmTmp->next; 112 112 } 113 113 } … … 116 116 * Dump a maps to a file, see dumpMapToFile(). 117 117 * 118 * @param m the map to dump 119 * @param file the the file pointer to store the map 120 */ 121 void _dumpMapsToFile(maps* m,FILE* file,int limit){ 122 maps* tmp=m; 118 * @param pmsMaps the map to dump 119 * @param psFile the the file pointer to store the map 120 * @param iLimit the number of maps to print (0 for no limit) 121 */ 122 void _dumpMapsToFile(maps* pmsMaps,FILE* psFile,int iLimit){ 123 maps* tmp=pmsMaps; 123 124 int cnt=0; 124 125 while(tmp!=NULL){ 125 fprintf( file,"[%s]\n",tmp->name);126 fprintf(psFile,"[%s]\n",tmp->name); 126 127 if(tmp->child!=NULL){ 127 _dumpMapsToFile(tmp->child, file,limit);128 _dumpMapsToFile(tmp->child,psFile,iLimit); 128 129 }else 129 dumpMapToFile(tmp->content, file);130 fflush( file);130 dumpMapToFile(tmp->content,psFile); 131 fflush(psFile); 131 132 tmp=tmp->next; 132 133 cnt++; 133 if( limit>=0 && cnt==limit)134 if(iLimit>=0 && cnt==iLimit) 134 135 tmp=NULL; 135 136 } 136 fflush( file);137 fflush(psFile); 137 138 } 138 139 … … 140 141 * Dump a maps to a file, see _dumpMapsToFile(). 141 142 * 142 * @param mthe map to dump143 * @param file_path the full path to the file nameto store the map144 * @param limit the number limiting the maps to be dumped145 */ 146 void dumpMapsToFile(maps* m,char* file_path,int limit){147 FILE* file=fopen(file_path,"w+");148 _dumpMapsToFile( m,file,limit);149 fflush( file);150 fclose( file);143 * @param pmsMaps the map to dump 144 * @param pcaFilePath the the file pointer to store the map 145 * @param iLimit the number of maps to print (0 for no limit) 146 */ 147 void dumpMapsToFile(maps* pmsMaps,char* pcaFilePath,int iLimit){ 148 FILE* psFile=fopen(pcaFilePath,"w+"); 149 _dumpMapsToFile(pmsMaps,psFile,iLimit); 150 fflush(psFile); 151 fclose(psFile); 151 152 } 152 153 … … 157 158 */ 158 159 iotype* createIoType(){ 159 iotype* io=(iotype*)malloc(IOTYPE_SIZE);160 io->content=NULL;161 io->next=NULL;162 return io;160 iotype* pioIO=(iotype*)malloc(IOTYPE_SIZE); 161 pioIO->content=NULL; 162 pioIO->next=NULL; 163 return pioIO; 163 164 } 164 165 … … 166 167 * Create a new map 167 168 * 168 * @param name the key to add to the map169 * @param value the corresponding value to add to the map169 * @param pccName the key to add to the map 170 * @param pccValue the corresponding value to add to the map 170 171 * @return a pointer to the allocated map 171 172 */ 172 map* createMap(const char* name,const char* value){173 map* tmp=(map *)malloc(MAP_SIZE);174 tmp->name=zStrdup(name);175 tmp->value=zStrdup(value);176 tmp->next=NULL;177 return tmp;173 map* createMap(const char* pccName,const char* pccValue){ 174 map* pmTtmp=(map *)malloc(MAP_SIZE); 175 pmTtmp->name=zStrdup(pccName); 176 pmTtmp->value=zStrdup(pccValue); 177 pmTtmp->next=NULL; 178 return pmTtmp; 178 179 } 179 180 … … 181 182 * Create a new maps with the given name 182 183 * 183 * @param name of the maps184 * @param pccName of the maps 184 185 * @return the allocated map 185 186 */ 186 maps* createMaps(const char* name){187 maps* tmp = (maps *) malloc (MAPS_SIZE);188 tmp->name = zStrdup (name);189 tmp->content = NULL;190 tmp->child = NULL;191 tmp->next = NULL;192 return tmp;187 maps* createMaps(const char* pccName){ 188 maps* pmTmp = (maps *) malloc (MAPS_SIZE); 189 pmTmp->name = zStrdup (pccName); 190 pmTmp->content = NULL; 191 pmTmp->child = NULL; 192 pmTmp->next = NULL; 193 return pmTmp; 193 194 } 194 195 … … 196 197 * Count number of map in a map 197 198 * 198 * @param mthe map to count199 * @param pmMap the map to count 199 200 * @return number of map in a map 200 201 */ 201 int count(map* m){202 map* tmp=m;202 int count(map* pmMap){ 203 map* pmTmp=pmMap; 203 204 int c=0; 204 while( tmp!=NULL){205 while(pmTmp!=NULL){ 205 206 c++; 206 tmp=tmp->next;207 pmTmp=pmTmp->next; 207 208 } 208 209 return c; … … 212 213 * Count number of maps in a maps 213 214 * 214 * @param mthe maps to count215 * @param pmMap the maps to count 215 216 * @return number of maps in a maps 216 217 */ 217 int maps_length(maps* m){218 maps* tmp=m;218 int maps_length(maps* pmMap){ 219 maps* pmTmp=pmMap; 219 220 int c=0; 220 while( tmp!=NULL){221 while(pmTmp!=NULL){ 221 222 c++; 222 tmp=tmp->next;223 pmTmp=pmTmp->next; 223 224 } 224 225 return c; … … 228 229 * Verify if a key exist in a map 229 230 * 230 * @param mthe map to search for the key231 * @param key the key to search in the map231 * @param pmMap the map to search for the key 232 * @param pccKey the key to search in the map 232 233 * @return true if the key wwas found, false in other case 233 234 */ 234 bool hasKey(map* m,const char *key){235 map* tmp=m;236 while( tmp!=NULL){237 if(strcasecmp( tmp->name,key)==0)235 bool hasKey(map* pmMap,const char *pccKey){ 236 map* pmTmp=pmMap; 237 while(pmTmp!=NULL){ 238 if(strcasecmp(pmTmp->name,pccKey)==0) 238 239 return true; 239 tmp=tmp->next;240 pmTmp=pmTmp->next; 240 241 } 241 242 #ifdef DEBUG_MAP … … 248 249 * Access a specific maps 249 250 * 250 * @param mthe maps to search for the key251 * @param key the key to search in the maps251 * @param pmMap the maps to search for the key 252 * @param pccKey the key to search in the maps 252 253 * @return a pointer on the maps found or NULL if not found 253 254 */ 254 maps* getMaps(maps* m,const char *key){255 maps* tmp=m;256 while( tmp!=NULL){257 if(strcasecmp( tmp->name,key)==0){258 return tmp;259 } 260 tmp=tmp->next;255 maps* getMaps(maps* pmsMaps,const char *pccKey){ 256 maps* pmTmp=pmsMaps; 257 while(pmTmp!=NULL){ 258 if(strcasecmp(pmTmp->name,pccKey)==0){ 259 return pmTmp; 260 } 261 pmTmp=pmTmp->next; 261 262 } 262 263 return NULL; … … 266 267 * Access a specific map 267 268 * 268 * @param mthe map to search for the key269 * @param key the key to search in the map269 * @param pmMap the map to search for the key 270 * @param pccKey the key to search in the map 270 271 * @return a pointer on the map found or NULL if not found 271 272 */ 272 map* getMap(map* m,const char *key){273 map* tmp=m;274 while( tmp!=NULL){275 if(strcasecmp( tmp->name,key)==0){276 return tmp;277 } 278 tmp=tmp->next;273 map* getMap(map* pmMap,const char *pccKey){ 274 map* pmTmp=pmMap; 275 while(pmTmp!=NULL){ 276 if(strcasecmp(pmTmp->name,pccKey)==0){ 277 return pmTmp; 278 } 279 pmTmp=pmTmp->next; 279 280 } 280 281 return NULL; … … 285 286 * Access the last map 286 287 * 287 * @param mthe map to search for the lastest map288 * @param pmMap the map to search for the lastest map 288 289 * @return a pointer on the lastest map found or NULL if not found 289 290 */ 290 map* getLastMap(map* m){291 map* tmp=m;292 while( tmp!=NULL){293 if( tmp->next==NULL){294 return tmp;295 } 296 tmp=tmp->next;291 map* getLastMap(map* pmMap){ 292 map* pmTmp=pmMap; 293 while(pmTmp!=NULL){ 294 if(pmTmp->next==NULL){ 295 return pmTmp; 296 } 297 pmTmp=pmTmp->next; 297 298 } 298 299 return NULL; … … 302 303 * Access a specific map from a maps 303 304 * 304 * @param mthe maps to search for the key305 * @param key the key to search in the maps306 * @param subkey the key to search in the map (found for the key, if any)305 * @param pmMap the maps to search for the key 306 * @param pccKey the key to search in the maps 307 * @param pccSubkey the key to search in the map (found for the key, if any) 307 308 * @return a pointer on the map found or NULL if not found 308 309 */ 309 map* getMapFromMaps(maps* m,const char* key,const char* subkey){310 maps* _tmpm=getMaps(m,key);311 if( _tmpm!=NULL){312 map* _ztmpm=getMap(_tmpm->content,subkey);313 return _ztmpm;310 map* getMapFromMaps(maps* pmMap,const char* pccKey,const char* pccSubkey){ 311 maps* pmTmp=getMaps(pmMap,pccKey); 312 if(pmTmp!=NULL){ 313 map* pmTmp1=getMap(pmTmp->content,pccSubkey); 314 return pmTmp1; 314 315 } 315 316 else return NULL; … … 320 321 * Require to call free on mo after calling this function. 321 322 * 322 * @param mothe map to free323 */ 324 void freeMap(map** mo){325 map* _cursor=*mo;326 if( _cursor!=NULL){323 * @param pmMap the map to free 324 */ 325 void freeMap(map** pmMap){ 326 map* pmCursor=*pmMap; 327 if(pmCursor!=NULL){ 327 328 #ifdef DEBUG 328 329 fprintf(stderr,"freeMap\n"); 329 330 #endif 330 if( _cursor->name!=NULL)331 free( _cursor->name);332 if( _cursor->value!=NULL)333 free( _cursor->value);334 if( _cursor->next!=NULL){335 freeMap(& _cursor->next);336 if( _cursor->next!=NULL)337 free( _cursor->next);331 if(pmCursor->name!=NULL) 332 free(pmCursor->name); 333 if(pmCursor->value!=NULL) 334 free(pmCursor->value); 335 if(pmCursor->next!=NULL){ 336 freeMap(&pmCursor->next); 337 if(pmCursor->next!=NULL) 338 free(pmCursor->next); 338 339 } 339 340 } … … 344 345 * Require to call free on mo after calling this function. 345 346 * 346 * @param mothe maps to free347 */ 348 void freeMaps(maps** mo){349 maps* _cursor=*mo;350 if( _cursor && _cursor!=NULL){347 * @param pmMap the maps to free 348 */ 349 void freeMaps(maps** pmMap){ 350 maps* pmCursor=*pmMap; 351 if(pmCursor && pmCursor!=NULL){ 351 352 #ifdef DEBUG 352 353 fprintf(stderr,"freeMaps\n"); 353 354 #endif 354 free( _cursor->name);355 if( _cursor->content!=NULL){356 freeMap(& _cursor->content);357 free( _cursor->content);358 } 359 if( _cursor->child!=NULL){360 freeMaps(& _cursor->child);361 free( _cursor->child);362 } 363 if( _cursor->next!=NULL){364 freeMaps(& _cursor->next);365 free( _cursor->next);355 free(pmCursor->name); 356 if(pmCursor->content!=NULL){ 357 freeMap(&pmCursor->content); 358 free(pmCursor->content); 359 } 360 if(pmCursor->child!=NULL){ 361 freeMaps(&pmCursor->child); 362 free(pmCursor->child); 363 } 364 if(pmCursor->next!=NULL){ 365 freeMaps(&pmCursor->next); 366 free(pmCursor->next); 366 367 } 367 368 } … … 371 372 * Verify if an elements contains a name equal to the given key. 372 373 * 373 * @param ethe elements to search for the key374 * @param key the elements name to search374 * @param peElem the elements to search for the key 375 * @param pccKey the elements name to search 375 376 * @return true if the elements contains the name, false in other cases. 376 377 */ 377 bool hasElement(elements* e,const char* key){378 elements* tmp=e;379 while( tmp!=NULL){380 if(strcasecmp( key,tmp->name)==0)378 bool hasElement(elements* peElem,const char* pccKey){ 379 elements* peTmp=peElem; 380 while(peTmp!=NULL){ 381 if(strcasecmp(pccKey,peTmp->name)==0) 381 382 return true; 382 tmp=tmp->next;383 peTmp=peTmp->next; 383 384 } 384 385 return false; … … 388 389 * Access a specific elements named key. 389 390 * 390 * @param m the elements to search391 * @param key the elements name to search391 * @param peElem the elements to search 392 * @param pccKey the elements name to search 392 393 * @return a pointer to the specific element if found, NULL in other case. 393 394 */ 394 elements* getElements(elements* m,const char *key){395 elements* tmp=m;396 while( tmp!=NULL){397 if(strcasecmp( tmp->name,key)==0)398 return tmp;399 tmp=tmp->next;395 elements* getElements(elements* peElem,const char *pccKey){ 396 elements* peTmp=peElem; 397 while(peTmp!=NULL){ 398 if(strcasecmp(peTmp->name,pccKey)==0) 399 return peTmp; 400 peTmp=peTmp->next; 400 401 } 401 402 return NULL; … … 406 407 * Require to call free on i after calling this function. 407 408 * 408 * @param ithe iotype to free409 */ 410 void freeIOType(iotype** i){411 iotype* _cursor=*i;412 if( _cursor!=NULL){413 if( _cursor->next!=NULL){414 freeIOType(& _cursor->next);415 free( _cursor->next);416 } 417 freeMap(& _cursor->content);418 free( _cursor->content);409 * @param piotIO the iotype to free 410 */ 411 void freeIOType(iotype** piotIO){ 412 iotype* piotCursor=*piotIO; 413 if(piotCursor!=NULL){ 414 if(piotCursor->next!=NULL){ 415 freeIOType(&piotCursor->next); 416 free(piotCursor->next); 417 } 418 freeMap(&piotCursor->content); 419 free(piotCursor->content); 419 420 } 420 421 } … … 424 425 * Require to call free on e after calling this function. 425 426 * 426 * @param ethe iotype to free427 */ 428 void freeElements(elements** e){429 elements* tmp=*e;430 if( tmp!=NULL){431 if( tmp->name!=NULL)432 free( tmp->name);433 freeMap(& tmp->content);434 if( tmp->content!=NULL)435 free( tmp->content);436 freeMap(& tmp->metadata);437 if( tmp->metadata!=NULL)438 free( tmp->metadata);439 freeMap(& tmp->additional_parameters);440 if( tmp->additional_parameters!=NULL)441 free( tmp->additional_parameters);442 if( tmp->format!=NULL)443 free( tmp->format);444 freeElements(& tmp->child);445 if( tmp->child!=NULL){446 free( tmp->child);447 } 448 if( tmp->defaults!=NULL){449 freeIOType(& tmp->defaults);450 free( tmp->defaults);451 } 452 if( tmp->supported!=NULL){453 freeIOType(& tmp->supported);454 free( tmp->supported);455 } 456 if( tmp->next!=NULL){457 freeElements(& tmp->next);458 free( tmp->next);427 * @param peElem the iotype to free 428 */ 429 void freeElements(elements** peElem){ 430 elements* peTmp=*peElem; 431 if(peTmp!=NULL){ 432 if(peTmp->name!=NULL) 433 free(peTmp->name); 434 freeMap(&peTmp->content); 435 if(peTmp->content!=NULL) 436 free(peTmp->content); 437 freeMap(&peTmp->metadata); 438 if(peTmp->metadata!=NULL) 439 free(peTmp->metadata); 440 freeMap(&peTmp->additional_parameters); 441 if(peTmp->additional_parameters!=NULL) 442 free(peTmp->additional_parameters); 443 if(peTmp->format!=NULL) 444 free(peTmp->format); 445 freeElements(&peTmp->child); 446 if(peTmp->child!=NULL){ 447 free(peTmp->child); 448 } 449 if(peTmp->defaults!=NULL){ 450 freeIOType(&peTmp->defaults); 451 free(peTmp->defaults); 452 } 453 if(peTmp->supported!=NULL){ 454 freeIOType(&peTmp->supported); 455 free(peTmp->supported); 456 } 457 if(peTmp->next!=NULL){ 458 freeElements(&peTmp->next); 459 free(peTmp->next); 459 460 } 460 461 } … … 469 470 */ 470 471 service* createService(){ 471 service * s1= (service *) malloc (SERVICE_SIZE);472 s1->name=NULL;473 s1->content=NULL;474 s1->metadata=NULL;475 s1->additional_parameters=NULL;476 s1->inputs=NULL;477 s1->outputs=NULL;478 return s1;472 service *psService = (service *) malloc (SERVICE_SIZE); 473 psService->name=NULL; 474 psService->content=NULL; 475 psService->metadata=NULL; 476 psService->additional_parameters=NULL; 477 psService->inputs=NULL; 478 psService->outputs=NULL; 479 return psService; 479 480 } 480 481 … … 483 484 * Require to be invoked for every createService call. 484 485 * 485 * @param sthe service to free486 */ 487 void freeService(service** s){488 service* tmp=*s;489 if( tmp!=NULL){490 if( tmp->name!=NULL)491 free( tmp->name);492 freeMap(& tmp->content);493 if( tmp->content!=NULL)494 free( tmp->content);495 freeMap(& tmp->metadata);496 if( tmp->metadata!=NULL)497 free( tmp->metadata);498 freeMap(& tmp->additional_parameters);499 if( tmp->additional_parameters!=NULL)500 free( tmp->additional_parameters);501 freeElements(& tmp->inputs);502 if( tmp->inputs!=NULL)503 free( tmp->inputs);504 freeElements(& tmp->outputs);505 if( tmp->outputs!=NULL)506 free( tmp->outputs);486 * @param psService the service to free 487 */ 488 void freeService(service** psService){ 489 service* psTmp=*psService; 490 if(psTmp!=NULL){ 491 if(psTmp->name!=NULL) 492 free(psTmp->name); 493 freeMap(&psTmp->content); 494 if(psTmp->content!=NULL) 495 free(psTmp->content); 496 freeMap(&psTmp->metadata); 497 if(psTmp->metadata!=NULL) 498 free(psTmp->metadata); 499 freeMap(&psTmp->additional_parameters); 500 if(psTmp->additional_parameters!=NULL) 501 free(psTmp->additional_parameters); 502 freeElements(&psTmp->inputs); 503 if(psTmp->inputs!=NULL) 504 free(psTmp->inputs); 505 freeElements(&psTmp->outputs); 506 if(psTmp->outputs!=NULL) 507 free(psTmp->outputs); 507 508 } 508 509 } … … 511 512 * Add key value pair to an existing map. 512 513 * 513 * @param mthe map to add the KVP514 * @param nthe key to add515 * @param vthe corresponding value to add516 */ 517 void addToMap(map* m,const char* n,const char* v){518 if (m!= NULL) { // knut: add NULL-pointer check519 if (hasKey(m, n) == false) {520 map* _cursor = m;521 while (_cursor->next != NULL) {522 _cursor = _cursor->next;523 524 _cursor->next = createMap(n, v);525 526 527 map *tmp = getMap(m, n);528 529 530 tmp->value = zStrdup(v);531 532 514 * @param pMap the map to add the KVP 515 * @param pccName the key to add 516 * @param pccValue the corresponding value to add 517 */ 518 void addToMap(map* pMap,const char* pccName,const char* pccValue){ 519 if (pMap != NULL) { // knut: add NULL-pointer check 520 if (hasKey(pMap, pccName) == false) { 521 map* pmCursor = pMap; 522 while (pmCursor->next != NULL) { 523 pmCursor = pmCursor->next; 524 } 525 pmCursor->next = createMap(pccName, pccValue); 526 } 527 else { 528 map *tmp = getMap(pMap, pccName); 529 if (tmp->value != NULL) 530 free(tmp->value); 531 tmp->value = zStrdup(pccValue); 532 } 533 } 533 534 } 534 535 … … 536 537 * Add a key and an integer value to an existing map. 537 538 * 538 * @param mthe map to add the KVP539 * @param nthe key to add540 * @param vthe corresponding value to add541 */ 542 void addIntToMap(map* m,const char* n,const int v){543 char svalue[10];544 sprintf( svalue,"%d",v);545 if(hasKey( m,n)==false){546 map* _cursor=m;547 while( _cursor->next!=NULL){548 _cursor=_cursor->next;549 } 550 _cursor->next=createMap(n,svalue);539 * @param pMap the map to add the KVP 540 * @param pccName the key to add 541 * @param iValue the corresponding value to add 542 */ 543 void addIntToMap(map* pMap,const char* pccName,const int iValue){ 544 char acValue[10]; 545 sprintf(acValue,"%d",iValue); 546 if(hasKey(pMap,pccName)==false){ 547 map* pmCursor=pMap; 548 while(pmCursor->next!=NULL){ 549 pmCursor=pmCursor->next; 550 } 551 pmCursor->next=createMap(pccName,acValue); 551 552 } 552 553 else{ 553 map * tmp=getMap(m,n);554 if( tmp->value!=NULL)555 free( tmp->value);556 tmp->value=zStrdup(svalue);554 map *pmTmp=getMap(pMap,pccName); 555 if(pmTmp->value!=NULL) 556 free(pmTmp->value); 557 pmTmp->value=zStrdup(acValue); 557 558 } 558 559 } … … 561 562 * Add a key and a binary value to an existing map. 562 563 * 563 * @param mthe map to add the KVP564 * @param nthe key to add565 * @param vthe corresponding value to add566 * @param size the size of the given value564 * @param pMap the map to add the KVP 565 * @param pccName the key to add 566 * @param pccValue the corresponding value to add 567 * @param iSize the size of the given value 567 568 * @return a pointer to the updated map m 568 569 */ 569 map* addToMapWithSize(map* m,const char* n,const char* v,int size){570 char sin[128];571 char sname[10]="size";572 map * tmp;573 if(hasKey( m,n)==false){574 map* _cursor= m;570 map* addToMapWithSize(map* pMap,const char* pccName,const char* pccValue,int iSize){ 571 char acIn[128]; 572 char acName[10]="size"; 573 map *pmTmp; 574 if(hasKey(pMap,pccName)==false){ 575 map* _cursor=pMap; 575 576 if(_cursor!=NULL){ 576 addToMap( m,n,"");577 addToMap(pMap,pccName,""); 577 578 }else{ 578 m=createMap(n,"");579 } 580 } 581 if(strlen( n)>5)582 sprintf( sname,"size_%s",n+6);583 tmp=getMap(m,n);584 if( tmp->value!=NULL)585 free( tmp->value);586 tmp->value=(char*)malloc((size+1)*sizeof(char));587 if( v!=NULL)588 memmove( tmp->value,v,size*sizeof(char));589 tmp->value[size]=0;590 sprintf( sin,"%d",size);591 addToMap( m,sname,sin);592 return m;579 pMap=createMap(pccName,""); 580 } 581 } 582 if(strlen(pccName)>5) 583 sprintf(acName,"size_%s",pccName+6); 584 pmTmp=getMap(pMap,pccName); 585 if(pmTmp->value!=NULL) 586 free(pmTmp->value); 587 pmTmp->value=(char*)malloc((iSize+1)*sizeof(char)); 588 if(pccValue!=NULL) 589 memmove(pmTmp->value,pccValue,iSize*sizeof(char)); 590 pmTmp->value[iSize]=0; 591 sprintf(acIn,"%d",iSize); 592 addToMap(pMap,acName,acIn); 593 return pMap; 593 594 } 594 595 … … 596 597 * Add a map at the end of another map. 597 598 * 598 * @param mo the map to add mi599 * @param mi the map to add to mo600 */ 601 void addMapToMap(map** mo,map* mi){602 map* tmp=mi;603 map* _cursor=*mo;604 while( tmp!=NULL){605 if( _cursor==NULL){606 * mo=createMap(tmp->name,tmp->value);607 (* mo)->next=NULL;599 * @param pmMapOut the map to add pmMapIn to 600 * @param pmMapIn the map to add to pmMapOut 601 */ 602 void addMapToMap(map** pmMapOut,map* pmMapIn){ 603 map* pmTmp=pmMapIn; 604 map* pmCursor=*pmMapOut; 605 while(pmTmp!=NULL){ 606 if(pmCursor==NULL){ 607 *pmMapOut=createMap(pmTmp->name,pmTmp->value); 608 (*pmMapOut)->next=NULL; 608 609 } 609 610 else{ 610 map* tmp1=getMap(*mo,tmp->name);611 if( tmp1==NULL){612 while( _cursor->next!=NULL)613 _cursor=_cursor->next;614 _cursor->next=createMap(tmp->name,tmp->value);611 map* pmTmp1=getMap(*pmMapOut,pmTmp->name); 612 if(pmTmp1==NULL){ 613 while(pmCursor->next!=NULL) 614 pmCursor=pmCursor->next; 615 pmCursor->next=createMap(pmTmp->name,pmTmp->value); 615 616 } 616 617 else{ 617 addToMap(* mo,tmp->name,tmp->value);618 addToMap(*pmMapOut,pmTmp->name,pmTmp->value); 618 619 } 619 620 } 620 _cursor=*mo;621 tmp=tmp->next;621 pmCursor=*pmMapOut; 622 pmTmp=pmTmp->next; 622 623 } 623 624 } … … 626 627 * Add a map to iotype. 627 628 * 628 * @param iothe iotype to add the map629 * @param mithe map to add to io630 */ 631 void addMapToIoType(iotype** io,map* mi){632 iotype* tmp=*io;633 while( tmp->next!=NULL){634 tmp=tmp->next;635 } 636 tmp->next=(iotype*)malloc(IOTYPE_SIZE);637 tmp->next->content=NULL;638 addMapToMap(& tmp->next->content,mi);639 tmp->next->next=NULL;629 * @param piotType the iotype to add the map 630 * @param pmMap the map to add to io 631 */ 632 void addMapToIoType(iotype** piotType,map* pmMap){ 633 iotype* piotTmp=*piotType; 634 while(piotTmp->next!=NULL){ 635 piotTmp=piotTmp->next; 636 } 637 piotTmp->next=(iotype*)malloc(IOTYPE_SIZE); 638 piotTmp->next->content=NULL; 639 addMapToMap(&piotTmp->next->content,pmMap); 640 piotTmp->next->next=NULL; 640 641 } 641 642 … … 643 644 * Access a specific map or set its value. 644 645 * 645 * @param mthe map to search for the key646 * @param key the key to search/add in the map647 * @param value the value to add if the key does not exist646 * @param ppmMap the map to search for the key 647 * @param pccKey the key to search/add in the map 648 * @param pccValue the value to add if the key does not exist 648 649 * @return a pointer on the map found or NULL if not found 649 650 */ 650 map* getMapOrFill(map** m,const char *key,const char* value){651 map* tmp=*m;652 map* tmpMap=getMap(tmp,key);653 if( tmpMap==NULL){654 if( tmp!=NULL){655 addToMap((* m),key,value);651 map* getMapOrFill(map** ppmMap,const char *pccKey,const char* pccValue){ 652 map* pmTmp=*ppmMap; 653 map* pmTmp1=getMap(pmTmp,pccKey); 654 if(pmTmp1==NULL){ 655 if(pmTmp!=NULL){ 656 addToMap((*ppmMap),pccKey,pccValue); 656 657 } 657 658 else 658 (* m)=createMap(key,value);659 tmpMap=getMap(*m,key);660 } 661 return tmpMap;659 (*ppmMap)=createMap(pccKey,pccValue); 660 pmTmp1=getMap(*ppmMap,pccKey); 661 } 662 return pmTmp1; 662 663 } 663 664 … … 665 666 * Verify if a map is contained in another map. 666 667 * 667 * @param mthe map to search for i668 * @param ithe map to search in m668 * @param pmMap the map to search for i 669 * @param pmSearch the map to search in m 669 670 * @return true if i was found in m, false in other case 670 671 */ 671 bool contains(map* m,map* i){672 while( i!=NULL){673 if(strcasecmp( i->name,"value")!=0 &&674 strcasecmp( i->name,"xlink:href")!=0 &&675 strcasecmp( i->name,"useMapServer")!=0 &&676 strcasecmp( i->name,"asReference")!=0){672 bool contains(map* pmMap,map* pmSearch){ 673 while(pmSearch!=NULL){ 674 if(strcasecmp(pmSearch->name,"value")!=0 && 675 strcasecmp(pmSearch->name,"xlink:href")!=0 && 676 strcasecmp(pmSearch->name,"useMapServer")!=0 && 677 strcasecmp(pmSearch->name,"asReference")!=0){ 677 678 map *tmp; 678 if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 679 strcasecmp(i->value,tmp->value)!=0) 679 if(hasKey(pmMap,pmSearch->name) && 680 (tmp=getMap(pmMap,pmSearch->name))!=NULL && 681 strcasecmp(pmSearch->value,tmp->value)!=0) 680 682 return false; 681 683 } 682 i=i->next;684 pmSearch=pmSearch->next; 683 685 } 684 686 return true; … … 688 690 * Access a specific iotype from an elements. 689 691 * 690 * @param ethe elements to search for the name691 * @param name the name to search in the elements e692 * @param values the map to verify it was contained in the defaults or692 * @param peElem the elements to search for the name 693 * @param pcName the name to search in the elements e 694 * @param pcValues the map to verify it was contained in the defaults or 693 695 * supported content of the elements e 694 696 * @return a pointer on the iotype found or NULL if not found 695 697 */ 696 iotype* getIoTypeFromElement(elements* e,char *name, map* values){697 elements* cursor=e;698 if( values!=NULL){699 while( cursor!=NULL){700 if(strcasecmp( cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){701 if(contains( cursor->defaults->content,values)==true)702 return cursor->defaults;698 iotype* getIoTypeFromElement(elements* peElem,char *pcName, map* pcValues){ 699 elements* peCursor=peElem; 700 if(pcValues!=NULL){ 701 while(peCursor!=NULL){ 702 if(strcasecmp(peCursor->name,pcName)==0 && (peCursor->defaults!=NULL || peCursor->supported!=NULL)){ 703 if(contains(peCursor->defaults->content,pcValues)==true) 704 return peCursor->defaults; 703 705 else{ 704 iotype* tmp= cursor->supported;706 iotype* tmp=peCursor->supported; 705 707 while(tmp!=NULL){ 706 if(contains(tmp->content, values)==true)708 if(contains(tmp->content,pcValues)==true) 707 709 return tmp; 708 710 tmp=tmp->next; … … 710 712 } 711 713 } 712 cursor=cursor->next;714 peCursor=peCursor->next; 713 715 } 714 716 }else{ 715 while( cursor!=NULL){716 if(strcasecmp( cursor->name,name)==0 && cursor->defaults!=NULL){717 return cursor->defaults;717 while(peCursor!=NULL){ 718 if(strcasecmp(peCursor->name,pcName)==0 && peCursor->defaults!=NULL){ 719 return peCursor->defaults; 718 720 } 719 cursor=cursor->next;721 peCursor=peCursor->next; 720 722 } 721 723 } … … 726 728 * Load binary values from a map (in) and add them to another map (out) 727 729 * 728 * @param out the map to add binaries values729 * @param in the map containing the binary values to add ti out730 * @param pos index of the binary in an array (in case of "MapArray")731 */ 732 void loadMapBinary(map** out,map* in,int pos){733 map* size=getMap(in,"size");734 map * lout=*out;735 map * tmpVin,*tmpVout;736 if( size!=NULL && pos>0){730 * @param pmOut the map to add binaries values 731 * @param pmIn the map containing the binary values to add ti out 732 * @param iPos index of the binary in an array (in case of "MapArray") 733 */ 734 void loadMapBinary(map** ppmOut,map* pmIn,int iPos){ 735 map* pmSize=getMap(pmIn,"size"); 736 map *pmOut=*ppmOut; 737 map *pmTmpVin,*pmTmpVout; 738 if(pmSize!=NULL && iPos>0){ 737 739 char tmp[11]; 738 sprintf(tmp,"size_%d", pos);739 size=getMap(in,tmp);740 sprintf(tmp,"value_%d", pos);741 tmpVin=getMap(in,tmp);742 tmpVout=getMap(lout,tmp);743 free( tmpVout->value);744 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));745 memmove( tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));746 tmpVout->value[atoi(size->value)]=0;740 sprintf(tmp,"size_%d",iPos); 741 pmSize=getMap(pmIn,tmp); 742 sprintf(tmp,"value_%d",iPos); 743 pmTmpVin=getMap(pmIn,tmp); 744 pmTmpVout=getMap(pmOut,tmp); 745 free(pmTmpVout->value); 746 pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char)); 747 memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char)); 748 pmTmpVout->value[atoi(pmSize->value)]=0; 747 749 }else{ 748 if( size!=NULL){749 tmpVin=getMap(in,"value");750 tmpVout=getMap(lout,"value");751 free( tmpVout->value);752 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));753 memmove( tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));754 tmpVout->value[atoi(size->value)]=0;755 } 756 } 757 } 758 750 if(pmSize!=NULL){ 751 pmTmpVin=getMap(pmIn,"value"); 752 pmTmpVout=getMap(pmOut,"value"); 753 free(pmTmpVout->value); 754 pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char)); 755 memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char)); 756 pmTmpVout->value[atoi(pmSize->value)]=0; 757 } 758 } 759 } 760 759 761 /** 760 762 * Load binary values from a map (in) and add them to another map (out). … … 762 764 * @see loadMapBinary 763 765 * 764 * @param out the map to add binaries values765 * @param in the map containing the binary values to add ti out766 */ 767 void loadMapBinaries(map** out,map* in){768 map* size=getMap(in,"size");769 map* length=getMap(in,"length");770 map* toload=getMap(in,"to_load");771 if( toload!=NULL && strcasecmp(toload->value,"false")==0){766 * @param ppmOut the map to add binaries values 767 * @param pmIn the map containing the binary values to add ti out 768 */ 769 void loadMapBinaries(map** ppmOut,map* pmIn){ 770 map* pmSize=getMap(pmIn,"size"); 771 map* pmLength=getMap(pmIn,"length"); 772 map* pmToload=getMap(pmIn,"to_load"); 773 if(pmToload!=NULL && strcasecmp(pmToload->value,"false")==0){ 772 774 #ifdef DEBUG 773 775 fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__); … … 775 777 return ; 776 778 } 777 if( length!=NULL){778 int len=atoi( length->value);779 if(pmLength!=NULL){ 780 int len=atoi(pmLength->value); 779 781 int i=0; 780 782 for(i=0;i<len;i++){ 781 loadMapBinary( out,in,i);783 loadMapBinary(ppmOut,pmIn,i); 782 784 } 783 785 } 784 786 else 785 if( size!=NULL)786 loadMapBinary( out,in,-1);787 if(pmSize!=NULL) 788 loadMapBinary(ppmOut,pmIn,-1); 787 789 } 788 790 … … 790 792 * Duplicate a Maps 791 793 * 792 * @param mothe maps to clone794 * @param ppmsOut the maps to clone 793 795 * @return the allocated maps containing a copy of the mo maps 794 796 */ 795 maps* dupMaps(maps** mo){796 maps* _cursor=*mo;797 maps* res=NULL;798 if( _cursor!=NULL){799 map* mc=_cursor->content;800 maps* mcs=_cursor->child;801 res=createMaps(_cursor->name);802 if( mc!=NULL){803 addMapToMap(& res->content,mc);804 loadMapBinaries(& res->content,mc);805 } 806 if( mcs!=NULL){807 res->child=dupMaps(&mcs);808 } 809 res->next=dupMaps(&_cursor->next);810 } 811 return res;797 maps* dupMaps(maps** ppmsOut){ 798 maps* pmsCursor=*ppmsOut; 799 maps* pmRes=NULL; 800 if(pmsCursor!=NULL){ 801 map* pmContent=pmsCursor->content; 802 maps* pmsChild=pmsCursor->child; 803 pmRes=createMaps(pmsCursor->name); 804 if(pmContent!=NULL){ 805 addMapToMap(&pmRes->content,pmContent); 806 loadMapBinaries(&pmRes->content,pmContent); 807 } 808 if(pmsChild!=NULL){ 809 pmRes->child=dupMaps(&pmsChild); 810 } 811 pmRes->next=dupMaps(&pmsCursor->next); 812 } 813 return pmRes; 812 814 } 813 815 … … 816 818 * 817 819 * @see addMapToMap, dupMaps, getMaps 818 * @param mothe maps to add mi819 * @param mithe maps to add to mo820 */ 821 void addMapsToMaps(maps** mo,maps* mi){822 maps* tmp=mi;823 maps* _cursor=*mo;824 while( tmp!=NULL){825 if( _cursor==NULL){826 * mo=dupMaps(&mi);820 * @param ppmsOut the maps to add mi 821 * @param pmIn the maps to add to mo 822 */ 823 void addMapsToMaps(maps** ppmsOut,maps* pmIn){ 824 maps* pmsTmp=pmIn; 825 maps* pmsCursor=*ppmsOut; 826 while(pmsTmp!=NULL){ 827 if(pmsCursor==NULL){ 828 *ppmsOut=dupMaps(&pmIn); 827 829 } 828 830 else{ 829 maps* tmp1=getMaps(*mo,tmp->name);830 if( tmp1==NULL){831 while( _cursor->next!=NULL)832 _cursor=_cursor->next;833 _cursor->next=dupMaps(&tmp);834 if( tmp->child!=NULL)835 _cursor->next->child=dupMaps(&tmp->child);831 maps* pmsTmp1=getMaps(*ppmsOut,pmsTmp->name); 832 if(pmsTmp1==NULL){ 833 while(pmsCursor->next!=NULL) 834 pmsCursor=pmsCursor->next; 835 pmsCursor->next=dupMaps(&pmsTmp); 836 if(pmsTmp->child!=NULL) 837 pmsCursor->next->child=dupMaps(&pmsTmp->child); 836 838 else 837 _cursor->next->child=NULL;839 pmsCursor->next->child=NULL; 838 840 } 839 841 else{ 840 addMapToMap(& tmp1->content,tmp->content);841 if( tmp->child!=NULL)842 tmp1->child=dupMaps(&tmp->child);842 addMapToMap(&pmsTmp1->content,pmsTmp->content); 843 if(pmsTmp->child!=NULL) 844 pmsTmp1->child=dupMaps(&pmsTmp->child); 843 845 else 844 tmp1->child=NULL;846 pmsTmp1->child=NULL; 845 847 } 846 _cursor=*mo;847 } 848 tmp=tmp->next;848 pmsCursor=*ppmsOut; 849 } 850 pmsTmp=pmsTmp->next; 849 851 } 850 852 } … … 853 855 * Access a specific map array element 854 856 * 855 * @param mthe map to search for the key856 * @param key the key to search in the map857 * @param i ndex of the MapArray857 * @param pmMap the map to search for the key 858 * @param pccKey the key to search in the map 859 * @param iIndex of the MapArray 858 860 * @return a pointer on the map found or NULL if not found 859 861 */ 860 map* getMapArray(map* m,const char* key,int index){861 char tmp[1024];862 map* tmpMap;863 if(i ndex>0)864 sprintf( tmp,"%s_%d",key,index);862 map* getMapArray(map* pmMap,const char* pccKey,int iIndex){ 863 char acTmp[1024]; 864 map* pmTmp; 865 if(iIndex>0) 866 sprintf(acTmp,"%s_%d",pccKey,iIndex); 865 867 else 866 sprintf( tmp,"%s",key);868 sprintf(acTmp,"%s",pccKey); 867 869 #ifdef DEBUG 868 fprintf(stderr,"** KEY %s\n", tmp);870 fprintf(stderr,"** KEY %s\n",acTmp); 869 871 #endif 870 tmpMap=getMap(m,tmp);872 pmTmp=getMap(pmMap,acTmp); 871 873 #ifdef DEBUG 872 if( tmpMap!=NULL)873 dumpMap( tmpMap);874 if(pmTmp!=NULL) 875 dumpMap(pmTmp); 874 876 #endif 875 return tmpMap;877 return pmTmp; 876 878 } 877 879 … … 879 881 * Add a key value in a MapArray for a specific index 880 882 * 881 * @param mthe map to search for the key882 * @param key the key to search in the map883 * @param i ndex the index of the MapArray884 * @param value the value to set in the MapArray883 * @param pmMap the map to search for the key 884 * @param pccKey the key to search in the map 885 * @param iIndex the index of the MapArray 886 * @param pccValue the value to set in the MapArray 885 887 * @return a pointer on the map found or NULL if not found 886 888 */ 887 void setMapArray(map* m,const char* key,int index,const char* value){888 char tmp[1024];889 map* tmpSize;890 if(i ndex>0){891 map* len=getMap(m,"length");892 sprintf( tmp,"%s_%d",key,index);893 if(( len!=NULL && atoi(len->value)<index+1) || len==NULL){894 char tmp0[5];895 sprintf( tmp0,"%d",index+1);896 addToMap( m,"length",tmp0);889 void setMapArray(map* pmMap,const char* pccKey,int iIndex,const char* pccValue){ 890 char acTmp[1024]; 891 map* pmSize; 892 if(iIndex>0){ 893 map* pmLen=getMap(pmMap,"length"); 894 sprintf(acTmp,"%s_%d",pccKey,iIndex); 895 if((pmLen!=NULL && atoi(pmLen->value)<iIndex+1) || pmLen==NULL){ 896 char acTmp0[5]; 897 sprintf(acTmp0,"%d",iIndex+1); 898 addToMap(pmMap,"length",acTmp0); 897 899 } 898 900 } 899 901 else{ 900 sprintf( tmp,"%s",key);901 addToMap( m,"length","1");902 } 903 tmpSize=getMapArray(m,"size",index);904 if( tmpSize!=NULL && strncasecmp(key,"value",5)==0){905 map* p tr=getMapOrFill(&m,tmp,(char *)"");902 sprintf(acTmp,"%s",pccKey); 903 addToMap(pmMap,"length","1"); 904 } 905 pmSize=getMapArray(pmMap,"size",iIndex); 906 if(pmSize!=NULL && strncasecmp(pccKey,"value",5)==0){ 907 map* pmPtr=getMapOrFill(&pmMap,acTmp,(char *)""); 906 908 #ifdef DEBUG 907 fprintf(stderr,"%s\n", tmpSize->value);909 fprintf(stderr,"%s\n",pmSize->value); 908 910 #endif 909 free(p tr->value);910 p tr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));911 memcpy(p tr->value,value,atoi(tmpSize->value));911 free(pmPtr->value); 912 pmPtr->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char)); 913 memcpy(pmPtr->value,pccValue,atoi(pmSize->value)); 912 914 } 913 915 else 914 addToMap( m,tmp,value);916 addToMap(pmMap,acTmp,pccValue); 915 917 } 916 918 … … 918 920 * Add a key and an integer value to an existing map array. 919 921 * 920 * @param mthe map to add the KVP921 * @param nthe key to add922 * @param i ndex the index of the MapArray923 * @param vthe corresponding value to add924 */ 925 void addIntToMapArray(map* m,const char* n,int index,const int v){926 char svalue[10];927 sprintf( svalue,"%d",v);928 setMapArray( m,n,index,svalue);922 * @param pmMap the map to add the KVP 923 * @param pccName the key to add 924 * @param iIndex the index of the MapArray 925 * @param icValue the corresponding value to add 926 */ 927 void addIntToMapArray(map* pmMap,const char* pccName,int iIndex,const int icValue){ 928 char acValue[10]; 929 sprintf(acValue,"%d",icValue); 930 setMapArray(pmMap,pccName,iIndex,acValue); 929 931 } 930 932 … … 932 934 * Access the map "type" 933 935 * 934 * @param mtthe map936 * @param pmMap the map 935 937 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in 936 938 * other case 937 939 */ 938 map* getMapType(map* mt){939 map* tmap=getMap(mt,(char *)"mimeType");940 if( tmap==NULL){941 tmap=getMap(mt,"dataType");942 if( tmap==NULL){943 tmap=getMap(mt,"CRS");940 map* getMapType(map* pmMap){ 941 map* pmMime=getMap(pmMap,(char *)"mimeType"); 942 if(pmMime==NULL){ 943 pmMime=getMap(pmMap,"dataType"); 944 if(pmMime==NULL){ 945 pmMime=getMap(pmMap,"CRS"); 944 946 } 945 947 } 946 948 #ifdef DEBUG 947 dumpMap( tmap);949 dumpMap(pmMime); 948 950 #endif 949 return tmap;951 return pmMime; 950 952 } 951 953 … … 954 956 * 955 957 * @see getMapType 956 * @param mothe maps957 * @param mithe maps958 * @param typthe map "type"958 * @param pmsOut the maps 959 * @param pmsIn the maps 960 * @param pcType the map "type" 959 961 * @return 960 962 */ 961 int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){962 maps* tmp=mi;963 maps* _cursor=getMaps(*mo,tmp->name);964 char tmpLen[10];965 int len=1;966 char * tmpV[14]={963 int addMapsArrayToMaps(maps** pmsOut,maps* pmsIn,char* pcType){ 964 maps* pmsTmp=pmsIn; 965 maps* pmsCursor=getMaps(*pmsOut,pmsTmp->name); 966 char acLen[10]; 967 int iLen=1; 968 char *acV[14]={ 967 969 (char*)"size", 968 970 (char*)"value", … … 973 975 (char*)"fmimeType", 974 976 (char*)"xlink:href", 975 typ,977 pcType, 976 978 (char*)"schema", 977 979 (char*)"encoding", … … 980 982 (char*)"UpperCorner" 981 983 }; 982 int i =0;983 map* tmpLength;984 int iCounter=0; 985 map* pmLength; 984 986 985 if( _cursor==NULL)987 if(pmsCursor==NULL) 986 988 return -1; 987 989 988 tmpLength=getMap(_cursor->content,"length");989 if( tmpLength!=NULL){990 len=atoi(tmpLength->value);991 } 992 993 sprintf( tmpLen,"%d",len+1);994 addToMap( _cursor->content,"length",tmpLen);995 for(i =0;i<14;i++){996 map* tmpVI=getMap(tmp->content,tmpV[i]);997 if( tmpVI!=NULL){990 pmLength=getMap(pmsCursor->content,"length"); 991 if(pmLength!=NULL){ 992 iLen=atoi(pmLength->value); 993 } 994 995 sprintf(acLen,"%d",iLen+1); 996 addToMap(pmsCursor->content,"length",acLen); 997 for(iCounter=0;iCounter<14;iCounter++){ 998 map* pmTmp=getMap(pmsTmp->content,acV[iCounter]); 999 if(pmTmp!=NULL){ 998 1000 #ifdef DEBUG 999 fprintf(stderr,"%s = %s\n", tmpV[i],tmpVI->value);1001 fprintf(stderr,"%s = %s\n",pmTmp[iCounter],pmTmp->value); 1000 1002 #endif 1001 setMapArray( _cursor->content,tmpV[i],len,tmpVI->value);1003 setMapArray(pmsCursor->content,acV[iCounter],iLen,pmTmp->value); 1002 1004 } 1003 1005 } 1004 1006 1005 addToMap( _cursor->content,"isArray","true");1007 addToMap(pmsCursor->content,"isArray","true"); 1006 1008 return 0; 1007 1009 } … … 1010 1012 * Set a key value pair to a map contained in a Maps 1011 1013 * 1012 * @param mthe maps1013 * @param key the maps name1014 * @param subkey the map name included in the maps corresponding to key1015 * @param value the corresponding value to add in the map1016 */ 1017 void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){1018 maps* _tmpm=getMaps(m,key);1019 if( _tmpm!=NULL){1020 map* _ztmpm=getMap(_tmpm->content,subkey);1021 if( _ztmpm!=NULL){1022 if( _ztmpm->value!=NULL)1023 free( _ztmpm->value);1024 _ztmpm->value=zStrdup(value);1014 * @param pmsMaps the maps 1015 * @param pccKey the maps name 1016 * @param pccSubkey the map name included in the maps corresponding to key 1017 * @param pccValue the corresponding value to add in the map 1018 */ 1019 void setMapInMaps(maps* pmsMaps,const char* pccKey,const char* pccSubkey,const char *pccValue){ 1020 maps* pmsTmp=getMaps(pmsMaps,pccKey); 1021 if(pmsTmp!=NULL){ 1022 map* pmTmpSub=getMap(pmsTmp->content,pccSubkey); 1023 if(pmTmpSub!=NULL){ 1024 if(pmTmpSub->value!=NULL) 1025 free(pmTmpSub->value); 1026 pmTmpSub->value=zStrdup(pccValue); 1025 1027 }else{ 1026 maps * tmp=createMaps(key);1027 tmp->content=createMap(subkey,value);1028 addMapsToMaps(& _tmpm,tmp);1029 freeMaps(& tmp);1030 free( tmp);1028 maps *pmsToAdd=createMaps(pccKey); 1029 pmsToAdd->content=createMap(pccSubkey,pccValue); 1030 addMapsToMaps(&pmsTmp,pmsToAdd); 1031 freeMaps(&pmsToAdd); 1032 free(pmsToAdd); 1031 1033 } 1032 1034 }else{ 1033 maps * tmp=createMaps(key);1034 tmp->content=createMap(subkey,value);1035 addMapsToMaps(& m,tmp);1036 freeMaps(& tmp);1037 free( tmp);1035 maps *pmsToAdd=createMaps(pccKey); 1036 pmsToAdd->content=createMap(pccSubkey,pccValue); 1037 addMapsToMaps(&pmsMaps,pmsToAdd); 1038 freeMaps(&pmsToAdd); 1039 free(pmsToAdd); 1038 1040 } 1039 1041 } … … 1045 1047 */ 1046 1048 elements* createEmptyElements(){ 1047 elements* res=(elements*)malloc(ELEMENTS_SIZE);1048 res->name=NULL;1049 res->content=NULL;1050 res->metadata=NULL;1051 res->additional_parameters=NULL;1052 res->format=NULL;1053 res->defaults=NULL;1054 res->supported=NULL;1055 res->child=NULL;1056 res->next=NULL;1057 return res;1049 elements* peRes=(elements*)malloc(ELEMENTS_SIZE); 1050 peRes->name=NULL; 1051 peRes->content=NULL; 1052 peRes->metadata=NULL; 1053 peRes->additional_parameters=NULL; 1054 peRes->format=NULL; 1055 peRes->defaults=NULL; 1056 peRes->supported=NULL; 1057 peRes->child=NULL; 1058 peRes->next=NULL; 1059 return peRes; 1058 1060 } 1059 1061 … … 1061 1063 * Create a named elements 1062 1064 * 1063 * @param name the elements name1065 * @param pcName the elements name 1064 1066 * @return a pointer to the allocated elements 1065 1067 */ 1066 elements* createElements(const char* name){1067 elements* res=(elements*)malloc(ELEMENTS_SIZE);1068 res->name=zStrdup(name);1069 res->content=NULL;1070 res->metadata=NULL;1071 res->additional_parameters=NULL;1072 res->format=NULL;1073 res->defaults=NULL;1074 res->supported=NULL;1075 res->child=NULL;1076 res->next=NULL;1077 return res;1068 elements* createElements(const char* pcName){ 1069 elements* peRes=(elements*)malloc(ELEMENTS_SIZE); 1070 peRes->name=zStrdup(pcName); 1071 peRes->content=NULL; 1072 peRes->metadata=NULL; 1073 peRes->additional_parameters=NULL; 1074 peRes->format=NULL; 1075 peRes->defaults=NULL; 1076 peRes->supported=NULL; 1077 peRes->child=NULL; 1078 peRes->next=NULL; 1079 return peRes; 1078 1080 } 1079 1081 … … 1081 1083 * Set the name of an elements 1082 1084 * 1083 * @param name the elements name 1085 * @param peElem the elements to modify 1086 * @param pcName the elements name 1084 1087 * @return a pointer to the allocated elements 1085 1088 */ 1086 void setElementsName(elements** elem,char* name){1087 elements* res=*elem;1088 res->name=zStrdup(name);1089 res->content=NULL;1090 res->metadata=NULL;1091 res->format=NULL;1092 res->defaults=NULL;1093 res->supported=NULL;1094 res->child=NULL;1095 res->next=NULL;1089 void setElementsName(elements** ppeElem,char* pcName){ 1090 elements* peRes=*ppeElem; 1091 peRes->name=zStrdup(pcName); 1092 peRes->content=NULL; 1093 peRes->metadata=NULL; 1094 peRes->format=NULL; 1095 peRes->defaults=NULL; 1096 peRes->supported=NULL; 1097 peRes->child=NULL; 1098 peRes->next=NULL; 1096 1099 } 1097 1100 … … 1099 1102 * Dump an elements on stderr 1100 1103 * 1101 * @param ethe elements to dump1102 */ 1103 void dumpElements(elements* e){1104 elements* tmp=e;1105 while( tmp!=NULL){1106 iotype* tmpio=tmp->defaults;1104 * @param peElem the elements to dump 1105 */ 1106 void dumpElements(elements* peElem){ 1107 elements* peTmp=peElem; 1108 while(peTmp!=NULL){ 1109 iotype* piotTmp=peTmp->defaults; 1107 1110 int ioc=0; 1108 fprintf(stderr,"ELEMENT [%s]\n", tmp->name);1109 fprintf(stderr," > CONTENT [%s]\n", tmp->name);1110 dumpMap( tmp->content);1111 fprintf(stderr," > METADATA [%s]\n", tmp->name);1112 dumpMap( tmp->metadata);1113 fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n", tmp->name);1114 dumpMap( tmp->additional_parameters);1115 fprintf(stderr," > FORMAT [%s]\n", tmp->format);1116 while( tmpio!=NULL){1117 fprintf(stderr," > DEFAULTS [%s] (%i)\n", tmp->name,ioc);1118 dumpMap( tmpio->content);1119 tmpio=tmpio->next;1111 fprintf(stderr,"ELEMENT [%s]\n",peTmp->name); 1112 fprintf(stderr," > CONTENT [%s]\n",peTmp->name); 1113 dumpMap(peTmp->content); 1114 fprintf(stderr," > METADATA [%s]\n",peTmp->name); 1115 dumpMap(peTmp->metadata); 1116 fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",peTmp->name); 1117 dumpMap(peTmp->additional_parameters); 1118 fprintf(stderr," > FORMAT [%s]\n",peTmp->format); 1119 while(piotTmp!=NULL){ 1120 fprintf(stderr," > DEFAULTS [%s] (%i)\n",peTmp->name,ioc); 1121 dumpMap(piotTmp->content); 1122 piotTmp=piotTmp->next; 1120 1123 ioc++; 1121 1124 } 1122 tmpio=tmp->supported;1125 piotTmp=peTmp->supported; 1123 1126 ioc=0; 1124 while( tmpio!=NULL){1125 fprintf(stderr," > SUPPORTED [%s] (%i)\n", tmp->name,ioc);1126 dumpMap( tmpio->content);1127 tmpio=tmpio->next;1127 while(piotTmp!=NULL){ 1128 fprintf(stderr," > SUPPORTED [%s] (%i)\n",peTmp->name,ioc); 1129 dumpMap(piotTmp->content); 1130 piotTmp=piotTmp->next; 1128 1131 ioc++; 1129 1132 } 1130 if( tmp->child!=NULL){1133 if(peTmp->child!=NULL){ 1131 1134 fprintf(stderr," > CHILD \n"); 1132 dumpElements( tmp->child);1135 dumpElements(peTmp->child); 1133 1136 } 1134 1137 fprintf(stderr,"------------------\n"); 1135 tmp=tmp->next;1138 peTmp=peTmp->next; 1136 1139 } 1137 1140 } … … 1140 1143 * Dump an elements on stderr using the YAML syntaxe 1141 1144 * 1142 * @param e the elements to dump 1143 */ 1144 void dumpElementsAsYAML(elements* e,int level){ 1145 elements* tmp=e; 1145 * @param peElem the elements to dump 1146 * @param iLevel the current level 1147 */ 1148 void dumpElementsAsYAML(elements* peElem,int iLevel){ 1149 elements* peTmp=peElem; 1146 1150 int i; 1147 while( tmp!=NULL){1148 map* mcurs=tmp->content;1151 while(peTmp!=NULL){ 1152 map* pmCurs=peTmp->content; 1149 1153 int ioc=0; 1150 iotype* tmpio;1151 for(i=0;i<2+(4* level);i++)1154 iotype* piotTmp; 1155 for(i=0;i<2+(4*iLevel);i++) 1152 1156 fprintf(stderr," "); 1153 fprintf(stderr,"%s:\n", tmp->name);1154 while( mcurs!=NULL){1155 for(i=0;i<4+(4* level);i++)1157 fprintf(stderr,"%s:\n",peTmp->name); 1158 while(pmCurs!=NULL){ 1159 for(i=0;i<4+(4*iLevel);i++) 1156 1160 fprintf(stderr," "); 1157 _dumpMap( mcurs);1158 mcurs=mcurs->next;1159 } 1160 mcurs=tmp->metadata;1161 if( mcurs!=NULL){1162 for(i=0;i<4+(4* level);i++)1161 _dumpMap(pmCurs); 1162 pmCurs=pmCurs->next; 1163 } 1164 pmCurs=peTmp->metadata; 1165 if(pmCurs!=NULL){ 1166 for(i=0;i<4+(4*iLevel);i++) 1163 1167 fprintf(stderr," "); 1164 1168 fprintf(stderr,"MetaData:\n"); 1165 while( mcurs!=NULL){1166 for(i=0;i<6+(4* level);i++)1169 while(pmCurs!=NULL){ 1170 for(i=0;i<6+(4*iLevel);i++) 1167 1171 fprintf(stderr," "); 1168 _dumpMap( mcurs);1169 mcurs=mcurs->next;1172 _dumpMap(pmCurs); 1173 pmCurs=pmCurs->next; 1170 1174 } 1171 1175 } 1172 for(i=0;i<4+(4* level);i++)1176 for(i=0;i<4+(4*iLevel);i++) 1173 1177 fprintf(stderr," "); 1174 if( tmp->format!=NULL)1175 fprintf(stderr,"%s:\n", tmp->format);1178 if(peTmp->format!=NULL) 1179 fprintf(stderr,"%s:\n",peTmp->format); 1176 1180 else{ 1177 1181 fprintf(stderr,"Child:\n"); 1178 if( tmp->child!=NULL)1179 dumpElementsAsYAML( tmp->child,level+1);1180 } 1181 tmpio=tmp->defaults;1182 while( tmpio!=NULL){1183 for(i=0;i<6+(4* level);i++)1182 if(peTmp->child!=NULL) 1183 dumpElementsAsYAML(peTmp->child,iLevel+1); 1184 } 1185 piotTmp=peTmp->defaults; 1186 while(piotTmp!=NULL){ 1187 for(i=0;i<6+(4*iLevel);i++) 1184 1188 fprintf(stderr," "); 1185 1189 fprintf(stderr,"default:\n"); 1186 mcurs=tmpio->content;1187 while( mcurs!=NULL){1188 for(i=0;i<8+(4* level);i++)1190 pmCurs=piotTmp->content; 1191 while(pmCurs!=NULL){ 1192 for(i=0;i<8+(4*iLevel);i++) 1189 1193 fprintf(stderr," "); 1190 if(strcasecmp( mcurs->name,"range")==0){1191 fprintf(stderr,"range: \"%s\"\n", mcurs->value);1194 if(strcasecmp(pmCurs->name,"range")==0){ 1195 fprintf(stderr,"range: \"%s\"\n",pmCurs->value); 1192 1196 }else 1193 _dumpMap( mcurs);1194 mcurs=mcurs->next;1197 _dumpMap(pmCurs); 1198 pmCurs=pmCurs->next; 1195 1199 } 1196 tmpio=tmpio->next;1200 piotTmp=piotTmp->next; 1197 1201 ioc++; 1198 1202 } 1199 tmpio=tmp->supported;1203 piotTmp=peTmp->supported; 1200 1204 ioc=0; 1201 while( tmpio!=NULL){1202 for(i=0;i<6+(4* level);i++)1205 while(piotTmp!=NULL){ 1206 for(i=0;i<6+(4*iLevel);i++) 1203 1207 fprintf(stderr," "); 1204 1208 fprintf(stderr,"supported:\n"); 1205 mcurs=tmpio->content;1206 while( mcurs!=NULL){1207 for(i=0;i<8+(4* level);i++)1209 pmCurs=piotTmp->content; 1210 while(pmCurs!=NULL){ 1211 for(i=0;i<8+(4*iLevel);i++) 1208 1212 fprintf(stderr," "); 1209 if(strcasecmp( mcurs->name,"range")==0){1210 fprintf(stderr,"range: \"%s\"\n", mcurs->value);1213 if(strcasecmp(pmCurs->name,"range")==0){ 1214 fprintf(stderr,"range: \"%s\"\n",pmCurs->value); 1211 1215 }else 1212 _dumpMap( mcurs);1213 mcurs=mcurs->next;1216 _dumpMap(pmCurs); 1217 pmCurs=pmCurs->next; 1214 1218 } 1215 tmpio=tmpio->next;1219 piotTmp=piotTmp->next; 1216 1220 ioc++; 1217 1221 } 1218 tmp=tmp->next;1222 peTmp=peTmp->next; 1219 1223 } 1220 1224 } … … 1223 1227 * Duplicate an elements 1224 1228 * 1225 * @param ethe elements to clone1229 * @param peElem the elements to clone 1226 1230 * @return the allocated elements containing a copy of the elements e 1227 1231 */ 1228 elements* dupElements(elements* e){1229 elements* cursor=e;1230 elements* tmp=NULL;1231 if( cursor!=NULL && cursor->name!=NULL){1232 elements* dupElements(elements* peElem){ 1233 elements* peCursor=peElem; 1234 elements* peTmp=NULL; 1235 if(peCursor!=NULL && peCursor->name!=NULL){ 1232 1236 #ifdef DEBUG 1233 1237 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); … … 1235 1239 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1236 1240 #endif 1237 tmp=(elements*)malloc(ELEMENTS_SIZE);1238 tmp->name=zStrdup(cursor->name);1239 tmp->content=NULL;1240 addMapToMap(& tmp->content,cursor->content);1241 tmp->metadata=NULL;1242 addMapToMap(& tmp->metadata,cursor->metadata);1243 tmp->additional_parameters=NULL;1244 addMapToMap(& tmp->additional_parameters,cursor->additional_parameters);1245 if( cursor->format!=NULL)1246 tmp->format=zStrdup(cursor->format);1241 peTmp=(elements*)malloc(ELEMENTS_SIZE); 1242 peTmp->name=zStrdup(peCursor->name); 1243 peTmp->content=NULL; 1244 addMapToMap(&peTmp->content,peCursor->content); 1245 peTmp->metadata=NULL; 1246 addMapToMap(&peTmp->metadata,peCursor->metadata); 1247 peTmp->additional_parameters=NULL; 1248 addMapToMap(&peTmp->additional_parameters,peCursor->additional_parameters); 1249 if(peCursor->format!=NULL) 1250 peTmp->format=zStrdup(peCursor->format); 1247 1251 else 1248 tmp->format=NULL;1249 if( cursor->defaults!=NULL){1250 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);1251 tmp->defaults->content=NULL;1252 addMapToMap(& tmp->defaults->content,cursor->defaults->content);1253 tmp->defaults->next=NULL;1252 peTmp->format=NULL; 1253 if(peCursor->defaults!=NULL){ 1254 peTmp->defaults=(iotype*)malloc(IOTYPE_SIZE); 1255 peTmp->defaults->content=NULL; 1256 addMapToMap(&peTmp->defaults->content,peCursor->defaults->content); 1257 peTmp->defaults->next=NULL; 1254 1258 #ifdef DEBUG 1255 1259 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1256 dumpMap( tmp->defaults->content);1260 dumpMap(peTmp->defaults->content); 1257 1261 #endif 1258 1262 }else 1259 tmp->defaults=NULL;1260 if( cursor->supported!=NULL && cursor->supported->content!=NULL){1261 iotype * tmp2=cursor->supported->next;1262 tmp->supported=(iotype*)malloc(IOTYPE_SIZE);1263 tmp->supported->content=NULL;1264 addMapToMap(& tmp->supported->content,cursor->supported->content);1265 tmp->supported->next=NULL;1266 while( tmp2!=NULL){1267 addMapToIoType(& tmp->supported,tmp2->content);1263 peTmp->defaults=NULL; 1264 if(peCursor->supported!=NULL && peCursor->supported->content!=NULL){ 1265 iotype *piotTmp=peCursor->supported->next; 1266 peTmp->supported=(iotype*)malloc(IOTYPE_SIZE); 1267 peTmp->supported->content=NULL; 1268 addMapToMap(&peTmp->supported->content,peCursor->supported->content); 1269 peTmp->supported->next=NULL; 1270 while(piotTmp!=NULL){ 1271 addMapToIoType(&peTmp->supported,piotTmp->content); 1268 1272 #ifdef DEBUG 1269 1273 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1270 dumpMap( tmp->defaults->content);1274 dumpMap(peTmp->defaults->content); 1271 1275 #endif 1272 tmp2=tmp2->next;1276 piotTmp=piotTmp->next; 1273 1277 } 1274 1278 } 1275 1279 else 1276 tmp->supported=NULL;1277 if( cursor->child!=NULL)1278 tmp->child=dupElements(cursor->child);1280 peTmp->supported=NULL; 1281 if(peCursor->child!=NULL) 1282 peTmp->child=dupElements(peCursor->child); 1279 1283 else 1280 tmp->child=NULL;1281 if( cursor->next!=NULL)1282 tmp->next=dupElements(cursor->next);1284 peTmp->child=NULL; 1285 if(peCursor->next!=NULL) 1286 peTmp->next=dupElements(peCursor->next); 1283 1287 else 1284 tmp->next=NULL;1285 } 1286 return tmp;1288 peTmp->next=NULL; 1289 } 1290 return peTmp; 1287 1291 } 1288 1292 … … 1291 1295 * 1292 1296 * @see dupElements 1293 * @param m the elements to add the e1294 * @param ethe elements to be added to m1295 */ 1296 void addToElements(elements** m,elements* e){1297 elements* tmp=e;1298 if(* m==NULL){1299 (* m)=dupElements(tmp);1297 * @param ppeElem the elements to add the e 1298 * @param peELem the elements to be added to m 1299 */ 1300 void addToElements(elements** ppeElem,elements* peELem){ 1301 elements* peTmp=peELem; 1302 if(*ppeElem==NULL){ 1303 (*ppeElem)=dupElements(peTmp); 1300 1304 }else{ 1301 addToElements(&(* m)->next,tmp);1305 addToElements(&(*ppeElem)->next,peTmp); 1302 1306 } 1303 1307 } … … 1306 1310 * Set the name of a service 1307 1311 * 1308 * @param name the service name 1309 */ 1310 void setServiceName(service** serv,char* name){ 1311 service* res=*serv; 1312 res->name=zStrdup(name); 1313 res->content=NULL; 1314 res->metadata=NULL; 1315 res->inputs=NULL; 1316 res->outputs=NULL; 1312 * @param ppsServ the service 1313 * @param pcName the service name 1314 */ 1315 void setServiceName(service** ppsServ,char* pcName){ 1316 service* psRes=*ppsServ; 1317 psRes->name=zStrdup(pcName); 1318 psRes->content=NULL; 1319 psRes->metadata=NULL; 1320 psRes->inputs=NULL; 1321 psRes->outputs=NULL; 1317 1322 } 1318 1323 … … 1320 1325 * Dump a service on stderr 1321 1326 * 1322 * @param sthe service to dump1323 */ 1324 void dumpService(service* s){1325 if( s==NULL)1327 * @param psServ the service to dump 1328 */ 1329 void dumpService(service* psServ){ 1330 if(psServ==NULL) 1326 1331 return; 1327 fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n", s->name);1328 if( s->content!=NULL){1332 fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",psServ->name); 1333 if(psServ->content!=NULL){ 1329 1334 fprintf(stderr,"CONTENT MAP\n"); 1330 dumpMap( s->content);1331 if( s->metadata!=NULL)1335 dumpMap(psServ->content); 1336 if(psServ->metadata!=NULL) 1332 1337 fprintf(stderr,"CONTENT METADATA\n"); 1333 dumpMap( s->metadata);1334 if( s->additional_parameters!=NULL)1338 dumpMap(psServ->metadata); 1339 if(psServ->additional_parameters!=NULL) 1335 1340 fprintf(stderr,"CONTENT AdditionalParameters\n"); 1336 dumpMap( s->additional_parameters);1337 } 1338 if( s->inputs!=NULL){1339 fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n", s->name);1340 dumpElements( s->inputs);1341 } 1342 if( s->outputs!=NULL){1343 fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n", s->name);1344 dumpElements( s->outputs);1341 dumpMap(psServ->additional_parameters); 1342 } 1343 if(psServ->inputs!=NULL){ 1344 fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",psServ->name); 1345 dumpElements(psServ->inputs); 1346 } 1347 if(psServ->outputs!=NULL){ 1348 fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",psServ->name); 1349 dumpElements(psServ->outputs); 1345 1350 } 1346 1351 fprintf(stderr,"++++++++++++++++++\n"); … … 1350 1355 * Dump a service on stderr using the YAML syntaxe 1351 1356 * 1352 * @param sthe service to dump1353 */ 1354 void dumpServiceAsYAML(service* s){1357 * @param psServ the service to dump 1358 */ 1359 void dumpServiceAsYAML(service* psServ){ 1355 1360 int i; 1356 fprintf(stderr,"# %s\n\n", s->name);1357 if( s->content!=NULL){1358 map* mcurs=s->content;1359 dumpMap( mcurs);1360 mcurs=s->metadata;1361 if( mcurs!=NULL){1361 fprintf(stderr,"# %s\n\n",psServ->name); 1362 if(psServ->content!=NULL){ 1363 map* pmCurs=psServ->content; 1364 dumpMap(pmCurs); 1365 pmCurs=psServ->metadata; 1366 if(pmCurs!=NULL){ 1362 1367 fprintf(stderr,"MetaData:\n"); 1363 while( mcurs!=NULL){1368 while(pmCurs!=NULL){ 1364 1369 for(i=0;i<2;i++) 1365 1370 fprintf(stderr," "); 1366 _dumpMap( mcurs);1367 mcurs=mcurs->next;1371 _dumpMap(pmCurs); 1372 pmCurs=pmCurs->next; 1368 1373 } 1369 1374 } 1370 1375 } 1371 if( s->inputs!=NULL){1376 if(psServ->inputs!=NULL){ 1372 1377 fprintf(stderr,"\ninputs:\n"); 1373 dumpElementsAsYAML( s->inputs,0);1374 } 1375 if( s->outputs!=NULL){1378 dumpElementsAsYAML(psServ->inputs,0); 1379 } 1380 if(psServ->outputs!=NULL){ 1376 1381 fprintf(stderr,"\noutputs:\n"); 1377 dumpElementsAsYAML( s->outputs,0);1382 dumpElementsAsYAML(psServ->outputs,0); 1378 1383 } 1379 1384 } … … 1382 1387 * Duplicate a service 1383 1388 * 1384 * @param sthe service to clone1389 * @param psServ the service to clone 1385 1390 * @return the allocated service containing a copy of the serfvice s 1386 1391 */ 1387 service* dupService(service* s){1388 service * res=(service*)malloc(SERVICE_SIZE);1389 res->name=zStrdup(s->name);1390 res->content=NULL;1391 addMapToMap(& res->content,s->content);1392 res->metadata=NULL;1393 addMapToMap(& res->metadata,s->metadata);1394 res->additional_parameters=NULL;1395 addMapToMap(& res->additional_parameters,s->additional_parameters);1396 res->inputs=dupElements(s->inputs);1397 res->outputs=dupElements(s->outputs);1398 return res;1392 service* dupService(service* psServ){ 1393 service *psRes=(service*)malloc(SERVICE_SIZE); 1394 psRes->name=zStrdup(psServ->name); 1395 psRes->content=NULL; 1396 addMapToMap(&psRes->content,psServ->content); 1397 psRes->metadata=NULL; 1398 addMapToMap(&psRes->metadata,psServ->metadata); 1399 psRes->additional_parameters=NULL; 1400 addMapToMap(&psRes->additional_parameters,psServ->additional_parameters); 1401 psRes->inputs=dupElements(psServ->inputs); 1402 psRes->outputs=dupElements(psServ->outputs); 1403 return psRes; 1399 1404 } 1400 1405 … … 1402 1407 * Print the registry on stderr. 1403 1408 * 1404 * @param rthe registry1405 */ 1406 void dumpRegistry(registry* r){1407 registry* p =r;1408 while(p !=NULL){1409 services* s=p->content;1410 fprintf(stderr,"%s \n",p ->name);1411 s=p->content;1412 while( s!=NULL){1413 dumpService( s->content);1414 s=s->next;1415 } 1416 p =p->next;1409 * @param prReg the registry 1410 */ 1411 void dumpRegistry(registry* prReg){ 1412 registry* prCurs=prReg; 1413 while(prCurs!=NULL){ 1414 services* psServ=prCurs->content; 1415 fprintf(stderr,"%s \n",prCurs->name); 1416 psServ=prCurs->content; 1417 while(psServ!=NULL){ 1418 dumpService(psServ->content); 1419 psServ=psServ->next; 1420 } 1421 prCurs=prCurs->next; 1417 1422 } 1418 1423 } … … 1421 1426 * Add a service to the registry 1422 1427 * 1423 * @param reg the resgitry to add the service1424 * @param name the registry name to update1425 * @param content the service to add1426 */ 1427 bool addServiceToRegistry(registry** reg,char* name,service* content){1428 registry *l=* reg;1428 * @param prReg the resgitry to add the service 1429 * @param pcName the registry name to update 1430 * @param psContent the service to add 1431 */ 1432 bool addServiceToRegistry(registry** prReg,char* pcName,service* psContent){ 1433 registry *l=*prReg; 1429 1434 int isInitial=-1; 1430 1435 if(l==NULL){ … … 1435 1440 int hasLevel=-1; 1436 1441 while(isInitial<0 && l!=NULL){ 1437 if(l->name!=NULL && strcasecmp( name,l->name)==0){1442 if(l->name!=NULL && strcasecmp(pcName,l->name)==0){ 1438 1443 hasLevel=1; 1439 1444 break; … … 1444 1449 if(isInitial<0) 1445 1450 l=(registry*)malloc(REGISTRY_SIZE); 1446 l->name=zStrdup( name);1451 l->name=zStrdup(pcName); 1447 1452 l->content=NULL; 1448 1453 l->next=NULL; … … 1450 1455 if(l->content==NULL){ 1451 1456 l->content=(services*)malloc(SERVICES_SIZE); 1452 l->content->content=dupService( content);1457 l->content->content=dupService(psContent); 1453 1458 l->content->next=NULL; 1454 1459 } 1455 1460 else{ 1456 services* s=l->content;1457 while( s->next!=NULL)1458 s=s->next;1459 s->next=(services*)malloc(SERVICES_SIZE);1460 s->next->content=dupService(content);1461 s->next->next=NULL;1461 services* psServ=l->content; 1462 while(psServ->next!=NULL) 1463 psServ=psServ->next; 1464 psServ->next=(services*)malloc(SERVICES_SIZE); 1465 psServ->next->content=dupService(psContent); 1466 psServ->next->next=NULL; 1462 1467 } 1463 1468 l->next=NULL; 1464 1469 if(isInitial>0) 1465 * reg=l;1470 *prReg=l; 1466 1471 else{ 1467 registry * r=*reg;1468 while( r->next!=NULL)1469 r=r->next;1470 r->next=l;1471 r->next->next=NULL;1472 registry *prCurs=*prReg; 1473 while(prCurs->next!=NULL) 1474 prCurs=prCurs->next; 1475 prCurs->next=l; 1476 prCurs->next->next=NULL; 1472 1477 } 1473 1478 return true; … … 1480 1485 * Free memory allocated for the registry 1481 1486 * 1482 * @param rthe registry1483 */ 1484 void freeRegistry(registry** r){1485 registry* lr=*r;1486 while( lr!=NULL){1487 services* s=lr->content;1488 free( lr->name);1489 while( s!=NULL){1490 service* s1=s->content;1491 s=s->next;1492 if( s1!=NULL){1493 freeService(& s1);1494 free( s1);1495 s1=NULL;1487 * @param prReg the registry 1488 */ 1489 void freeRegistry(registry** prReg){ 1490 registry* prLocalRef=*prReg; 1491 while(prLocalRef!=NULL){ 1492 services* psServ=prLocalRef->content; 1493 free(prLocalRef->name); 1494 while(psServ!=NULL){ 1495 service* psServ1=psServ->content; 1496 psServ=psServ->next; 1497 if(psServ1!=NULL){ 1498 freeService(&psServ1); 1499 free(psServ1); 1500 psServ1=NULL; 1496 1501 } 1497 1502 } 1498 lr=lr->next;1503 prLocalRef=prLocalRef->next; 1499 1504 } 1500 1505 } … … 1503 1508 * Access a service in the registry 1504 1509 * 1505 * @param rthe registry1506 * @param level the regitry to search ("concept", "generic" or "implementation")1507 * @param sname the service name1510 * @param prReg the registry 1511 * @param pcLevel the regitry to search ("concept", "generic" or "implementation") 1512 * @param pcName the service name 1508 1513 * @return the service pointer if a corresponding service was found or NULL 1509 1514 */ 1510 service* getServiceFromRegistry(registry* r,char *level,char* sname){1511 registry * lr=r;1512 while( lr!=NULL){1513 if(strcasecmp( lr->name,level)==0){1514 services* s=lr->content;1515 while( s!=NULL){1516 if( s->content!=NULL && strcasecmp(s->content->name,sname)==0)1517 return s->content;1518 s=s->next;1515 service* getServiceFromRegistry(registry* prReg,char *pcLevel,char* pcName){ 1516 registry *prLocalRef=prReg; 1517 while(prLocalRef!=NULL){ 1518 if(strcasecmp(prLocalRef->name,pcLevel)==0){ 1519 services* psServ=prLocalRef->content; 1520 while(psServ!=NULL){ 1521 if(psServ->content!=NULL && strcasecmp(psServ->content->name,pcName)==0) 1522 return psServ->content; 1523 psServ=psServ->next; 1519 1524 } 1520 1525 break; 1521 1526 } 1522 lr=lr->next;1527 prLocalRef=prLocalRef->next; 1523 1528 } 1524 1529 return NULL; … … 1528 1533 * Apply inheritance to an out map from a reference in map 1529 1534 * 1530 * @param out the map to update1531 * @param in the reference map (containing inherited properties)1532 */ 1533 void inheritMap(map** out,map* in){1534 map* content=in;1535 if((* out)==NULL){1536 addMapToMap( out,in);1535 * @param ppmOut the map to update 1536 * @param pmIn the reference map (containing inherited properties) 1537 */ 1538 void inheritMap(map** ppmOut,map* pmIn){ 1539 map* pmContent=pmIn; 1540 if((*ppmOut)==NULL){ 1541 addMapToMap(ppmOut,pmIn); 1537 1542 return; 1538 1543 } 1539 while( content!=NULL){1540 map* cmap=getMap(*out,content->name);1541 if( cmap==NULL)1542 addToMap(* out,content->name,content->value);1543 content=content->next;1544 while(pmContent!=NULL){ 1545 map* pmCurrent=getMap(*ppmOut,pmContent->name); 1546 if(pmCurrent==NULL) 1547 addToMap(*ppmOut,pmCurrent->name,pmCurrent->value); 1548 pmCurrent=pmCurrent->next; 1544 1549 } 1545 1550 } … … 1548 1553 * Apply inheritance to an out iotype from a reference in iotype 1549 1554 * 1550 * @param out the iotype to update1551 * @param in the reference iotype (containing inherited properties)1552 */ 1553 void inheritIOType(iotype** out,iotype* in){1554 iotype* io=in;1555 iotype* oio=*out;1556 if( io!=NULL){1557 if(* out==NULL){1558 * out=(iotype*)malloc(IOTYPE_SIZE);1559 (* out)->content=NULL;1560 addMapToMap(&(* out)->content,io->content);1561 (* out)->next=NULL;1562 oio=*out;1563 inheritIOType(& oio->next,io->next);1555 * @param ppiotOut the iotype to update 1556 * @param piotIn the reference iotype (containing inherited properties) 1557 */ 1558 void inheritIOType(iotype** ppiotOut,iotype* piotIn){ 1559 iotype* piotInCurosor=piotIn; 1560 iotype* ppiotOutCursor=*ppiotOut; 1561 if(piotInCurosor!=NULL){ 1562 if(*ppiotOut==NULL){ 1563 *ppiotOut=(iotype*)malloc(IOTYPE_SIZE); 1564 (*ppiotOut)->content=NULL; 1565 addMapToMap(&(*ppiotOut)->content,piotInCurosor->content); 1566 (*ppiotOut)->next=NULL; 1567 ppiotOutCursor=*ppiotOut; 1568 inheritIOType(&ppiotOutCursor->next,piotInCurosor->next); 1564 1569 }else{ 1565 inheritIOType(& oio->next,io->next);1570 inheritIOType(&ppiotOutCursor->next,piotInCurosor->next); 1566 1571 } 1567 1572 } … … 1571 1576 * Apply inheritance to an out elements from a reference in elements 1572 1577 * 1573 * @param out the elements to update1574 * @param in the reference elements (containing inherited properties)1575 */ 1576 void inheritElements(elements** out,elements* in){1577 elements* content=in;1578 while( content!=NULL && *out!=NULL){1579 elements* cmap=getElements(*out,content->name);1580 if( cmap==NULL)1581 addToElements( out,content);1578 * @param ppeOut the elements to update 1579 * @param peIn the reference elements (containing inherited properties) 1580 */ 1581 void inheritElements(elements** ppeOut,elements* peIn){ 1582 elements* peContent=peIn; 1583 while(peContent!=NULL && *ppeOut!=NULL){ 1584 elements* peCurrent=getElements(*ppeOut,peContent->name); 1585 if(peCurrent==NULL) 1586 addToElements(ppeOut,peContent); 1582 1587 else{ 1583 inheritMap(& cmap->content,content->content);1584 inheritMap(& cmap->metadata,content->metadata);1585 if( cmap->format==NULL && content->format!=NULL)1586 cmap->format=zStrdup(content->format);1587 inheritIOType(& cmap->defaults,content->defaults);1588 if( cmap->supported==NULL)1589 inheritIOType(& cmap->supported,content->supported);1588 inheritMap(&peCurrent->content,peContent->content); 1589 inheritMap(&peCurrent->metadata,peContent->metadata); 1590 if(peCurrent->format==NULL && peContent->format!=NULL) 1591 peCurrent->format=zStrdup(peContent->format); 1592 inheritIOType(&peCurrent->defaults,peContent->defaults); 1593 if(peCurrent->supported==NULL) 1594 inheritIOType(&peCurrent->supported,peContent->supported); 1590 1595 else{ 1591 iotype* p =content->supported;1592 while(p !=NULL){1593 addMapToIoType(& cmap->supported,p->content);1594 p =p->next;1596 iotype* piotTmp=peContent->supported; 1597 while(piotTmp!=NULL){ 1598 addMapToIoType(&peCurrent->supported,piotTmp->content); 1599 piotTmp=piotTmp->next; 1595 1600 } 1596 1601 } 1597 1602 } 1598 content=content->next;1603 peContent=peContent->next; 1599 1604 } 1600 1605 } … … 1603 1608 * Apply inheritance to a service based on a registry 1604 1609 * 1605 * @param rthe registry storing profiles hierarchy1606 * @param sthe service to update depending on its inheritance1607 */ 1608 void inheritance(registry * r,service** s){1609 service* ls=*s;1610 * @param prReg the registry storing profiles hierarchy 1611 * @param psServ the service to update depending on its inheritance 1612 */ 1613 void inheritance(registry *prReg,service** psServ){ 1614 service* psCursor=*psServ; 1610 1615 map *profile,*level; 1611 if( r==NULL)1616 if(prReg==NULL) 1612 1617 return; 1613 if( ls==NULL || ls->content==NULL)1618 if(psCursor==NULL || psCursor->content==NULL) 1614 1619 return; 1615 profile=getMap( ls->content,"extend");1616 level=getMap( ls->content,"level");1620 profile=getMap(psCursor->content,"extend"); 1621 level=getMap(psCursor->content,"level"); 1617 1622 if(profile!=NULL&&level!=NULL){ 1618 1623 service* s1; 1619 1624 if(strncasecmp(level->value,"profile",7)==0) 1620 s1=getServiceFromRegistry( r,(char*)"generic",profile->value);1625 s1=getServiceFromRegistry(prReg,(char*)"generic",profile->value); 1621 1626 else 1622 s1=getServiceFromRegistry( r,level->value,profile->value);1627 s1=getServiceFromRegistry(prReg,level->value,profile->value); 1623 1628 1624 inheritMap(& ls->content,s1->content);1625 inheritMap(& ls->metadata,s1->metadata);1626 if( ls->inputs==NULL && s1->inputs!=NULL){1627 ls->inputs=dupElements(s1->inputs);1629 inheritMap(&psCursor->content,s1->content); 1630 inheritMap(&psCursor->metadata,s1->metadata); 1631 if(psCursor->inputs==NULL && s1->inputs!=NULL){ 1632 psCursor->inputs=dupElements(s1->inputs); 1628 1633 }else{ 1629 inheritElements(& ls->inputs,s1->inputs);1630 } 1631 if( ls->outputs==NULL && s1->outputs!=NULL){1632 ls->outputs=dupElements(s1->outputs);1634 inheritElements(&psCursor->inputs,s1->inputs); 1635 } 1636 if(psCursor->outputs==NULL && s1->outputs!=NULL){ 1637 psCursor->outputs=dupElements(s1->outputs); 1633 1638 }else 1634 inheritElements(& ls->outputs,s1->outputs);1639 inheritElements(&psCursor->outputs,s1->outputs); 1635 1640 } 1636 1641 } … … 1639 1644 * Convert a maps to a char*** (only used for Fortran support) 1640 1645 * 1641 * @param mthe maps to convert1642 * @param cthe resulting array1643 */ 1644 void mapsToCharXXX(maps* m,char*** c){1645 maps* tm=m;1646 * @param pmsMap the maps to convert 1647 * @param pppcValues the resulting array 1648 */ 1649 void mapsToCharXXX(maps* pmsMap,char*** pppcValues){ 1650 maps* pmsCursor=pmsMap; 1646 1651 int i=0; 1647 1652 int j=0; 1648 char tmp[10][30][1024];1649 memset( tmp,0,1024*10*10);1650 while( tm!=NULL){1651 map* tc=tm->content;1653 char aaacTmp[10][30][1024]; 1654 memset(aaacTmp,0,1024*10*10); 1655 while(pmsCursor!=NULL){ 1656 map* pmContent=pmsCursor->content; 1652 1657 if(i>=10) 1653 1658 break; 1654 strcpy( tmp[i][j],"name");1659 strcpy(aaacTmp[i][j],"name"); 1655 1660 j++; 1656 strcpy( tmp[i][j],tm->name);1661 strcpy(aaacTmp[i][j],pmsCursor->name); 1657 1662 j++; 1658 while( tc!=NULL){1663 while(pmContent!=NULL){ 1659 1664 if(j>=30) 1660 1665 break; 1661 strcpy( tmp[i][j],tc->name);1666 strcpy(aaacTmp[i][j],pmContent->name); 1662 1667 j++; 1663 strcpy( tmp[i][j],tc->value);1668 strcpy(aaacTmp[i][j],pmContent->value); 1664 1669 j++; 1665 tc=tc->next;1666 } 1667 tm=tm->next;1670 pmContent=pmContent->next; 1671 } 1672 pmsCursor=pmsCursor->next; 1668 1673 j=0; 1669 1674 i++; 1670 1675 } 1671 memcpy( c,tmp,10*10*1024);1676 memcpy(pppcValues,aaacTmp,10*10*1024); 1672 1677 } 1673 1678 … … 1675 1680 * Convert a char*** to a maps (only used for Fortran support) 1676 1681 * 1677 * @param cthe array to convert1678 * @param mthe resulting maps1679 */ 1680 void charxxxToMaps(char*** c,maps**m){1681 maps* trorf=*m;1682 * @param pppcValues the array to convert 1683 * @param ppmsMaps the resulting maps 1684 */ 1685 void charxxxToMaps(char*** pppcValues,maps** ppmsMaps){ 1686 maps* pmsCursor=*ppmsMaps; 1682 1687 int i,j; 1683 char tmp[10][30][1024];1684 memcpy( tmp,c,10*30*1024);1688 char aaaTmp[10][30][1024]; 1689 memcpy(aaaTmp,pppcValues,10*30*1024); 1685 1690 for(i=0;i<10;i++){ 1686 if(strlen( tmp[i][1])==0)1691 if(strlen(aaaTmp[i][1])==0) 1687 1692 break; 1688 trorf->name=tmp[i][1];1689 trorf->content=NULL;1690 trorf->next=NULL;1693 pmsCursor->name=aaaTmp[i][1]; 1694 pmsCursor->content=NULL; 1695 pmsCursor->next=NULL; 1691 1696 for(j=2;j<29;j+=2){ 1692 if(strlen( tmp[i][j+1])==0)1697 if(strlen(aaaTmp[i][j+1])==0) 1693 1698 break; 1694 if( trorf->content==NULL)1695 trorf->content=createMap(tmp[i][j],tmp[i][j+1]);1699 if(pmsCursor->content==NULL) 1700 pmsCursor->content=createMap(aaaTmp[i][j],aaaTmp[i][j+1]); 1696 1701 else 1697 addToMap( trorf->content,tmp[i][j],tmp[i][j+1]);1698 } 1699 trorf=trorf->next;1700 } 1701 m=&trorf;1702 addToMap(pmsCursor->content,aaaTmp[i][j],aaaTmp[i][j+1]); 1703 } 1704 pmsCursor=pmsCursor->next; 1705 } 1706 ppmsMaps=&pmsCursor; 1702 1707 } 1703 1708 … … 1705 1710 * Verify that a map has a value 1706 1711 * 1707 * @param map pointer to map that should be checked1712 * @param pmMap pointer to map that should be checked 1708 1713 * @return true if map has a value or false if value is missing/empty/NULL 1709 1714 */ 1710 bool nonempty(map* map) {1711 return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);1715 bool nonempty(map* pmMap) { 1716 return (pmMap != NULL && pmMap->value != NULL && strlen(pmMap->value) > 0 && strcmp(pmMap->value, "NULL") != 0); 1712 1717 } 1713 1718 … … 1716 1721 * data structure, and obtain that value 1717 1722 * 1718 * @param source pointer to maps structure1719 * @param node name of maps node to search1720 * @param key name of map node to find1721 * @param kvp address to the map* if it exists, otherwise NULL1723 * @param pmsSource pointer to maps structure 1724 * @param pccNode name of maps node to search 1725 * @param pccKey name of map node to find 1726 * @param ppmKvp address to the map* if it exists, otherwise NULL 1722 1727 * @return true if map has a value or false if value is missing/NULL 1723 1728 * 1724 1729 * @note The map assigned to kvp is owned by the source maps 1725 1730 */ 1726 bool hasvalue(maps* source, const char* node, const char* key, map** kvp) {1727 *kvp = getMapFromMaps(source, node, key);1728 return (*kvp != NULL && (*kvp)->value != NULL &&1729 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0);1731 bool hasvalue(maps* pmsSource, const char* pccNode, const char* pccKey, map** ppmKvp) { 1732 *ppmKvp = getMapFromMaps(pmsSource, pccNode, pccKey); 1733 return (*ppmKvp != NULL && (*ppmKvp)->value != NULL && 1734 strlen((*ppmKvp)->value) > 0 && strcmp((*ppmKvp)->value, "NULL") != 0); 1730 1735 } 1731 1736 … … 1733 1738 * Set error message in configuration maps 1734 1739 * 1735 * @param conf reference to configuration maps 1736 * @param service name of service 1737 * @param exc WPSException code 1738 * @param message exception text (default: exception text in WPS specification) 1739 */ 1740 void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) { 1741 1742 if (message == NULL) { 1743 message = WPSExceptionText[exc]; 1744 } 1745 1746 size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16; 1747 char* msg = (char*)malloc(len * sizeof(char)); 1748 1749 if (msg != NULL) { 1750 snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]); 1751 setMapInMaps(conf, "lenv", "message", msg); 1752 free(msg); 1753 } 1754 } 1755 1756 void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) { 1757 1758 size_t msglen = 512; 1759 const char empty[] = ""; 1760 1761 FILE* log; 1762 1763 // system time, process time [nanoseconds] 1764 unsigned long long sys_t, proc_t; 1765 1766 // processor time consumed by the program: 1767 clock_t t = clock(); 1768 1769 // system time: 1770 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 1771 1772 std::time_t now_t = std::chrono::system_clock::to_time_t(now); 1773 std::tm* tm = localtime(&now_t); 1774 char* str = asctime(tm); 1775 str[strlen(str) - 1] = '\0'; // remove newline 1776 1777 sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); 1778 //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC); 1779 proc_t = t; 1780 1781 if (message != NULL) { 1782 msglen += strlen(message); 1783 } 1784 else { 1785 message = empty; 1786 } 1787 //getLastErrorMessage(); // cgiScriptName 1788 char* text = (char*)malloc(sizeof(char)*msglen); 1789 1790 snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1791 zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ // 1792 1793 if (file != NULL && (log = fopen(file, "a+")) != NULL) { 1794 fputs(text, log); 1795 fclose(log); 1796 } 1797 else { 1740 * @param pmsaConf reference to configuration maps 1741 * @param pccService name of service 1742 * @param weExc WPSException code 1743 * @param pccMessage exception text (default: exception text in WPS specification) 1744 */ 1745 void setErrorMessage(maps*& pmsaConf, const char* pccService, WPSException weExc, const char* pccMessage) { 1746 if (pccMessage == NULL) { 1747 pccMessage = WPSExceptionText[weExc]; 1748 } 1749 size_t len = strlen(pccService) + strlen(": ") + strlen(pccMessage) + strlen(": ") + strlen(WPSExceptionCode[weExc]) + 16; 1750 char* pcMsg = (char*)malloc(len * sizeof(char)); 1751 if (pcMsg != NULL) { 1752 snprintf(pcMsg, len * sizeof(char), "\n%s: %s: %s\n", pccService, pccMessage, WPSExceptionCode[weExc]); 1753 setMapInMaps(pmsaConf, "lenv", "message", pcMsg); 1754 free(pcMsg); 1755 } 1756 } 1757 1758 /** 1759 * Print debug message 1760 * 1761 * @param pccSource the file invoking the function 1762 * @param pccFunction the function calling for logMessage 1763 * @param iLine the line number 1764 * @param pccFile the file to log informations 1765 * @param pccMessage the message to be print 1766 */ 1767 void logMessage(const char* pccSource, const char* pccFunction, int iLne, const char* pccFile, const char* pccMessage) { //, const char* source, const char* function, int line) { 1768 1769 size_t msglen = 512; 1770 const char empty[] = ""; 1771 1772 FILE* pfLog; 1773 1774 // system time, process time [nanoseconds] 1775 unsigned long long sys_t, proc_t; 1776 1777 // processor time consumed by the program: 1778 clock_t t = clock(); 1779 1780 // system time: 1781 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 1782 1783 std::time_t now_t = std::chrono::system_clock::to_time_t(now); 1784 std::tm* tm = localtime(&now_t); 1785 char* pcStr = asctime(tm); 1786 pcStr[strlen(pcStr) - 1] = '\0'; // remove newline 1787 1788 sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); 1789 //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC); 1790 proc_t = t; 1791 1792 if (pccMessage != NULL) { 1793 msglen += strlen(pccMessage); 1794 } 1795 else { 1796 pccMessage = empty; 1797 } 1798 //getLastErrorMessage(); // cgiScriptName 1799 char* pcText = (char*)malloc(sizeof(char)*msglen); 1800 1801 snprintf(pcText, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1802 zGetpid(), pccSource, iLne, pccFunction, pcStr, sys_t, proc_t, pccMessage); // __FILE__ __LINE__ __func__ // 1803 1804 if (pccFile != NULL && (pfLog = fopen(pccFile, "a+")) != NULL) { 1805 fputs(pcText, pfLog); 1806 fclose(pfLog); 1807 } 1808 else { 1798 1809 #ifdef MSG_LOG_FILE 1799 if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) {1800 fputs(text, log);1801 fclose(log);1802 1810 if ((pfLog = fopen(MSG_LOG_FILE, "a+")) != NULL) { 1811 fputs(pcText, pfLog); 1812 fclose(pfLog); 1813 } 1803 1814 #endif 1804 1805 1806 if (text != NULL) free(text);1815 } 1816 1817 if (pcText != NULL) free(pcText); 1807 1818 } 1808 1819 … … 1815 1826 #ifdef WIN32 1816 1827 #ifndef USE_MS 1817 char *strcasestr (char const * a, char const *b)1828 char *strcasestr (char const *pccA, char const *pccB) 1818 1829 { 1819 char * x = zStrdup (a);1820 char * y = zStrdup (b);1830 char *pcX = zStrdup (pccA); 1831 char *pcY = zStrdup (pccB); 1821 1832 1822 x = _strlwr (x);1823 y = _strlwr (y);1824 char *pos = strstr ( x, y);1825 char *ret = pos == NULL ? NULL : (char *) ( a + (pos - x));1826 free ( x);1827 free ( y);1833 pcX = _strlwr (pcX); 1834 pcY = _strlwr (pcY); 1835 char *pos = strstr (pcX, pcY); 1836 char *ret = pos == NULL ? NULL : (char *) (pccA + (pos - pcX)); 1837 free (pcX); 1838 free (pcY); 1828 1839 return ret; 1829 1840 }; … … 1843 1854 * The memory should be deallocated by calling freeMap. 1844 1855 */ 1845 char* allocateMapValue(map* node, size_t num_bytes)1856 char* allocateMapValue(map* pmNode, size_t sNumBytes) 1846 1857 { 1847 if (node == NULL) {1848 1849 1850 1851 if (node->value != NULL) {1852 free(node->value);1853 1854 node->value = (char*) malloc(num_bytes);1858 if (pmNode == NULL) { 1859 return NULL; 1860 } 1861 1862 if (pmNode->value != NULL) { 1863 free(pmNode->value); 1864 } 1865 pmNode->value = (char*) malloc(sNumBytes); 1855 1866 1856 return node->value;1857 } 1867 return pmNode->value; 1868 } -
trunk/zoo-project/zoo-kernel/service_internal_python.c
r962 r967 468 468 while(tmp!=NULL){ 469 469 PyObject* name=PyString_FromString(tmp->name); 470 if(strcasecmp(tmp->name,"value")==0 && strlen(tmp->value)>0) {470 if(strcasecmp(tmp->name,"value")==0) { 471 471 if(isArray!=NULL){ 472 472 map* len=getMap(tmp,"length"); … … 492 492 lvalue=PyString_FromString(vMap->value); 493 493 } 494 else{ 495 lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value)); 494 else{ 495 if(strlen(vMap->value)>0) 496 lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value)); 497 else 498 lvalue=Py_None; 496 499 } 497 500 if(sMap!=NULL){ … … 553 556 } 554 557 else if(size!=NULL && useFile==NULL){ 555 PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value)); 558 PyObject* value; 559 if(strlen(tmp->value)>0) 560 value=PyString_FromStringAndSize(tmp->value,atoi(size->value)); 561 else 562 value=Py_None; 556 563 if(PyDict_SetItem(res,name,value)<0){ 557 564 Py_DECREF(value); … … 572 579 } 573 580 else{ 574 if(PyDict_GetItem(res,name)==NULL && strlen(tmp->value)>0){581 if(PyDict_GetItem(res,name)==NULL){ 575 582 PyObject* value=PyString_FromString(tmp->value); 576 583 if(PyDict_SetItem(res,name,value)<0){ -
trunk/zoo-project/zoo-kernel/service_json.c
r965 r967 603 603 604 604 map* tmp=getMap(s,"code"); 605 exceptionCode=produceStatusString(m,tmp); 605 606 if(tmp!=NULL){ 606 if(strcmp(tmp->value,"OperationNotSupported")==0 ||607 strcmp(tmp->value,"NoApplicableCode")==0)608 exceptionCode="500 Not Implemented";609 else610 if(strcmp(tmp->value,"MissingParameterValue")==0 ||611 strcmp(tmp->value,"InvalidUpdateSequence")==0 ||612 strcmp(tmp->value,"OptionNotSupported")==0 ||613 strcmp(tmp->value,"VersionNegotiationFailed")==0 ||614 strcmp(tmp->value,"InvalidParameterValue")==0)615 exceptionCode="400 Bad request";616 else617 if(strcmp(tmp->value,"NotFound")==0 ||618 strcmp(tmp->value,"NoSuchProcess")==0 ||619 strcmp(tmp->value,"NoSuchJob")==0 ||620 strcmp(tmp->value,"ResultNotReady")==0)621 exceptionCode="404 Not Found";622 else623 exceptionCode="500 Internal Server Error";624 607 json_object_object_add(res,"code",json_object_new_string(tmp->value)); 625 608 } 626 609 else{ 627 exceptionCode="500 Internal Server Error";628 610 json_object_object_add(res,"code",json_object_new_string("NoApplicableCode")); 629 611 } … … 716 698 json_object* json_cinput=NULL; 717 699 if(json_object_object_get_ex(req,"value",&json_cinput)!=FALSE){ 700 output->content=createMap("value",json_object_get_string(json_cinput)); 701 } 702 else{ 718 703 json_object* json_value=NULL; 719 if(json_object_object_get_ex(json_cinput,"inlineValue",&json_value)!=FALSE) 720 output->content=createMap("value",json_object_get_string(json_value)); 721 else{ 722 if(json_object_object_get_ex(json_cinput,"href",&json_value)!=FALSE){ 723 output->content=createMap("xlink:href",json_object_get_string(json_value)); 724 int len=0; 725 int createdStr=0; 726 char *tmpStr="url"; 727 char *tmpStr1="input"; 728 if(getMaps(conf,"http_requests")==NULL){ 729 maps* tmpMaps=createMaps("http_requests"); 730 tmpMaps->content=createMap("length","1"); 731 addMapsToMaps(&conf,tmpMaps); 732 freeMaps(&tmpMaps); 733 free(tmpMaps); 734 }else{ 735 map* tmpMap=getMapFromMaps(conf,"http_requests","length"); 736 int len=atoi(tmpMap->value); 737 createdStr=1; 738 tmpStr=(char*) malloc((12)*sizeof(char)); 739 sprintf(tmpStr,"%d",len+1); 740 setMapInMaps(conf,"http_requests","length",tmpStr); 741 sprintf(tmpStr,"url_%d",len); 742 tmpStr1=(char*) malloc((14)*sizeof(char)); 743 sprintf(tmpStr1,"input_%d",len); 744 } 745 setMapInMaps(conf,"http_requests",tmpStr,json_object_get_string(json_value)); 746 setMapInMaps(conf,"http_requests",tmpStr1,name); 747 if(createdStr>0){ 748 free(tmpStr); 749 free(tmpStr1); 750 } 704 if(json_object_object_get_ex(req,"href",&json_value)!=FALSE){ 705 output->content=createMap("xlink:href",json_object_get_string(json_value)); 706 int len=0; 707 int createdStr=0; 708 char *tmpStr="url"; 709 char *tmpStr1="input"; 710 if(getMaps(conf,"http_requests")==NULL){ 711 maps* tmpMaps=createMaps("http_requests"); 712 tmpMaps->content=createMap("length","1"); 713 addMapsToMaps(&conf,tmpMaps); 714 freeMaps(&tmpMaps); 715 free(tmpMaps); 716 }else{ 717 map* tmpMap=getMapFromMaps(conf,"http_requests","length"); 718 int len=atoi(tmpMap->value); 719 createdStr=1; 720 tmpStr=(char*) malloc((12)*sizeof(char)); 721 sprintf(tmpStr,"%d",len+1); 722 setMapInMaps(conf,"http_requests","length",tmpStr); 723 sprintf(tmpStr,"url_%d",len); 724 tmpStr1=(char*) malloc((14)*sizeof(char)); 725 sprintf(tmpStr1,"input_%d",len); 726 } 727 setMapInMaps(conf,"http_requests",tmpStr,json_object_get_string(json_value)); 728 setMapInMaps(conf,"http_requests",tmpStr1,name); 729 if(createdStr>0){ 730 free(tmpStr); 731 free(tmpStr1); 751 732 } 752 733 } … … 807 788 808 789 /** 809 * Parse inputs / outputs 790 * Parse a single input / output entity 791 * 792 * @param conf the maps containing the settings of the main.cfg file 793 * @param ioElements the elements extracted from the zcfg 794 * @param ioMaps the produced maps containing inputs (or outputs) 795 * @param ioType the char* set to inputs or outputs 796 * @param key char* the input/output name 797 * @param val json_object pointing to the input/output 798 * @param cMaps the outputed maps containing input (or output) metedata 799 */ 800 void _parseJIOSingle(maps* conf,elements* cio, maps** ioMaps,const char* ioType,const char* key,json_object* val,maps* cMaps){ 801 json_object* json_cinput; 802 if(json_object_object_get_ex(val,"dataType",&json_cinput)!=FALSE){ 803 parseJLiteral(conf,val,cio,cMaps); 804 } else if(json_object_object_get_ex(val,"format",&json_cinput)!=FALSE){ 805 parseJComplex(conf,val,cio,cMaps,key); 806 } else if(json_object_object_get_ex(val,"bbox",&json_cinput)!=FALSE){ 807 parseJBoundingBox(conf,val,cio,cMaps); 808 }// else error! 809 else{ 810 if(json_object_object_get_ex(val,"value",&json_cinput)!=FALSE){ 811 map* error=createMap("code","BadRequest"); 812 char tmpS[1024]; 813 sprintf(tmpS,_("Missing input for %s"),cio->name); 814 addToMap(error,"message",tmpS); 815 setMapInMaps(conf,"lenv","status_code","400 Bad Request"); 816 printExceptionReportResponseJ(conf,error); 817 return; 818 }else{ 819 if(json_object_get_type(json_cinput)==json_type_string){ 820 parseJLiteral(conf,val,cio,cMaps); 821 }else if(json_object_get_type(json_cinput)==json_type_object){ 822 json_object* json_ccinput=NULL; 823 if(json_object_object_get_ex(json_cinput,"bbox",&json_ccinput)!=FALSE){ 824 parseJComplex(conf,val,cio,cMaps,key); 825 } 826 else{ 827 parseJBoundingBox(conf,val,cio,cMaps); 828 } 829 }else{ 830 if(strcmp(ioType,"input")==0){ 831 map* error=createMap("code","BadRequest"); 832 char tmpS1[1024]; 833 sprintf(tmpS1,_("Issue with input %s"),cio->name); 834 addToMap(error,"message",tmpS1); 835 setMapInMaps(conf,"lenv","status_code","400 Bad Request"); 836 printExceptionReportResponseJ(conf,error); 837 return; 838 } 839 } 840 } 841 } 842 } 843 844 /** 845 * Parse a single input / output entity that can be an array 846 * 847 * @param conf the maps containing the settings of the main.cfg file 848 * @param ioElements the elements extracted from the zcfg 849 * @param ioMaps the produced maps containing inputs (or outputs) 850 * @param ioType the char* set to inputs or outputs 851 * @param key char* the input/output name 852 * @param val json_object pointing to the input/output 853 */ 854 void parseJIOSingle(maps* conf,elements* ioElements, maps** ioMaps,const char* ioType,const char* key,json_object* val){ 855 maps *cMaps=NULL; 856 cMaps=createMaps(key); 857 elements* cio=getElements(ioElements,key); 858 if(json_object_is_type(val,json_type_array)){ 859 int i=0; 860 size_t len=json_object_array_length(val); 861 for(i=0;i<len;i++){ 862 json_object* json_current_io=json_object_array_get_idx(val,i); 863 maps* pmsExtra=createMaps(key); 864 _parseJIOSingle(conf,cio,ioMaps,ioType,key,json_current_io,pmsExtra); 865 map* pmCtx=pmsExtra->content; 866 while(pmCtx!=NULL){ 867 if(cMaps->content==NULL) 868 cMaps->content=createMap(pmCtx->name,pmCtx->value); 869 else 870 setMapArray(cMaps->content,pmCtx->name,i,pmCtx->value); 871 pmCtx=pmCtx->next; 872 } 873 freeMaps(&pmsExtra); 874 free(pmsExtra); 875 } 876 }else{ 877 _parseJIOSingle(conf,cio,ioMaps,ioType,key,val,cMaps); 878 } 879 880 881 if(strcmp(ioType,"outputs")==0){ 882 // Outputs 883 json_object* json_cinput; 884 if(json_object_object_get_ex(val,"transmissionMode",&json_cinput)!=FALSE){ 885 if(cMaps->content==NULL) 886 cMaps->content=createMap("transmissionMode",json_object_get_string(json_cinput)); 887 else 888 addToMap(cMaps->content,"transmissionMode",json_object_get_string(json_cinput)); 889 } 890 if(json_object_object_get_ex(val,"format",&json_cinput)!=FALSE){ 891 json_object_object_foreach(json_cinput, key1, val1) { 892 if(cMaps->content==NULL) 893 cMaps->content=createMap(key1,json_object_get_string(val1)); 894 else 895 addToMap(cMaps->content,key1,json_object_get_string(val1)); 896 } 897 } 898 } 899 900 addToMap(cMaps->content,"inRequest","true"); 901 if (ioMaps == NULL) 902 *ioMaps = dupMaps(&cMaps); 903 else 904 addMapsToMaps (ioMaps, cMaps); 905 906 freeMaps(&cMaps); 907 free(cMaps); 908 } 909 910 /** 911 * Parse all the inputs / outputs entities 912 * 810 913 * @param conf the maps containing the settings of the main.cfg file 811 914 * @param req json_object pointing to the input/output … … 816 919 void parseJIO(maps* conf, json_object* req, elements* ioElements, maps** ioMaps,const char* ioType){ 817 920 json_object* json_io=NULL; 818 if(json_object_object_get_ex(req,ioType,&json_io)!=FALSE){ 921 if(json_object_object_get_ex(req,ioType,&json_io)!=FALSE){ 819 922 json_object* json_current_io=NULL; 820 size_t len=json_object_array_length(json_io); 821 for(int i=0;i<len;i++){ 822 maps *cMaps=NULL; 823 json_current_io=json_object_array_get_idx(json_io,i); 824 json_object* cname=NULL; 825 if(json_object_object_get_ex(json_current_io,"id",&cname)!=FALSE){ 826 cMaps=createMaps(json_object_get_string(cname)); 827 elements* cio=getElements(ioElements,json_object_get_string(cname)); 828 json_object* json_input; 829 json_object* json_cinput; 830 if(json_object_object_get_ex(json_current_io,"input",&json_input)!=FALSE){ 831 if(json_object_object_get_ex(json_input,"dataType",&json_cinput)!=FALSE){ 832 parseJLiteral(conf,json_input,cio,cMaps); 833 } else if(json_object_object_get_ex(json_input,"format",&json_cinput)!=FALSE){ 834 parseJComplex(conf,json_input,cio,cMaps,json_object_get_string(cname)); 835 } else if(json_object_object_get_ex(json_input,"bbox",&json_cinput)!=FALSE){ 836 parseJBoundingBox(conf,json_input,cio,cMaps); 837 }// else error! 838 else{ 839 if(json_object_object_get_ex(json_input,"value",&json_cinput)!=FALSE){ 840 map* error=createMap("code","BadRequest"); 841 char tmpS[1024]; 842 sprintf(tmpS,_("Missing input for %s"),ioElements->name); 843 addToMap(error,"message",tmpS); 844 setMapInMaps(conf,"lenv","status_code","400 Bad Request"); 845 printExceptionReportResponseJ(conf,error); 846 return; 847 }else{ 848 if(json_object_get_type(json_cinput)==json_type_string){ 849 parseJLiteral(conf,json_input,cio,cMaps); 850 }else if(json_object_get_type(json_cinput)==json_type_object){ 851 json_object* json_ccinput=NULL; 852 if(json_object_object_get_ex(json_cinput,"bbox",&json_ccinput)!=FALSE){ 853 parseJComplex(conf,json_input,cio,cMaps,json_object_get_string(cname)); 854 } 855 else{ 856 parseJBoundingBox(conf,json_input,cio,cMaps); 857 } 858 }else{ 859 if(strcmp(ioType,"input")==0){ 860 map* error=createMap("code","BadRequest"); 861 char tmpS1[1024]; 862 sprintf(tmpS1,_("Issue with input %s"),ioElements->name); 863 addToMap(error,"message",tmpS1); 864 setMapInMaps(conf,"lenv","status_code","400 Bad Request"); 865 printExceptionReportResponseJ(conf,error); 866 return; 867 } 868 } 869 } 870 } 871 }else{ 872 if(strcmp(ioType,"input")==0){ 873 map* error=createMap("code","BadRequest"); 874 char tmpS1[1024]; 875 sprintf(tmpS1,_("Missing input for %s"),ioElements->name); 876 addToMap(error,"message",tmpS1); 877 setMapInMaps(conf,"lenv","status_code","400 Bad Request"); 878 printExceptionReportResponseJ(conf,error); 879 return; 880 }else{ 881 // Outputs 882 if(json_object_object_get_ex(json_current_io,"transmissionMode",&json_cinput)!=FALSE){ 883 if(cMaps->content==NULL) 884 cMaps->content=createMap("transmissionMode",json_object_get_string(json_cinput)); 885 else 886 addToMap(cMaps->content,"transmissionMode",json_object_get_string(json_cinput)); 887 } 888 if(json_object_object_get_ex(json_current_io,"format",&json_cinput)!=FALSE){ 889 json_object_object_foreach(json_cinput, key, val) { 890 if(cMaps->content==NULL) 891 cMaps->content=createMap(key,json_object_get_string(val)); 892 else 893 addToMap(cMaps->content,key,json_object_get_string(val)); 894 } 895 } 896 } 923 if(json_object_is_type(json_io,json_type_array)){ 924 size_t len=json_object_array_length(json_io); 925 for(int i=0;i<len;i++){ 926 maps *cMaps=NULL; 927 json_current_io=json_object_array_get_idx(json_io,i); 928 json_object* cname=NULL; 929 if(json_object_object_get_ex(json_current_io,"id",&cname)!=FALSE) { 930 json_object* json_input=NULL; 931 if(json_object_object_get_ex(json_current_io,"input",&json_input)!=FALSE) { 932 parseJIOSingle(conf,ioElements,ioMaps,ioType,json_object_get_string(cname),json_input); 933 }else 934 parseJIOSingle(conf,ioElements,ioMaps,ioType,json_object_get_string(cname),json_current_io); 897 935 } 898 936 } 899 addToMap(cMaps->content,"inRequest","true"); 900 if (ioMaps == NULL) 901 *ioMaps = dupMaps(&cMaps); 902 else 903 addMapsToMaps (ioMaps, cMaps); 937 }else{ 938 json_object_object_foreach(json_io, key, val) { 939 parseJIOSingle(conf,ioElements,ioMaps,ioType,key,val); 940 } 904 941 } 905 942 } … … 924 961 maps* in=*inputs; 925 962 parseJIO(conf,req,s->inputs,inputs,"inputs"); 963 parseJIO(conf,req,s->outputs,outputs,"outputs"); 926 964 927 965 if(parsed==0){ 928 json_io=NULL;929 if(json_object_object_get_ex(req,"outputs",&json_io)!=FALSE){930 parseJIO(conf,req,s->outputs,outputs,"outputs");931 }932 966 json_io=NULL; 933 967 if(json_object_object_get_ex(req,"mode",&json_io)!=FALSE){ … … 967 1001 } 968 1002 1003 /** 1004 * Print the jobs status info 1005 * cf. 1006 * 1007 * @param conf the maps containing the settings of the main.cfg file 1008 * @return the JSON object pointer to the jobs list 1009 */ 1010 json_object* printJobStatus(maps* pmsConf,char* pcJobId){ 1011 json_object* pjoRes=NULL; 1012 runGetStatus(pmsConf,pcJobId,"GetStatus"); 1013 map* pmError=getMapFromMaps(pmsConf,"lenv","error"); 1014 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 1015 printExceptionReportResponseJ(pmsConf,getMapFromMaps(pmsConf,"lenv","code")); 1016 return NULL; 1017 }else{ 1018 map* pmStatus=getMapFromMaps(pmsConf,"lenv","status"); 1019 setMapInMaps(pmsConf,"lenv","gs_location","false"); 1020 setMapInMaps(pmsConf,"lenv","gs_usid",pcJobId); 1021 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Failed",6)==0) 1022 pjoRes=createStatus(pmsConf,SERVICE_FAILED); 1023 else 1024 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Succeeded",9)==0) 1025 pjoRes=createStatus(pmsConf,SERVICE_SUCCEEDED); 1026 else 1027 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Running",7)==0){ 1028 map* tmpMap=getMapFromMaps(pmsConf,"lenv","Message"); 1029 if(tmpMap!=NULL) 1030 setMapInMaps(pmsConf,"lenv","gs_message",tmpMap->value); 1031 pjoRes=createStatus(pmsConf,SERVICE_STARTED); 1032 } 1033 else 1034 pjoRes=createStatus(pmsConf,SERVICE_FAILED); 1035 } 1036 return pjoRes; 1037 } 1038 969 1039 /** 970 1040 * Print the jobs list … … 985 1055 char* extn = strstr(dp->d_name, ".json"); 986 1056 if(extn!=NULL){ 987 json_object* cjob=json_object_new_object();988 1057 char* tmpStr=zStrdup(dp->d_name); 989 1058 tmpStr[strlen(dp->d_name)-5]=0; 1059 json_object* cjob=json_object_new_object(); 990 1060 json_object_object_add(cjob,"id",json_object_new_string(tmpStr)); 991 char *tmps1=(char*)malloc((strlen(cpath)+strlen(dp->d_name)+2)*sizeof(char)); 992 sprintf (tmps1, "%s/%s", cpath, dp->d_name); 993 FILE* cdat=fopen(tmps1,"rb"); 994 if(cdat!=NULL){ 995 zStatStruct f_status; 996 int s=zStat(tmps1, &f_status); 997 char* mystring=(char*)malloc((f_status.st_size+1)*sizeof(char)); 998 fread(mystring,1,f_status.st_size,cdat); 999 mystring[f_status.st_size]=0; 1000 json_object *jobj = NULL; 1001 int slen = 0; 1002 enum json_tokener_error jerr; 1003 struct json_tokener* tok=json_tokener_new(); 1004 do { 1005 slen = strlen(mystring); 1006 jobj = json_tokener_parse_ex(tok, mystring, slen); 1007 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 1008 if (jerr != json_tokener_success) { 1009 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 1010 return NULL; 1011 } 1012 if (tok->char_offset < slen){ 1013 return NULL; 1014 } 1061 json_object *jobj=printJobStatus(conf,tmpStr); 1062 if(jobj!=NULL) 1015 1063 json_object_object_add(cjob,"infos",jobj); 1016 free(mystring);1017 fclose(cdat);1018 }1019 1064 free(tmpStr); 1020 1065 json_object_array_add(res,cjob); … … 1036 1081 */ 1037 1082 json_object* printJResult(maps* conf,service* s,maps* result,int res){ 1038 json_object* eres1=json_object_new_object();1039 1083 if(res==SERVICE_FAILED){ 1040 1084 char* pacTmp=produceErrorMessage(conf); … … 1051 1095 if(getMapFromMaps(conf,"lenv","no-headers")==NULL) 1052 1096 printHeaders(conf); 1053 json_object* eres=json_object_new_array(); 1054 maps* resu=result; 1055 int itn=0; 1056 while(resu!=NULL){ 1057 json_object* res1=json_object_new_object(); 1058 json_object_object_add(res1,"id",json_object_new_string(resu->name)); 1059 map* tmpMap=getMap(resu->content,"mimeType"); 1060 json_object* res3=json_object_new_object(); 1061 if(tmpMap!=NULL) 1062 json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value)); 1063 if((tmpMap=getMap(resu->content,"value"))!=NULL || 1064 (getMap(resu->content,"generated_file"))!=NULL){ 1065 json_object* res2=json_object_new_object(); 1066 map* tmpMap1=NULL; 1067 if((tmpMap1=getMap(resu->content,"transmissionMode"))!=NULL) { 1068 if(strcmp(tmpMap1->value,"value")==0) { 1069 map* tmpMap2=getMap(resu->content,"mimeType"); 1070 if(tmpMap2!=NULL && strstr(tmpMap2->value,"json")!=NULL){ 1071 json_object *jobj = NULL; 1072 int slen = 0; 1073 enum json_tokener_error jerr; 1074 struct json_tokener* tok=json_tokener_new(); 1075 do { 1076 slen = strlen(tmpMap->value); 1077 jobj = json_tokener_parse_ex(tok, tmpMap->value, slen); 1078 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 1079 if (jerr != json_tokener_success) { 1080 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 1081 return eres1; 1097 map* pmMode=getMapFromMaps(conf,"request","response"); 1098 if(pmMode!=NULL && strncasecmp(pmMode->value,"raw",3)==0){ 1099 maps* resu=result; 1100 printRawdataOutput(conf,resu); 1101 map* pmError=getMapFromMaps(conf,"lenv","error"); 1102 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 1103 printExceptionReportResponseJ(conf,pmError); 1104 } 1105 return NULL; 1106 }else{ 1107 json_object* eres1=json_object_new_object(); 1108 map* pmIOAsArray=getMapFromMaps(conf,"openapi","io_as_array"); 1109 json_object* eres; 1110 if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0) 1111 eres=json_object_new_array(); 1112 else 1113 eres=json_object_new_object(); 1114 maps* resu=result; 1115 int itn=0; 1116 while(resu!=NULL){ 1117 json_object* res1=json_object_new_object(); 1118 if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0) 1119 json_object_object_add(res1,"id",json_object_new_string(resu->name)); 1120 map* tmpMap=getMap(resu->content,"mimeType"); 1121 json_object* res3=json_object_new_object(); 1122 if(tmpMap!=NULL) 1123 json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value)); 1124 else{ 1125 json_object_object_add(res3,"mimeType",json_object_new_string("text/plain")); 1126 map* pmDataType=getMap(resu->content,"dataType"); 1127 if(pmDataType!=NULL){ 1128 json_object* pjoTmp3=json_object_new_object(); 1129 json_object_object_add(pjoTmp3,"name",json_object_new_string(pmDataType->value)); 1130 json_object_object_add(res1,"dataType",pjoTmp3); 1131 } 1132 } 1133 if((tmpMap=getMap(resu->content,"value"))!=NULL || 1134 (getMap(resu->content,"generated_file"))!=NULL){ 1135 //json_object* res2=json_object_new_object(); 1136 map* tmpMap1=NULL; 1137 if((tmpMap1=getMap(resu->content,"transmissionMode"))!=NULL) { 1138 if(strcmp(tmpMap1->value,"value")==0) { 1139 map* tmpMap2=getMap(resu->content,"mimeType"); 1140 if(tmpMap2!=NULL && strstr(tmpMap2->value,"json")!=NULL){ 1141 json_object *jobj = NULL; 1142 int slen = 0; 1143 enum json_tokener_error jerr; 1144 struct json_tokener* tok=json_tokener_new(); 1145 do { 1146 slen = strlen(tmpMap->value); 1147 jobj = json_tokener_parse_ex(tok, tmpMap->value, slen); 1148 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 1149 if (jerr != json_tokener_success) { 1150 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 1151 return eres1; 1152 } 1153 if (tok->char_offset < slen){ 1154 return eres1; 1155 } 1156 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 1157 json_object_object_add(res1,"value",jobj); 1158 }else{ 1159 map* tmp1=getMapFromMaps(conf,"main","tmpPath"); 1160 map *gfile=getMap(resu->content,"generated_file"); 1161 if(gfile!=NULL){ 1162 gfile=getMap(resu->content,"expected_generated_file"); 1163 if(gfile==NULL){ 1164 gfile=getMap(resu->content,"generated_file"); 1165 } 1166 FILE* pfData=fopen(gfile->value,"rb"); 1167 if(pfData!=NULL){ 1168 zStatStruct f_status; 1169 int s=zStat(gfile->value, &f_status); 1170 char* pcaTmp=(char*)malloc((f_status.st_size+1)*sizeof(char)); 1171 fread(pcaTmp,1,f_status.st_size,pfData); 1172 pcaTmp[f_status.st_size]=0; 1173 fclose(pfData); 1174 json_object_object_add(res1,"value",json_object_new_string(base64(pcaTmp,f_status.st_size))); 1175 json_object_object_add(res3,"encoding",json_object_new_string("base64")); 1176 free(pcaTmp); 1177 } 1178 }else{ 1179 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 1180 json_object_object_add(res1,"value",json_object_new_string(tmpMap->value)); 1181 } 1082 1182 } 1083 if (tok->char_offset < slen){ 1084 return eres1; 1085 } 1086 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 1087 json_object_object_add(res2,"inlineValue",jobj); 1088 }else{ 1089 map* tmp1=getMapFromMaps(conf,"main","tmpPath"); 1090 map *gfile=getMap(resu->content,"generated_file"); 1091 if(gfile!=NULL){ 1092 gfile=getMap(resu->content,"expected_generated_file"); 1093 if(gfile==NULL){ 1094 gfile=getMap(resu->content,"generated_file"); 1095 } 1096 FILE* pfData=fopen(gfile->value,"rb"); 1097 if(pfData!=NULL){ 1098 zStatStruct f_status; 1099 int s=zStat(gfile->value, &f_status); 1100 char* pcaTmp=(char*)malloc((f_status.st_size+1)*sizeof(char)); 1101 fread(pcaTmp,1,f_status.st_size,pfData); 1102 pcaTmp[f_status.st_size]=0; 1103 fclose(pfData); 1104 json_object_object_add(res2,"inlineValue",json_object_new_string(base64(pcaTmp,f_status.st_size))); 1105 json_object_object_add(res3,"encoding",json_object_new_string("base64")); 1106 free(pcaTmp); 1107 } 1108 }else{ 1109 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 1110 json_object_object_add(res2,"inlineValue",json_object_new_string(tmpMap->value)); 1183 } 1184 else{ 1185 char *pcaFileUrl=produceFileUrl(s,conf,resu,NULL,itn); 1186 itn++; 1187 if(pcaFileUrl!=NULL){ 1188 json_object_object_add(res1,"href", 1189 json_object_new_string(pcaFileUrl)); 1190 free(pcaFileUrl); 1111 1191 } 1112 1192 } 1113 1193 } 1114 else{ 1115 // Create file for reference data if not existing 1116 map *gfile=getMap(resu->content,"generated_file"); 1117 char *file_name=NULL; 1118 char *file_path=NULL; 1119 char *file_url=NULL; 1120 map *tmp1=getMapFromMaps(conf,"main","tmpPath"); 1121 if(gfile!=NULL){ 1122 gfile=getMap(resu->content,"expected_generated_file"); 1123 if(gfile==NULL){ 1124 gfile=getMap(resu->content,"generated_file"); 1125 } 1126 if(strstr(gfile->value,tmp1->value)!=NULL) 1127 file_name=zStrdup(strstr(gfile->value,tmp1->value)+strlen(tmp1->value)); 1128 }/*else*/ 1129 { 1130 // Create file for reference data 1131 map *tmpUrl=getMapFromMaps(conf,"main","tmpUrl"); 1132 map *usid=getMapFromMaps(conf,"lenv","usid"); 1133 map *ext=getMap(resu->content,"extension"); 1134 if(gfile==NULL){ 1135 char file_ext[32]; 1136 if( ext != NULL && ext->value != NULL) { 1137 strncpy(file_ext, ext->value, 32); 1138 } 1139 else { 1140 // Obtain default file extension (see mimetypes.h). 1141 // If the MIME type is not recognized, txt is used as the default extension 1142 map* mtype=getMap(resu->content,"mimeType"); 1143 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 1144 } 1145 if(file_name!=NULL) 1146 free(file_name); 1147 1148 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(resu->name)+45)*sizeof(char)); 1149 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,resu->name,usid->value,itn,file_ext); 1150 1151 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 1152 sprintf(file_path,"%s/%s",tmp1->value,file_name); 1153 }else{ 1154 file_path=(char*)malloc((strlen(gfile->value)+1)*sizeof(char)); 1155 sprintf(file_path,"%s",gfile->value); 1156 } 1157 1158 1159 itn++; 1160 1161 file_url=(char*)malloc((strlen(tmpUrl->value)+ 1162 strlen(file_name)+2)*sizeof(char)); 1163 sprintf(file_url,"%s/%s",tmpUrl->value,file_name); 1164 1165 if(gfile==NULL){ 1166 FILE *ofile=fopen(file_path,"wb"); 1167 if(ofile==NULL){ 1168 char tmpMsg[1024]; 1169 sprintf(tmpMsg, 1170 _("Unable to create the file \"%s\" for storing the %s final result."), 1171 file_name,resu->name); 1172 map* error=createMap("code","InternalError"); 1173 addToMap(error,"message",tmpMsg); 1174 printExceptionReportResponseJ(conf,error); 1175 free(file_name); 1176 free(file_path); 1177 return NULL; 1178 } 1179 1180 map* toto=getMap(resu->content,"value"); 1181 if(toto==NULL){ 1182 char tmpMsg[1024]; 1183 sprintf(tmpMsg, 1184 _("No value found for the requested output %s."), 1185 resu->name); 1186 map* error=createMap("code","InternalError"); 1187 addToMap(error,"message",tmpMsg); 1188 printExceptionReportResponseJ(conf,error); 1189 fclose(ofile); 1190 free(file_name); 1191 free(file_path); 1192 return NULL; 1193 } 1194 map* size=getMap(resu->content,"size"); 1195 if(size!=NULL && toto!=NULL) 1196 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); 1197 else 1198 if(toto!=NULL && toto->value!=NULL) 1199 fwrite(toto->value,1, 1200 strlen(toto->value)*sizeof(char),ofile); 1201 fclose(ofile); 1202 } 1203 json_object_object_add(res2,"href", 1204 json_object_new_string(file_url)); 1205 free(file_url); 1206 free(file_name); 1207 free(file_path); 1208 1209 } 1210 1211 } 1212 } 1213 json_object_object_add(res1,"value",res2); 1214 json_object_object_add(res1,"format",res3); 1215 json_object_array_add(eres,res1); 1216 } 1217 resu=resu->next; 1218 } 1219 json_object_object_add(eres1,"outputs",eres); 1220 const char* jsonStr = 1221 json_object_to_json_string_ext(eres1,JSON_C_TO_STRING_PLAIN); 1222 map *tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 1223 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1224 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1225 char *pacTmp=(char*)malloc((strlen(tmpPath->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char)); 1226 sprintf(pacTmp,"%s/%s_%s.json", 1227 tmpPath->value,cIdentifier->value,sessId->value); 1228 zStatStruct zsFStatus; 1229 int iS=zStat(pacTmp, &zsFStatus); 1230 if(iS==0 && zsFStatus.st_size>0){ 1231 map* tmpPath1 = getMapFromMaps (conf, "main", "tmpUrl"); 1232 char* pacTmpUrl=(char*)malloc((strlen(tmpPath1->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));; 1233 sprintf(pacTmpUrl,"%s/%s_%s.json",tmpPath1->value, 1234 cIdentifier->value,sessId->value); 1235 if(getMapFromMaps(conf,"lenv","gs_location")==NULL) 1236 setMapInMaps(conf,"headers","Location",pacTmpUrl); 1237 free(pacTmpUrl); 1238 } 1239 free(pacTmp); 1240 if(res==3){ 1241 map* mode=getMapFromMaps(conf,"request","mode"); 1242 if(mode!=NULL && strncasecmp(mode->value,"async",5)==0) 1243 setMapInMaps(conf,"headers","Status","201 Created"); 1244 else 1245 setMapInMaps(conf,"headers","Status","200 Ok"); 1246 } 1247 else{ 1248 setMapInMaps(conf,"headers","Status","500 Issue running your service"); 1249 } 1250 return eres1; 1194 //json_object_object_add(res1,"value",res2); 1195 json_object_object_add(res1,"format",res3); 1196 if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0){ 1197 json_object_array_add(eres,res1); 1198 }else 1199 json_object_object_add(eres,resu->name,res1); 1200 } 1201 resu=resu->next; 1202 } 1203 json_object_object_add(eres1,"outputs",eres); 1204 const char* jsonStr = 1205 json_object_to_json_string_ext(eres1,JSON_C_TO_STRING_PLAIN); 1206 map *tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 1207 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1208 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1209 char *pacTmp=(char*)malloc((strlen(tmpPath->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char)); 1210 sprintf(pacTmp,"%s/%s_%s.json", 1211 tmpPath->value,cIdentifier->value,sessId->value); 1212 zStatStruct zsFStatus; 1213 int iS=zStat(pacTmp, &zsFStatus); 1214 if(iS==0 && zsFStatus.st_size>0){ 1215 map* tmpPath1 = getMapFromMaps (conf, "main", "tmpUrl"); 1216 char* pacTmpUrl=(char*)malloc((strlen(tmpPath1->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));; 1217 sprintf(pacTmpUrl,"%s/%s_%s.json",tmpPath1->value, 1218 cIdentifier->value,sessId->value); 1219 if(getMapFromMaps(conf,"lenv","gs_location")==NULL) 1220 setMapInMaps(conf,"headers","Location",pacTmpUrl); 1221 free(pacTmpUrl); 1222 } 1223 free(pacTmp); 1224 if(res==3){ 1225 map* mode=getMapFromMaps(conf,"request","mode"); 1226 if(mode!=NULL && strncasecmp(mode->value,"async",5)==0) 1227 setMapInMaps(conf,"headers","Status","201 Created"); 1228 else 1229 setMapInMaps(conf,"headers","Status","200 Ok"); 1230 } 1231 else{ 1232 setMapInMaps(conf,"headers","Status","500 Issue running your service"); 1233 } 1234 return eres1; 1235 } 1251 1236 } 1252 1237 … … 1338 1323 } 1339 1324 tmp1=(char*) realloc(tmp1,(strlen(tmpPath->value)+ 1340 strlen(cIdentifier->value)+1341 strlen(sessId->value)+21)*sizeof(char));1325 strlen(cIdentifier->value)+ 1326 strlen(sessId->value)+21)*sizeof(char)); 1342 1327 int needResult=0; 1343 1328 char *message, *rstatus; … … 1652 1637 json_object_object_add(cc,"$ref",json_object_new_string(pmSchema->value)); 1653 1638 if(useContent!=NULL && strncasecmp(useContent->value,"true",4)!=0){ 1654 1639 json_object_object_add(res,code,cc); 1655 1640 }else{ 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1641 json_object *cc0=json_object_new_object(); 1642 if(pmSchema!=NULL) 1643 json_object_object_add(cc0,"schema",cc); 1644 json_object *cc1=json_object_new_object(); 1645 if(pmType!=NULL) 1646 json_object_object_add(cc1,pmType->value,cc0); 1647 else 1648 json_object_object_add(cc1,"application/json",cc0); 1649 json_object *cc2=json_object_new_object(); 1650 json_object_object_add(cc2,"content",cc1); 1651 json_object_object_add(cc2,"description",json_object_new_string(msg)); 1652 json_object_object_add(res,code,cc2); 1668 1653 } 1669 1654 } -
trunk/zoo-project/zoo-kernel/service_json.h
r962 r967 52 52 void parseJRequest(maps*,service* s,json_object*,map*,maps**,maps**); 53 53 json_object* printJResult(maps*,service*,maps*,int); 54 json_object* printJobStatus(maps*,char*); 54 55 json_object* printJobList(maps*); 55 56 int createStatusFile(maps*,int); -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r966 r967 419 419 420 420 map* errormap = createMap("text", tmp01); 421 map* tmpMap=getMapFromMaps(m," lenv","executionType");421 map* tmpMap=getMapFromMaps(m,"main","executionType"); 422 422 char* errorCode=(char*)code; 423 423 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"json",4)==0) … … 1888 1888 maps *request_input_real_format = NULL; 1889 1889 1890 setMapInMaps(m," lenv","executionType","xml");1890 setMapInMaps(m,"main","executionType","xml"); 1891 1891 if((strlen(cgiQueryString)>0 && cgiQueryString[0]=='/') /*&& strstr(cgiAccept,"json")!=NULL*/){ 1892 1892 // 1893 // OGC API - Process ingstarts here1893 // OGC API - Processes starts here 1894 1894 // 1895 1895 #ifndef USE_JSON 1896 errorException (m, _("OGC API - Process ing is not supported by this ZOO-Kernel."), "InternalError", NULL);1896 errorException (m, _("OGC API - Processes is not supported by this ZOO-Kernel, please contact the service provider."), "InternalError", NULL); 1897 1897 return 1; 1898 1898 #else … … 1908 1908 signal (SIGABRT, json_sig_handler); 1909 1909 #endif 1910 setMapInMaps(m,"main","executionType","json"); 1910 1911 r_inputs = getMapOrFill (&request_inputs, "metapath", ""); 1911 1912 char conf_file1[10240]; … … 1920 1921 } 1921 1922 addMapsToMaps(&m,m1); 1922 setMapInMaps(m,"lenv","executionType","json");1923 1923 map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support"); 1924 dumpMap(pmTmp0);1925 1924 if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){ 1926 1925 map* pmTmpUrl=getMapFromMaps(m,"openapi","rootUrl"); … … 2305 2304 }else{ 2306 2305 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2307 runGetStatus(m,jobId,"GetStatus"); 2308 map* pmError=getMapFromMaps(m,"lenv","error"); 2309 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2310 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2311 return 1; 2312 }else{ 2313 map* pmStatus=getMapFromMaps(m,"lenv","status"); 2314 setMapInMaps(m,"lenv","gs_location","false"); 2315 setMapInMaps(m,"lenv","gs_usid",jobId); 2316 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Failed",6)==0) 2317 res=createStatus(m,SERVICE_FAILED); 2318 else 2319 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Succeeded",9)==0) 2320 res=createStatus(m,SERVICE_SUCCEEDED); 2321 else 2322 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Running",7)==0){ 2323 map* tmpMap=getMapFromMaps(m,"lenv","Message"); 2324 if(tmpMap!=NULL) 2325 setMapInMaps(m,"lenv","gs_message",tmpMap->value); 2326 res=createStatus(m,SERVICE_STARTED); 2327 } 2328 else 2329 res=createStatus(m,SERVICE_FAILED); 2330 } 2306 res=printJobStatus(m,jobId); 2331 2307 free(jobId); 2332 2308 } … … 2530 2506 map* testMap=getMapFromMaps(m,"main","memory"); 2531 2507 loadHttpRequests(m,request_input_real_format); 2532 dumpMaps(request_input_real_format); 2508 2509 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0) 2510 return -1; 2533 2511 loadServiceAndRun (&m, s1, request_inputs, 2534 2512 &request_input_real_format, … … 2548 2526 }else{ 2549 2527 loadHttpRequests(m,request_input_real_format); 2528 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0) 2529 return -1; 2550 2530 loadServiceAndRun (&m,s1,request_inputs, 2551 2531 &request_input_real_format, … … 2560 2540 } 2561 2541 } 2562 if(res!=NULL){ 2542 map* pmHasPrinted=getMapFromMaps(m,"lenv","hasPrinted"); 2543 if(res!=NULL && (pmHasPrinted==NULL || strncasecmp(pmHasPrinted->value,"false",5)==0)){ 2563 2544 if(getMapFromMaps(m,"lenv","no-headers")==NULL){ 2564 2545 printHeaders(m); … … 2573 2554 #endif 2574 2555 }else{ 2575 2576 2556 // 2577 2557 // WPS 1.0.0 and 2.0.0 starts here 2578 2558 // 2559 setMapInMaps(m,"main","executionType","xml"); 2579 2560 //Check for minimum inputs 2580 2561 map* version=getMap(request_inputs,"version"); … … 3435 3416 signal (SIGABRT, donothing); 3436 3417 #endif 3418 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 3419 fflush(stderr); 3437 3420 3438 3421 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 3439 3422 { 3423 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 3424 fflush(stderr); 3440 3425 if (eres == SERVICE_SUCCEEDED) 3441 3426 #ifdef USE_CALLBACK … … 3495 3480 if(cgiSid!=NULL) 3496 3481 free(cgiSid); 3497 map* tMap=getMapFromMaps(m," lenv","executionType");3482 map* tMap=getMapFromMaps(m,"main","executionType"); 3498 3483 if(tMap!=NULL && strncasecmp(tMap->value,"xml",3)==0) 3499 3484 InternetCloseHandle (&hInternet); … … 3524 3509 free (REQUEST); 3525 3510 free (SERVICE_URL); 3511 3526 3512 #ifdef DEBUG 3527 3513 fprintf (stderr, "Processed response \n"); -
trunk/zoo-project/zoo-services/utils/open-api/server/.htaccess
r962 r967 1 RewriteRule ^ogc-api/api.html$ /cgi-bin 3/zoo_loader.cgi?/api.html [L,QSA]2 RewriteRule ^ogc-api/index.html$ /cgi-bin 3/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api/ [L,QSA]3 RewriteRule ^ogc-api(.*).html$ /cgi-bin 3/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api$1 [L,QSA]4 RewriteRule ^ogc-api(.*)$ /cgi-bin 3/zoo_loader.cgi?$1 [L,QSA]1 RewriteRule ^ogc-api/api.html$ /cgi-bin/zoo_loader.cgi?/api.html [L,QSA] 2 RewriteRule ^ogc-api/index.html$ /cgi-bin/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api/ [L,QSA] 3 RewriteRule ^ogc-api(.*).html$ /cgi-bin/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api$1 [L,QSA] 4 RewriteRule ^ogc-api(.*)$ /cgi-bin/zoo_loader.cgi?$1 [L,QSA] -
trunk/zoo-project/zoo-services/utils/open-api/templates/index.html
r965 r967 269 269 #set $cid="JOBSOCKET-"+$conf["lenv"]["usid"] 270 270 <form class="needs-validation" data-id="$cid" novalidate> 271 <h3>Inputs</h3> 272 <div class="accordion" id="accordionInputExample"> 273 #for i in range(len(values["inputs"])) 274 #set cInput=$values["inputs"][$i] 275 #set cName=$cInput["id"].replace(".","_") 276 $printCard({"id": $cName, "title": $cInput["id"],"content":'<p>'+$cInput["description"]+'</p>'+$printInputContent($cInput)}) 277 #end for 278 </div> 271 <input type="hidden" name="oapi_ioAsArray" value="#if "io_as_array" in $openapi["openapi"]#$openapi["openapi"]["io_as_array"]#else#false#end if#" /> 272 <input type="hidden" name="oapi_wsUrl" value="$openapi["openapi"]["wsurl"]" /> 273 <input type="hidden" name="oapi_jobUrl" value="$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs" /> 274 <input type="hidden" name="oapi_reqID" value="$cid" /> 275 <h3>Inputs</h3> 276 <div class="accordion" id="accordionInputExample"> 277 #for i in range(len(values["inputs"])) 278 #set cInput=$values["inputs"][$i] 279 #set cName=$cInput["id"].replace(".","_") 280 $printCard({"id": $cName, "title": $cInput["id"],"content":'<p>'+$cInput["description"]+'</p>'+$printInputContent($cInput)}) 281 #end for 282 </div> 279 283 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 284 <h3>Outputs</h3> 285 <div class="accordion" id="accordionOutputExample"> 286 #for i in range(len(values["outputs"])) 287 #set cOutput=$values["outputs"][$i] 288 #set cName=$cOutput["id"].replace(".","_") 289 #set cFormats=[] 290 #if "formats" in $cOutput["output"] 291 #for j in range(len($cOutput["output"]["formats"])) 292 #set cFormats+=[$cOutput["output"]["formats"][$j]["mimeType"]] 293 #end for 294 #end if 295 #set cTransmissions=[] 296 #for j in range(len($values["outputTransmission"])) 297 #set cTransmissions+=[$values["outputTransmission"][$j]] 298 #end for 299 #set cContent="<p>"+$cOutput["description"]+"</p>" 300 #if len(cFormats)>0 301 #set $cContent+=$printControl({"id": $cOutput["id"], "title": "format","type": "format","name": $cName,"options":$cFormats}) 302 #end if 303 #if len(cTransmissions)>0 304 #set $cContent+=$printControl({"id": $cOutput["id"], "title": "transmission","type": "transmission","name": $cName,"options":$cTransmissions}) 305 #end if 306 $printCard({"id": $cName+"_"+str($i),"title": $cOutput["id"],"content": $cContent}) 307 #end for 308 </div> 305 309 306 <h3>Execution options</h3> 307 <div class="accordion" id="accordionExampleExecutionMode"> 308 #set cContent="" 309 #set cUrl=$openapi["openapi"]["publisherurl"]+cid+"&type=" 310 #for a in ["successUri","inProgressUri","failedUri"] 311 #set $cContent+=$printControl({"title": $a,"type": "main_value","name": $a,"ph":"URL","value":$cUrl+$a.replace("Uri","")}) 312 #end for 313 $printCard({"id":"ModeOne","title":"Subscribers","content": $cContent}) 314 $printCard({"id":"ModeTwo","title":"Response","content": $printControl({"title":"format","type": "main_value","name": "format","options":["document","raw"]})}) 315 $printCard({"id":"ModeThree","title":"Mode","content": $printControl({"title":"mode","type": "main_value","name": "mode","options":["async","sync"]})}) 316 </div> 317 <button type="submit" class="btn btn-primary" >Submit</button> 318 </form> 310 <h3>Execution options</h3> 311 <div class="accordion" id="accordionExampleExecutionMode"> 312 #set cContent="" 313 #set cUrl=$openapi["openapi"]["publisherurl"]+cid+"&type=" 314 #for a in ["successUri","inProgressUri","failedUri"] 315 #set $cContent+=$printControl({"title": $a,"type": "main_value","name": $a,"ph":"URL","value":$cUrl+$a.replace("Uri","")}) 316 #end for 317 $printCard({"id":"ModeOne","title":"Subscribers","content": $cContent}) 318 $printCard({"id":"ModeTwo","title":"Response","content": $printControl({"title":"format","type": "main_value","name": "format","options":["document","raw"]})}) 319 $printCard({"id":"ModeThree","title":"Mode","content": $printControl({"title":"mode","type": "main_value","name": "mode","options":["async","sync"]})}) 320 </div> 321 322 <button type="submit" class="btn btn-primary" >Submit</button> 323 </form> 319 324 <div class="modal" tabindex="-1" id="exampleModal"> 320 325 <div class="modal-dialog modal-xl"> … … 343 348 </div> 344 349 </div> 345 <script> 346 var socket; 347 function addElementToList(){ 348 var lClosure=arguments[0]; 349 var isOver=false; 350 var cnt=0; 351 lClosure.parent().parent().find("div").each(function(){ 352 if(isOver) return; 353 if(\$(this).hasClass("btn-group")) isOver=true; 354 if(\$(this).hasClass("input-group")){ 355 lClosure.parent().parent().append(\$(this)[0].outerHTML); 356 cnt++; 357 } 358 }); 359 if(lClosure.parent().parent().find(".input-group").length>cnt) 360 lClosure.next().attr("disabled",false); 361 else 362 lClosure.next().attr("disabled",true); 363 } 364 function delElementToList(){ 365 var lClosure=arguments[0]; 366 var isOver=false; 367 var cnt=0; 368 lClosure.parent().parent().find("div").each(function(){ 369 if(isOver) return; 370 if(\$(this).hasClass("btn-group")) isOver=true; 371 if(\$(this).hasClass("input-group")) cnt++; 372 }); 373 if(lClosure.parent().parent().find(".input-group").length>cnt) 374 for(var i=0;i<cnt;i++) 375 lClosure.parent().parent().find(".input-group").last().remove(); 376 if(lClosure.parent().parent().find(".input-group").length==cnt) 377 lClosure.attr("disabled",true); 378 else 379 lClosure.attr("disabled",false); 380 } 381 382 function loadRequest(){ 383 var requestObject={ 384 "inputs":[], 385 "outputs":[], 386 "subscriber":{}, 387 "mode": \$("select[name='main_value_mode']").val(), 388 "response": \$("select[name='main_value_format']").val() 389 } 390 for(var i=0;i < System["JSON_STR"]["inputs"].length;i++){ 391 var cName=System["JSON_STR"]["inputs"][i]["id"].replace(".","_"); 392 var selector="input[name='input_value_"+cName+"'],"+ 393 "select[name='input_value_"+cName+"']"; 394 if(\$(selector).val()!=""){ 395 \$(selector).each(function(){ 396 var cInput={"id": System["JSON_STR"]["inputs"][i]["id"], "input": {}}; 397 if(System["JSON_STR"]["inputs"][i]["input"]["formats"]){ 398 var selector1="input[name='input_format_"+cName+"'],"+ 399 "select[name='input_format_"+cName+"']"; 400 console.log(\$(this).parent().prev().find("select").val()); 401 cInput["input"]["format"]={ 402 "mimeType": \$(this).parent().prev().find("select").val() 403 }; 404 cInput["input"]["value"]={ 405 "href": \$(this).val() 406 }; 407 } 408 else{ 409 if(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]){ 410 console.log(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]); 411 cInput["input"]["dataType"]={ 412 "name": System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"][0]["dataType"]["name"] 413 }; 414 cInput["input"]["value"]=\$(this).val(); 415 } 416 }console.log(cInput); 417 requestObject["inputs"].push(cInput); 418 }); 419 } 420 } 421 console.log(System["JSON_STR"]["outputs"]); 422 for(var i=0;i < System["JSON_STR"]["outputs"].length;i++){ 423 var cOutput={"id": System["JSON_STR"]["outputs"][i]["id"]}; 424 var cName=System["JSON_STR"]["outputs"][i]["id"].replace(/\./g,"_"); 425 if(System["JSON_STR"]["outputs"][i]["output"]["formats"]){ 426 var selector="select[name='format_"+cName+"']"; 427 cOutput["format"]={ 428 "mimeType": \$(selector).val() 429 }; 430 } 431 else{ 432 if(System["JSON_STR"]["outputs"][i]["output"]["literalDataDomains"]){ 433 cOutput["dataType"]={ 434 "name": System["JSON_STR"]["outputs"][i]["output"]["literalDataDomains"][0]["dataType"]["name"] 435 }; 436 } 437 } 438 var selector1="select[name='transmission_"+cName+"']"; 439 cOutput["transmissionMode"]=\$(selector1).val(); 440 requestObject["outputs"].push(cOutput); 441 } 442 if(\$("input[name='main_value_successUri']").val()!="") 443 requestObject["subscriber"]["successUri"]=\$("input[name='main_value_successUri']").val(); 444 if(\$("input[name='main_value_inProgressUri']").val()!="") 445 requestObject["subscriber"]["inProgressUri"]=\$("input[name='main_value_inProgressUri']").val(); 446 if(\$("input[name='main_value_failedUri']").val()!="") 447 requestObject["subscriber"]["failedUri"]=\$("input[name='main_value_failedUri']").val(); 448 \$(".modal").find("textarea").first().val(js_beautify(JSON.stringify(requestObject))); 449 \$("#exampleModal").modal('toggle'); 450 \$('#result').html(""); 451 \$("#exampleModal").find(".btn-primary").off('click'); 452 \$("#exampleModal").find(".btn-primary").click(function(){ 453 \$('#result').html(""); 454 if(!socket && requestObject["mode"]!="sync") 455 socket = new WebSocket("$openapi["openapi"]["wsurl"]"); 456 else 457 \$.ajax({ 458 contentType: "application/json", 459 data: \$("textarea").val(), 460 type: "POST", 461 url: "$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs", 462 success: function (msg) { 463 console.log(msg); 464 var cObj=msg; 465 \$('#result').html(js_beautify(JSON.stringify(msg["outputs"]))); 466 }, 467 error: function(){ 468 console.log(arguments); 469 }, 470 }); 471 if(requestObject["mode"]=="sync"){ 472 return; 473 } 474 socket.onopen = function () { 475 console.log('Connected!'); 476 socket.send("SUB $cid"); 477 }; 478 socket.onmessage = function(event) { 479 console.log('MESSAGE: ' + event.data); 480 if(event.data=="1") 481 \$.ajax({ 482 contentType: "application/json", 483 data: \$("textarea").val(), 484 type: "POST", 485 url: "$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs", 486 success: function (msg) { 487 console.log(msg); 488 }, 489 error: function(){ 490 console.log(arguments); 491 }, 492 }); 493 else{ 494 //progressBar 495 \$("#progress_details").show(); 496 var cObj=JSON.parse(event.data); 497 if(cObj["jobID"]){ 498 \$("#prgress_description").html(cObj["jobID"]+": "+cObj["message"]); 499 \$(".progress-bar").attr("aria-valuenow",cObj["progress"]); 500 \$(".progress-bar").css("width",cObj["progress"]+"%"); 501 }else{ 502 \$("#progress_details").hide(); 503 if(cObj["outputs"]) 504 \$('#result').html(js_beautify(JSON.stringify(cObj["outputs"]))); 505 else 506 \$('#result').html(cObj["message"]); 507 } 508 } 509 }; 510 }); 511 } 512 </script> 350 <script src="$openapi["openapi"]["rootUrl"]/../static/openapi.js"></script> 513 351 #end if 514 352 … … 687 525 <hr> 688 526 <address>$openapi["openapi"]["rootUrl"]$(currentUrl).html</address> 689 <!-- hhmts start -->Last modified: Fri Oct 23 18:25:03 CEST 2020 <!-- hhmts end -->527 <!-- hhmts start -->Last modified: Wed Dec 16 16:06:56 CET 2020 <!-- hhmts end --> 690 528 </main> 691 529 #if $currentKey=="root"
Note: See TracChangeset
for help on using the changeset viewer.