Changes in trunk/zoo-kernel/service_internal.c [26:9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/service_internal.c
r26 r9 35 35 return hex[code & 15]; 36 36 } 37 38 void* unhandleStatus(maps *conf){39 int shmid,i;40 key_t key;41 void *shm;42 struct shmid_ds shmids;43 char *s,*s1;44 map *tmpMap=getMapFromMaps(conf,"lenv","sid");45 if(tmpMap!=NULL){46 key=atoi(tmpMap->value);47 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {48 #ifdef DEBUG49 fprintf(stderr,"shmget failed to update value\n");50 #endif51 }else{52 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {53 #ifdef DEBUG54 fprintf(stderr,"shmat failed to update value\n");55 #endif56 }else{57 shmdt(shm);58 shmctl(shmid,IPC_RMID,&shmids);59 }60 }61 }62 }63 64 #ifdef USE_JS65 66 JSBool67 JSUpdateStatus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)68 {69 JS_MaybeGC(cx);70 char *sid;71 int istatus=0;72 char *status=NULL;73 maps *conf;74 int i=0;75 if(argc>2){76 #ifdef JS_DEBUG77 fprintf(stderr,"Number of arguments used to call the function : %i",argc);78 #endif79 return JS_FALSE;80 }81 conf=mapsFromJSObject(cx,argv[0]);82 dumpMaps(conf);83 if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){84 char tmpStatus[4];85 sprintf(tmpStatus,"%i",istatus);86 tmpStatus[3]=0;87 status=strdup(tmpStatus);88 }89 if(getMapFromMaps(conf,"lenv","status")!=NULL){90 if(status!=NULL)91 setMapInMaps(conf,"lenv","status",status);92 else93 setMapInMaps(conf,"lenv","status","15");94 updateStatus(conf);95 }96 freeMaps(&conf);97 free(conf);98 JS_MaybeGC(cx);99 return JS_TRUE;100 }101 102 #endif103 104 void* updateStatus(maps *conf){105 int shmid,i;106 key_t key;107 char *shm,*s,*s1;108 map *tmpMap=NULL;109 tmpMap=getMapFromMaps(conf,"lenv","sid");110 if(tmpMap!=NULL){111 key=atoi(tmpMap->value);112 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {113 #ifdef DEBUG114 fprintf(stderr,"shmget failed to update value\n");115 #endif116 }else{117 if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) {118 #ifdef DEBUG119 fprintf(stderr,"shmat failed to update value\n");120 #endif121 }122 else{123 tmpMap=getMapFromMaps(conf,"lenv","status");124 s1=shm;125 for(s=tmpMap->value;*s!=NULL;s++)126 *s1++=*s;127 shmdt((void *)shm);128 }129 }130 }131 }132 133 char* getStatus(int pid){134 int shmid,i;135 key_t key;136 void *shm;137 char *s;138 key=pid;139 if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {140 #ifdef DEBUG141 fprintf(stderr,"shmget failed in getStatus\n");142 #endif143 }else{144 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {145 #ifdef DEBUG146 fprintf(stderr,"shmat failed in getStatus\n");147 #endif148 }else{149 return (char*)shm;150 }151 }152 return "-1";153 }154 155 37 156 38 /* Returns a url-encoded version of str */ … … 847 729 char tmp[1024]; 848 730 sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); 849 xmlNewNsProp(nc6,ns_ ows,BAD_CAST "reference",BAD_CAST tmp);731 xmlNewNsProp(nc6,ns_xlink,BAD_CAST "reference",BAD_CAST tmp); 850 732 xmlAddChild(nc3,nc6); 851 733 tmp1=tmp1->next; … … 959 841 xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en"); 960 842 char tmp[256]; 961 char url[ 1024];843 char url[256]; 962 844 memset(tmp,0,256); 963 845 memset(url,0,256); 964 846 maps* tmp_maps=getMaps(m,"main"); 965 847 if(tmp_maps!=NULL){ 966 dumpMaps(getMaps(m,"lenv")); 967 map* tmpm1=getMap(tmp_maps->content,"serverAddress"); 968 /** 969 * Check if the ZOO Service GetStatus is available in the local directory. 970 * If yes, then it uses a reference to an URL which the client can access 971 * to get information on the status of a running Service (using the 972 * percentCompleted attribute). 973 * Else fallback to the initial method using the xml file to write in ... 974 */ 975 char ntmp[1024]; 976 #ifndef WIN32 977 getcwd(ntmp,1024); 978 #else 979 _getcwd(ntmp,1024); 980 #endif 981 struct stat myFileInfo; 982 int statRes; 983 char file_path[1024]; 984 sprintf(file_path,"%s/GetStatus.zcfg",ntmp); 985 statRes=stat(file_path,&myFileInfo); 986 if(statRes==0){ 987 char currentSid[128]; 988 map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); 989 map *tmp_lenv=NULL; 990 tmp_lenv=getMapFromMaps(m,"lenv","sid"); 991 if(tmp_lenv==NULL) 992 sprintf(currentSid,"%i",pid); 993 else 994 sprintf(currentSid,"%s",tmp_lenv->value); 995 if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ 996 sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); 997 }else{ 998 if(strlen(tmpm->value)>0) 999 if(strcasecmp(tmpm->value,"true")!=0) 1000 sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); 1001 else 1002 sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); 1003 else 1004 sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); 1005 } 1006 }else{ 1007 map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); 1008 if(tmpm1!=NULL && tmpm2!=NULL){ 1009 sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); 1010 } 1011 } 1012 if(tmpm1!=NULL) 1013 sprintf(tmp,"%s/",tmpm1->value); 848 map* tmpm=getMap(tmp_maps->content,"serverAddress"); 849 map* tmpm1=getMap(tmp_maps->content,"tmpUrl"); 850 if(tmpm!=NULL && tmpm1!=NULL){ 851 sprintf(url,"%s/%s/%s_%i.xml",tmpm->value,tmpm1->value,service,pid); 852 } 853 if(tmpm!=NULL) 854 sprintf(tmp,"%s/",tmpm->value); 1014 855 } 1015 856 1016 857 xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); 1017 if(status!=SERVICE_SUCCEEDED && status!=SERVICE_FAILED){858 if(status!=SERVICE_SUCCEEDED){ 1018 859 xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); 1019 860 } … … 1035 876 time_t now; 1036 877 char *tmp1; 1037 map *tmpStatus;1038 878 1039 879 now = time ( NULL ); … … 1044 884 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 1045 885 1046 xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);1047 1048 char sMsg[2048];1049 886 switch(status){ 1050 887 case SERVICE_SUCCEEDED: 888 xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); 1051 889 nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); 1052 sprintf(sMsg,"Service \"%s\" run successfully.",serv->name);1053 nc3=xmlNewText(BAD_CAST sMsg);1054 xmlAddChild(nc1,nc3);1055 890 break; 1056 891 case SERVICE_STARTED: 892 xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); 1057 893 nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); 1058 tmpStatus=getMapFromMaps(m,"lenv","status"); 1059 xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); 1060 sprintf(sMsg,"ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service.",serv->name); 1061 nc3=xmlNewText(BAD_CAST sMsg); 1062 xmlAddChild(nc1,nc3); 894 xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST "NEED_SERVICE_ACCESS"); 1063 895 break; 1064 896 case SERVICE_ACCEPTED: 897 xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); 1065 898 nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); 1066 sprintf(sMsg,"Service \"%s\" was accepted by the ZOO Kernel and it run as a background task. Please consult the statusLocation attribtue providen in this document to get the up-to-date document.",serv->name);1067 nc3=xmlNewText(BAD_CAST sMsg);1068 xmlAddChild(nc1,nc3);1069 899 break; 1070 900 case SERVICE_FAILED: 1071 901 nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); 1072 map *errorMap;1073 map *te;1074 te=getMapFromMaps(m,"lenv","code");1075 if(te!=NULL)1076 errorMap=createMap("code",te->value);1077 else1078 errorMap=createMap("code","NoApplicableCode");1079 te=getMapFromMaps(m,"lenv","message");1080 if(te!=NULL)1081 addToMap(errorMap,"text",te->value);1082 else1083 addToMap(errorMap,"text","No more information available");1084 nc3=createExceptionReportNode(m,errorMap,0);1085 xmlAddChild(nc1,nc3);1086 902 break; 1087 903 default : 1088 904 printf("error code not know : %i\n",status); 1089 //exit(1);905 exit(1); 1090 906 break; 1091 907 } … … 1243 1059 nc1=xmlNewNode(ns_wps, BAD_CAST type); 1244 1060 map *tmp=e->content; 1245 #ifdef DEBUG1061 //#ifdef DEBUG 1246 1062 dumpMap(tmp); 1247 1063 dumpElements(e); 1248 #endif1064 //#endif 1249 1065 nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); 1250 1066 nc3=xmlNewText(BAD_CAST e->name); … … 1269 1085 * IO type Reference or full Data ? 1270 1086 */ 1271 #ifdef DEBUG1087 //#ifdef DEBUG 1272 1088 fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); 1273 #endif1089 //#endif 1274 1090 map *tmpMap=getMap(m->content,"Reference"); 1275 1091 if(tmpMap==NULL){ … … 1394 1210 maps* tmpMap=getMaps(m,"main"); 1395 1211 char *encoding=getEncoding(tmpMap); 1396 map *tmpSid=getMapFromMaps(m,"lenv","sid"); 1397 if(tmpSid==NULL) 1398 printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); 1212 printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); 1399 1213 1400 1214 ns=xmlNewNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); … … 1403 1217 ns_xlink=xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink"); 1404 1218 ns_xsi=xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 1405 xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1 .0/owsExceptionReport.xsd");1219 xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1/owsExceptionReport.xsd"); 1406 1220 xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en"); 1407 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); 1221 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 1222 1223 xmlNewProp(n,BAD_CAST "version",BAD_CAST getVersion(tmpMap)); 1408 1224 1409 1225 nc = xmlNewNode(ns, BAD_CAST "Exception"); … … 1435 1251 xmlFreeNs(ns); 1436 1252 xmlCleanupParser(); 1437 }1438 1439 xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){1440 1441 int buffersize;1442 xmlChar *xmlbuff;1443 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;1444 xmlNodePtr n,nc,nc1,nc2;1445 1446 maps* tmpMap=getMaps(m,"main");1447 1448 ns=xmlNewNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");1449 n = xmlNewNode(ns, BAD_CAST "ExceptionReport");1450 1451 if(use_ns==1){1452 ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");1453 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");1454 ns_xsi=usedNs[xsiId];1455 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");1456 ns_xlink=usedNs[xlinkId];1457 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");1458 }1459 xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");1460 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0");1461 1462 nc = xmlNewNode(ns, BAD_CAST "Exception");1463 1464 map* tmp=getMap(s,"code");1465 if(tmp!=NULL)1466 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);1467 else1468 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");1469 1470 tmp=getMap(s,"text");1471 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");1472 nc2=NULL;1473 if(tmp!=NULL){1474 xmlNodeSetContent(nc1, BAD_CAST tmp->value);1475 }1476 else{1477 xmlNodeSetContent(nc1, BAD_CAST "No debug message available");1478 }1479 xmlAddChild(nc,nc1);1480 xmlAddChild(n,nc);1481 return n;1482 1253 } 1483 1254 … … 1525 1296 #endif 1526 1297 printProcessResponse(m,request_inputs1,cpid, 1527 s,r_inputs->value,res, 1528 request_inputs, 1529 request_outputs); 1530 } 1531 else 1532 if(res!=SERVICE_FAILED){ 1533 /** 1534 * We get the first output only !! 1535 */ 1536 char mime[1024]; 1537 map* mi=getMap(request_outputs->content,"mimeType"); 1538 #ifdef DEBUG 1539 fprintf(stderr,"SERVICE OUTPUTS\n"); 1540 dumpMaps(request_outputs); 1541 fprintf(stderr,"SERVICE OUTPUTS\n"); 1542 #endif 1543 map* en=getMap(request_outputs->content,"encoding"); 1544 if(mi!=NULL && en!=NULL) 1298 s,r_inputs->value,res, 1299 request_inputs, 1300 request_outputs); 1301 } 1302 else{ 1303 /** 1304 * We get the first output only !! 1305 */ 1306 char mime[1024]; 1307 map* mi=getMap(request_outputs->content,"mimeType"); 1308 #ifdef DEBUG 1309 fprintf(stderr,"SERVICE OUTPUTS\n"); 1310 dumpMaps(request_outputs); 1311 fprintf(stderr,"SERVICE OUTPUTS\n"); 1312 #endif 1313 map* en=getMap(request_outputs->content,"encoding"); 1314 if(mi!=NULL && en!=NULL) 1315 sprintf(mime, 1316 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 1317 mi->value,en->value); 1318 else 1319 if(mi!=NULL) 1545 1320 sprintf(mime, 1546 "Content-Type: %s; charset= %s\r\nStatus: 200 OK\r\n\r\n",1547 mi->value ,en->value);1321 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 1322 mi->value); 1548 1323 else 1549 if(mi!=NULL) 1550 sprintf(mime, 1551 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 1552 mi->value); 1553 else 1554 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 1555 printf("%s",mime); 1556 toto=getMap(request_outputs->content,"value"); 1557 if(mi!=NULL && strncmp(mi->value,"image",5)==0){ 1558 map* rs=getMapFromMaps(request_outputs,request_outputs->name,"size"); 1559 fwrite(toto->value,atoi(rs->value),1,stdout); 1560 } 1561 else 1562 printf("%s",toto->value); 1563 #ifdef DEBUG 1564 dumpMap(toto); 1565 #endif 1566 }else{ 1567 char tmp[1024]; 1568 map * errormap; 1569 map *lenv; 1570 lenv=getMapFromMaps(m,"lenv","message"); 1571 if(lenv!=NULL) 1572 sprintf(tmp,"Unable to run the Service. The message returned back by the Service was the following : %s",lenv->value); 1573 else 1574 sprintf(tmp,"Unable to run the Service. No more information was returned back by the Service."); 1575 errormap = createMap("text",tmp); 1576 addToMap(errormap,"code", "InternalError"); 1577 printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 1578 printExceptionReportResponse(m,errormap); 1579 freeMap(&errormap); 1580 free(errormap); 1581 } 1324 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 1325 printf("%s",mime); 1326 toto=getMap(request_outputs->content,"value"); 1327 if(mi!=NULL && strncmp(mi->value,"image",5)==0){ 1328 map* rs=getMapFromMaps(request_outputs,request_outputs->name,"size"); 1329 fwrite(toto->value,atoi(rs->value),1,stdout); 1330 } 1331 else 1332 printf("%s",toto->value); 1333 #ifdef DEBUG 1334 dumpMap(toto); 1335 #endif 1336 } 1582 1337 } 1583 1338
Note: See TracChangeset
for help on using the changeset viewer.