Ignore:
Timestamp:
Jun 15, 2015, 1:47:59 PM (9 years ago)
Author:
djay
Message:

Initial support for WPS 2.0.0 including the Dismiss extension.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r652 r654  
    2222 * THE SOFTWARE.
    2323 */
    24 
    25 
    2624
    2725extern "C" int yylex ();
     
    11111109
    11121110  if(strlen(cgiServerName)>0)
    1113   {
    1114     char tmpUrl[1024];
     1111    {
     1112      char tmpUrl[1024];
    11151113       
    1116         if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?         
    1117                 if ( strncmp(cgiServerPort, "443", 3) == 0 ) {
    1118                         sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
    1119                 }
    1120                 else {
    1121                         sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
    1122                 }
     1114      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?           
     1115        if ( strncmp(cgiServerPort, "443", 3) == 0 ) {
     1116          sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
    11231117        }
    11241118        else {
    1125                 if ( strncmp(cgiServerPort, "80", 2) == 0 ) {
    1126                         sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
    1127                 }
    1128                 else {
    1129                         sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
    1130                 }
     1119          sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
    11311120        }
    1132 #ifdef DEBUG
    1133     fprintf(stderr,"*** %s ***\n",tmpUrl);
    1134 #endif
    1135     setMapInMaps(m,"main","serverAddress",tmpUrl);
    1136   }
    1137 
    1138   /**
    1139    * Check for minimum inputs
    1140    */
     1121      }
     1122      else {
     1123        if ( strncmp(cgiServerPort, "80", 2) == 0 ) {
     1124          sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
     1125        }
     1126        else {
     1127          sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
     1128        }
     1129      }
     1130#ifdef DEBUG
     1131      fprintf(stderr,"*** %s ***\n",tmpUrl);
     1132#endif
     1133      setMapInMaps(m,"main","serverAddress",tmpUrl);
     1134    }
     1135
     1136  //Check for minimum inputs
     1137  map* version=getMap(request_inputs,"version");
     1138  if(version==NULL)
     1139    version=getMapFromMaps(m,"main","version");
     1140  setMapInMaps(m,"main","rversion",version->value);
     1141  int vid=getVersionId(version->value);
     1142  if(vid<0)
     1143    vid=0;
    11411144  map* err=NULL;
    1142   const char *vvr[]={
    1143     "GetCapabilities",
    1144     "DescribeProcess",
    1145     "Execute",
    1146     NULL
    1147   };
    1148   checkValidValue(request_inputs,&err,"request",(const char**)vvr,1);
     1145  const char **vvr=(const char**)requests[vid];
     1146  checkValidValue(request_inputs,&err,"request",vvr,1);
    11491147  const char *vvs[]={
    11501148    "WPS",
     
    11741172  r_inputs = getMap (request_inputs, "Request");
    11751173  REQUEST = zStrdup (r_inputs->value);
     1174  int reqId=-1;
    11761175  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
    11771176    checkValidValue(request_inputs,&err,"version",(const char**)vvv,1);
    1178     checkValidValue(request_inputs,&err,"identifier",NULL,1);
     1177    int j=0;
     1178    for(j=0;j<nbSupportedRequests;j++){
     1179      if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){
     1180        if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
     1181          checkValidValue(request_inputs,&err,"identifier",NULL,1);
     1182          reqId=j+1;
     1183          break;
     1184        }
     1185        else
     1186          if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob &&
     1187             strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
     1188            checkValidValue(request_inputs,&err,"jobid",NULL,1);
     1189            reqId=j+1;
     1190            break;
     1191          }
     1192      }else
     1193        break;
     1194    }
    11791195  }else{
    11801196    checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
     
    11871203    }
    11881204  }
    1189   map* version=getMap(request_inputs,"version");
    1190   if(version==NULL)
    1191     version=getMapFromMaps(m,"main","version");
    1192   setMapInMaps(m,"main","rversion",version->value);
    11931205  if(err!=NULL){
    11941206    printExceptionReportResponse (m, err);
     
    12931305  else
    12941306    {
    1295       r_inputs = getMap (request_inputs, "Identifier");
    1296 
    1297       struct dirent *dp;
    1298       DIR *dirp = opendir (conf_dir);
    1299       if (dirp == NULL)
    1300         {
    1301           errorException (m, _("The specified path path does not exist."),
    1302                           "InvalidParameterValue", conf_dir);
    1303           freeMaps (&m);
    1304           free (m);
     1307      r_inputs = getMap (request_inputs, "JobId");
     1308      if(reqId>nbReqIdentifier){
     1309        if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
     1310            strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
     1311          runGetStatus(m,r_inputs->value,REQUEST);
     1312          freeMaps (&m);
     1313          free (m);
    13051314          if(zooRegistry!=NULL){
    13061315            freeRegistry(&zooRegistry);
    13071316            free(zooRegistry);
    13081317          }
    1309           free (REQUEST);
    1310           free (SERVICE_URL);
    1311           return 0;
    1312         }
    1313       if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
    1314         {
    1315           /**
    1316            * Loop over Identifier list
    1317            */
    1318           xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
    1319           r_inputs = NULL;
    1320           r_inputs = getMap (request_inputs, "version");
    1321           map* version=getMapFromMaps(m,"main","rversion");
    1322           int vid=getVersionId(version->value);
    1323           xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
    1324                                         root_nodes[vid][1],(r_inputs!=NULL?r_inputs->value:"1.0.0"),1);
    1325 
    1326           r_inputs = getMap (request_inputs, "Identifier");
    1327 
    1328           char *orig = zStrdup (r_inputs->value);
    1329 
    1330           int saved_stdout = dup (fileno (stdout));
    1331           dup2 (fileno (stderr), fileno (stdout));
    1332           if (strcasecmp ("all", orig) == 0)
    1333             {
    1334               if (int res =
    1335                   recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
    1336                                   printDescribeProcessForProcess) < 0)
    1337                 return res;
    1338             }
    1339           else
    1340             {
    1341               char *saveptr;
    1342               char *tmps = strtok_r (orig, ",", &saveptr);
    1343 
    1344               char buff[256];
    1345               char buff1[1024];
    1346               while (tmps != NULL)
    1347                 {
    1348                   int hasVal = -1;
    1349                   char *corig = zStrdup (tmps);
    1350                   if (strstr (corig, ".") != NULL)
    1351                     {
    1352 
    1353                       parseIdentifier (m, conf_dir, corig, buff1);
    1354                       map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
    1355                       if (tmpMap != NULL)
    1356                         addToMap (request_inputs, "metapath", tmpMap->value);
    1357                       map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
    1358 
    1359                       s1 = (service *) malloc (SERVICE_SIZE);
    1360                       t = readServiceFile (m, buff1, &s1, tmpMapI->value);
    1361                       if (t < 0)
    1362                         {
    1363                           map *tmp00 = getMapFromMaps (m, "lenv", "message");
    1364                           char tmp01[1024];
    1365                           if (tmp00 != NULL)
    1366                             sprintf (tmp01,
    1367                                      _
    1368                                      ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
    1369                                      tmps, tmp00->value);
    1370                           else
    1371                             sprintf (tmp01,
    1372                                      _
    1373                                      ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
    1374                                      tmps);
    1375                           dup2 (saved_stdout, fileno (stdout));
    1376                           errorException (m, tmp01, "InvalidParameterValue",
    1377                                           "identifier");
    1378                           freeMaps (&m);
    1379                           free (m);
    1380                           if(zooRegistry!=NULL){
    1381                             freeRegistry(&zooRegistry);
    1382                             free(zooRegistry);
     1318          free (REQUEST);
     1319          free (SERVICE_URL);
     1320          return 0;
     1321        }
     1322        else
     1323          if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){
     1324            runDismiss(m,r_inputs->value);
     1325            freeMaps (&m);
     1326            free (m);
     1327            if(zooRegistry!=NULL){
     1328              freeRegistry(&zooRegistry);
     1329              free(zooRegistry);
     1330            }
     1331            free (REQUEST);
     1332            free (SERVICE_URL);
     1333            return 0;
     1334           
     1335          }
     1336        return 0;
     1337      }
     1338      if(reqId<=nbReqIdentifier){
     1339        r_inputs = getMap (request_inputs, "Identifier");
     1340
     1341        struct dirent *dp;
     1342        DIR *dirp = opendir (conf_dir);
     1343        if (dirp == NULL)
     1344          {
     1345            errorException (m, _("The specified path path does not exist."),
     1346                            "InvalidParameterValue", conf_dir);
     1347            freeMaps (&m);
     1348            free (m);
     1349            if(zooRegistry!=NULL){
     1350              freeRegistry(&zooRegistry);
     1351              free(zooRegistry);
     1352            }
     1353            free (REQUEST);
     1354            free (SERVICE_URL);
     1355            return 0;
     1356          }
     1357        if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
     1358          {
     1359            /**
     1360             * Loop over Identifier list
     1361             */
     1362            xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
     1363            r_inputs = NULL;
     1364            r_inputs = getMap (request_inputs, "version");
     1365            map* version=getMapFromMaps(m,"main","rversion");
     1366            int vid=getVersionId(version->value);
     1367            xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
     1368                                          root_nodes[vid][1],(r_inputs!=NULL?r_inputs->value:"1.0.0"),1);
     1369
     1370            r_inputs = getMap (request_inputs, "Identifier");
     1371
     1372            char *orig = zStrdup (r_inputs->value);
     1373
     1374            int saved_stdout = dup (fileno (stdout));
     1375            dup2 (fileno (stderr), fileno (stdout));
     1376            if (strcasecmp ("all", orig) == 0)
     1377              {
     1378                if (int res =
     1379                    recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     1380                                    printDescribeProcessForProcess) < 0)
     1381                  return res;
     1382              }
     1383            else
     1384              {
     1385                char *saveptr;
     1386                char *tmps = strtok_r (orig, ",", &saveptr);
     1387
     1388                char buff[256];
     1389                char buff1[1024];
     1390                while (tmps != NULL)
     1391                  {
     1392                    int hasVal = -1;
     1393                    char *corig = zStrdup (tmps);
     1394                    if (strstr (corig, ".") != NULL)
     1395                      {
     1396
     1397                        parseIdentifier (m, conf_dir, corig, buff1);
     1398                        map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
     1399                        if (tmpMap != NULL)
     1400                          addToMap (request_inputs, "metapath", tmpMap->value);
     1401                        map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
     1402
     1403                        s1 = (service *) malloc (SERVICE_SIZE);
     1404                        t = readServiceFile (m, buff1, &s1, tmpMapI->value);
     1405                        if (t < 0)
     1406                          {
     1407                            map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1408                            char tmp01[1024];
     1409                            if (tmp00 != NULL)
     1410                              sprintf (tmp01,
     1411                                       _
     1412                                       ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
     1413                                       tmps, tmp00->value);
     1414                            else
     1415                              sprintf (tmp01,
     1416                                       _
     1417                                       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
     1418                                       tmps);
     1419                            dup2 (saved_stdout, fileno (stdout));
     1420                            errorException (m, tmp01, "InvalidParameterValue",
     1421                                            "identifier");
     1422                            freeMaps (&m);
     1423                            free (m);
     1424                            if(zooRegistry!=NULL){
     1425                              freeRegistry(&zooRegistry);
     1426                              free(zooRegistry);
     1427                            }
     1428                            free (REQUEST);
     1429                            free (corig);
     1430                            free (orig);
     1431                            free (SERVICE_URL);
     1432                            free (s1);
     1433                            closedir (dirp);
     1434                            xmlFreeDoc (doc);
     1435                            xmlCleanupParser ();
     1436                            zooXmlCleanupNs ();
     1437                            return 1;
    13831438                          }
    1384                           free (REQUEST);
    1385                           free (corig);
    1386                           free (orig);
    1387                           free (SERVICE_URL);
    1388                           free (s1);
    1389                           closedir (dirp);
    1390                           xmlFreeDoc (doc);
    1391                           xmlCleanupParser ();
    1392                           zooXmlCleanupNs ();
    1393                           return 1;
    1394                         }
    1395 #ifdef DEBUG
    1396                       dumpService (s1);
    1397 #endif
    1398                       inheritance(zooRegistry,&s1);
    1399                       printDescribeProcessForProcess (m, n, s1);
    1400                       freeService (&s1);
    1401                       free (s1);
    1402                       s1 = NULL;
    1403                       scount++;
    1404                       hasVal = 1;
    1405                       setMapInMaps (m, "lenv", "level", "0");
    1406                     }
    1407                   else
    1408                     {
    1409                       memset (buff, 0, 256);
    1410                       snprintf (buff, 256, "%s.zcfg", corig);
    1411                       memset (buff1, 0, 1024);
    1412 #ifdef DEBUG
    1413                       printf ("\n#######%s\n########\n", buff);
    1414 #endif
    1415                       while ((dp = readdir (dirp)) != NULL)
    1416                         {
    1417                           if (strcasecmp (dp->d_name, buff) == 0)
    1418                             {
    1419                               memset (buff1, 0, 1024);
    1420                               snprintf (buff1, 1024, "%s/%s", conf_dir,
    1421                                         dp->d_name);
    1422                               s1 = (service *) malloc (SERVICE_SIZE);
    1423                               if (s1 == NULL)
    1424                                 {
    1425                                   dup2 (saved_stdout, fileno (stdout));
    1426                                   return errorException (m,
    1427                                                          _
    1428                                                          ("Unable to allocate memory."),
    1429                                                          "InternalError",
    1430                                                          NULL);
    1431                                 }
    1432 #ifdef DEBUG
    1433                               printf
    1434                                 ("#################\n(%s) %s\n#################\n",
    1435                                  r_inputs->value, buff1);
    1436 #endif
    1437                               char *tmp0 = zStrdup (dp->d_name);
    1438                               tmp0[strlen (tmp0) - 5] = 0;
    1439                               t = readServiceFile (m, buff1, &s1, tmp0);
    1440                               free (tmp0);
    1441                               if (t < 0)
    1442                                 {
    1443                                   map *tmp00 =
    1444                                     getMapFromMaps (m, "lenv", "message");
    1445                                   char tmp01[1024];
    1446                                   if (tmp00 != NULL)
    1447                                     sprintf (tmp01,
    1448                                              _
    1449                                              ("Unable to parse the ZCFG file: %s (%s)"),
    1450                                              dp->d_name, tmp00->value);
    1451                                   else
    1452                                     sprintf (tmp01,
    1453                                              _
    1454                                              ("Unable to parse the ZCFG file: %s."),
    1455                                              dp->d_name);
    1456                                   dup2 (saved_stdout, fileno (stdout));
    1457                                   errorException (m, tmp01, "InternalError",
    1458                                                   NULL);
    1459                                   freeMaps (&m);
    1460                                   free (m);
    1461                                   if(zooRegistry!=NULL){
    1462                                     freeRegistry(&zooRegistry);
    1463                                     free(zooRegistry);
     1439#ifdef DEBUG
     1440                        dumpService (s1);
     1441#endif
     1442                        inheritance(zooRegistry,&s1);
     1443                        printDescribeProcessForProcess (m, n, s1);
     1444                        freeService (&s1);
     1445                        free (s1);
     1446                        s1 = NULL;
     1447                        scount++;
     1448                        hasVal = 1;
     1449                        setMapInMaps (m, "lenv", "level", "0");
     1450                      }
     1451                    else
     1452                      {
     1453                        memset (buff, 0, 256);
     1454                        snprintf (buff, 256, "%s.zcfg", corig);
     1455                        memset (buff1, 0, 1024);
     1456#ifdef DEBUG
     1457                        printf ("\n#######%s\n########\n", buff);
     1458#endif
     1459                        while ((dp = readdir (dirp)) != NULL)
     1460                          {
     1461                            if (strcasecmp (dp->d_name, buff) == 0)
     1462                              {
     1463                                memset (buff1, 0, 1024);
     1464                                snprintf (buff1, 1024, "%s/%s", conf_dir,
     1465                                          dp->d_name);
     1466                                s1 = (service *) malloc (SERVICE_SIZE);
     1467                                if (s1 == NULL)
     1468                                  {
     1469                                    dup2 (saved_stdout, fileno (stdout));
     1470                                    return errorException (m,
     1471                                                           _
     1472                                                           ("Unable to allocate memory."),
     1473                                                           "InternalError",
     1474                                                           NULL);
    14641475                                  }
    1465                                   free (orig);
    1466                                   free (REQUEST);
    1467                                   closedir (dirp);
    1468                                   xmlFreeDoc (doc);
    1469                                   xmlCleanupParser ();
    1470                                   zooXmlCleanupNs ();
    1471                                   return 1;
    1472                                 }
    1473 #ifdef DEBUG
    1474                               dumpService (s1);
    1475 #endif
    1476                               inheritance(zooRegistry,&s1);
    1477                               printDescribeProcessForProcess (m, n, s1);
    1478                               freeService (&s1);
    1479                               free (s1);
    1480                               s1 = NULL;
    1481                               scount++;
    1482                               hasVal = 1;
    1483                             }
    1484                         }
    1485                     }
    1486                   if (hasVal < 0)
    1487                     {
    1488                       map *tmp00 = getMapFromMaps (m, "lenv", "message");
    1489                       char tmp01[1024];
    1490                       if (tmp00 != NULL)
    1491                         sprintf (tmp01,
    1492                                  _("Unable to parse the ZCFG file: %s (%s)"),
    1493                                  buff, tmp00->value);
    1494                       else
    1495                         sprintf (tmp01,
    1496                                  _("Unable to parse the ZCFG file: %s."),
    1497                                  buff);
    1498                       dup2 (saved_stdout, fileno (stdout));
    1499                       errorException (m, tmp01, "InvalidParameterValue",
    1500                                       "Identifier");
    1501                       freeMaps (&m);
    1502                       free (m);
    1503                       if(zooRegistry!=NULL){
    1504                         freeRegistry(&zooRegistry);
    1505                         free(zooRegistry);
     1476#ifdef DEBUG
     1477                                printf
     1478                                  ("#################\n(%s) %s\n#################\n",
     1479                                   r_inputs->value, buff1);
     1480#endif
     1481                                char *tmp0 = zStrdup (dp->d_name);
     1482                                tmp0[strlen (tmp0) - 5] = 0;
     1483                                t = readServiceFile (m, buff1, &s1, tmp0);
     1484                                free (tmp0);
     1485                                if (t < 0)
     1486                                  {
     1487                                    map *tmp00 =
     1488                                      getMapFromMaps (m, "lenv", "message");
     1489                                    char tmp01[1024];
     1490                                    if (tmp00 != NULL)
     1491                                      sprintf (tmp01,
     1492                                               _
     1493                                               ("Unable to parse the ZCFG file: %s (%s)"),
     1494                                               dp->d_name, tmp00->value);
     1495                                    else
     1496                                      sprintf (tmp01,
     1497                                               _
     1498                                               ("Unable to parse the ZCFG file: %s."),
     1499                                               dp->d_name);
     1500                                    dup2 (saved_stdout, fileno (stdout));
     1501                                    errorException (m, tmp01, "InternalError",
     1502                                                    NULL);
     1503                                    freeMaps (&m);
     1504                                    free (m);
     1505                                    if(zooRegistry!=NULL){
     1506                                      freeRegistry(&zooRegistry);
     1507                                      free(zooRegistry);
     1508                                    }
     1509                                    free (orig);
     1510                                    free (REQUEST);
     1511                                    closedir (dirp);
     1512                                    xmlFreeDoc (doc);
     1513                                    xmlCleanupParser ();
     1514                                    zooXmlCleanupNs ();
     1515                                    return 1;
     1516                                  }
     1517#ifdef DEBUG
     1518                                dumpService (s1);
     1519#endif
     1520                                inheritance(zooRegistry,&s1);
     1521                                printDescribeProcessForProcess (m, n, s1);
     1522                                freeService (&s1);
     1523                                free (s1);
     1524                                s1 = NULL;
     1525                                scount++;
     1526                                hasVal = 1;
     1527                              }
     1528                          }
    15061529                      }
    1507                       free (orig);
    1508                       free (REQUEST);
    1509                       closedir (dirp);
    1510                       xmlFreeDoc (doc);
    1511                       xmlCleanupParser ();
    1512                       zooXmlCleanupNs ();
    1513                       return 1;
    1514                     }
    1515                   rewinddir (dirp);
    1516                   tmps = strtok_r (NULL, ",", &saveptr);
    1517                   if (corig != NULL)
    1518                     free (corig);
    1519                 }
    1520             }
    1521           closedir (dirp);
    1522           fflush (stdout);
    1523           dup2 (saved_stdout, fileno (stdout));
    1524           free (orig);
    1525           printDocument (m, doc, getpid ());
    1526           freeMaps (&m);
    1527           free (m);
    1528           if(zooRegistry!=NULL){
    1529             freeRegistry(&zooRegistry);
    1530             free(zooRegistry);
     1530                    if (hasVal < 0)
     1531                      {
     1532                        map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1533                        char tmp01[1024];
     1534                        if (tmp00 != NULL)
     1535                          sprintf (tmp01,
     1536                                   _("Unable to parse the ZCFG file: %s (%s)"),
     1537                                   buff, tmp00->value);
     1538                        else
     1539                          sprintf (tmp01,
     1540                                   _("Unable to parse the ZCFG file: %s."),
     1541                                   buff);
     1542                        dup2 (saved_stdout, fileno (stdout));
     1543                        errorException (m, tmp01, "InvalidParameterValue",
     1544                                        "Identifier");
     1545                        freeMaps (&m);
     1546                        free (m);
     1547                        if(zooRegistry!=NULL){
     1548                          freeRegistry(&zooRegistry);
     1549                          free(zooRegistry);
     1550                        }
     1551                        free (orig);
     1552                        free (REQUEST);
     1553                        closedir (dirp);
     1554                        xmlFreeDoc (doc);
     1555                        xmlCleanupParser ();
     1556                        zooXmlCleanupNs ();
     1557                        return 1;
     1558                      }
     1559                    rewinddir (dirp);
     1560                    tmps = strtok_r (NULL, ",", &saveptr);
     1561                    if (corig != NULL)
     1562                      free (corig);
     1563                  }
     1564              }
     1565            closedir (dirp);
     1566            fflush (stdout);
     1567            dup2 (saved_stdout, fileno (stdout));
     1568            free (orig);
     1569            printDocument (m, doc, getpid ());
     1570            freeMaps (&m);
     1571            free (m);
     1572            if(zooRegistry!=NULL){
     1573              freeRegistry(&zooRegistry);
     1574              free(zooRegistry);
     1575            }
     1576            free (REQUEST);
     1577            free (SERVICE_URL);
     1578            fflush (stdout);
     1579            return 0;
    15311580          }
    1532           free (REQUEST);
    1533           free (SERVICE_URL);
    1534           fflush (stdout);
    1535           return 0;
    1536         }
    1537       else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
    1538         {
    1539           errorException (m,
    1540                           _
    1541                           ("The <request> value was not recognized. Allowed values are GetCapabilities, DescribeProcess, and Execute."),
    1542                           "InvalidParameterValue", "request");
    1543 #ifdef DEBUG
    1544           fprintf (stderr, "No request found %s", REQUEST);
    1545 #endif
    1546           closedir (dirp);
    1547           freeMaps (&m);
    1548           free (m);
    1549           if(zooRegistry!=NULL){
    1550             freeRegistry(&zooRegistry);
    1551             free(zooRegistry);
     1581        else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
     1582          {
     1583            map* version=getMapFromMaps(m,"main","rversion");
     1584            int vid=getVersionId(version->value);
     1585            int len,j=0;
     1586            for(j=0;j<nbSupportedRequests;j++){
     1587              if(requests[vid][j]!=NULL)
     1588                len+=strlen(requests[vid][j])+2;
     1589              else{
     1590                len+=4;
     1591                break;
     1592              }
     1593            }
     1594            char *tmpStr=(char*)malloc(len*sizeof(char));
     1595            int it=0;
     1596            for(j=0;j<nbSupportedRequests;j++){
     1597              if(requests[vid][j]!=NULL){
     1598                if(it==0){
     1599                  sprintf(tmpStr,"%s",requests[vid][j]);
     1600                  it++;
     1601                }else{
     1602                  char *tmpS=zStrdup(tmpStr);
     1603                  if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){
     1604                    sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]);
     1605                  }else{
     1606                    sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]);
     1607                 
     1608                  }
     1609                  free(tmpS);
     1610                }
     1611              }
     1612              else{
     1613                len+=4;
     1614                break;
     1615              }
     1616            }
     1617            char* message=(char*)malloc((61+len)*sizeof(char));
     1618            sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr);
     1619            errorException (m,_(message),"InvalidParameterValue", "request");
     1620#ifdef DEBUG
     1621            fprintf (stderr, "No request found %s", REQUEST);
     1622#endif
     1623            closedir (dirp);
     1624            freeMaps (&m);
     1625            free (m);
     1626            if(zooRegistry!=NULL){
     1627              freeRegistry(&zooRegistry);
     1628              free(zooRegistry);
     1629            }
     1630            free (REQUEST);
     1631            free (SERVICE_URL);
     1632            fflush (stdout);
     1633            return 0;
    15521634          }
    1553           free (REQUEST);
    1554           free (SERVICE_URL);
    1555           fflush (stdout);
    1556           return 0;
    1557         }
    1558       closedir (dirp);
    1559     }
    1560 
     1635        closedir (dirp);
     1636      }
     1637    }
     1638
     1639  map *postRequest = NULL;
     1640  postRequest = getMap (request_inputs, "xrequest");
     1641
     1642  if(vid==1 && postRequest==NULL){
     1643    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 
     1644    freeMaps (&m);
     1645    free (m);
     1646    if(zooRegistry!=NULL){
     1647      freeRegistry(&zooRegistry);
     1648      free(zooRegistry);
     1649    }
     1650    free (REQUEST);
     1651    free (SERVICE_URL);
     1652    fflush (stdout);
     1653    return 0;
     1654  }
     1655 
    15611656  s1 = NULL;
    15621657  s1 = (service *) malloc (SERVICE_SIZE);
     
    16451740  hInternet = InternetOpen (
    16461741#ifndef WIN32
    1647                              (LPCTSTR)
    1648 #endif
    1649                              "ZooWPSClient\0",
    1650                              INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
     1742                            (LPCTSTR)
     1743#endif
     1744                            "ZooWPSClient\0",
     1745                            INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    16511746
    16521747#ifndef WIN32
     
    17301825#endif
    17311826
    1732   // Need to check if we need to fork to load a status enabled
    1733   r_inputs = NULL;
    1734   map *store = getMap (request_inputs, "storeExecuteResponse");
    17351827  map *status = getMap (request_inputs, "status");
    1736   /**
    1737    * 05-007r7 WPS 1.0.0 page 57 :
    1738    * 'If status="true" and storeExecuteResponse is "false" then the service
    1739    * shall raise an exception.'
    1740    */
    1741   if (status != NULL && strcmp (status->value, "true") == 0 &&
    1742       store != NULL && strcmp (store->value, "false") == 0)
    1743     {
    1744       errorException (m,
    1745                       _
    1746                       ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
    1747                       "InvalidParameterValue", "storeExecuteResponse");
    1748       freeService (&s1);
    1749       free (s1);
    1750       freeMaps (&m);
    1751       free (m);
    1752 
    1753       freeMaps (&request_input_real_format);
    1754       free (request_input_real_format);
    1755 
    1756       freeMaps (&request_output_real_format);
    1757       free (request_output_real_format);
    1758 
    1759       free (REQUEST);
    1760       free (SERVICE_URL);
    1761       return 1;
    1762     }
    1763   r_inputs = getMap (request_inputs, "storeExecuteResponse");
     1828  if(vid==0){
     1829    // Need to check if we need to fork to load a status enabled
     1830    r_inputs = NULL;
     1831    map *store = getMap (request_inputs, "storeExecuteResponse");
     1832    /**
     1833     * 05-007r7 WPS 1.0.0 page 57 :
     1834     * 'If status="true" and storeExecuteResponse is "false" then the service
     1835     * shall raise an exception.'
     1836     */
     1837    if (status != NULL && strcmp (status->value, "true") == 0 &&
     1838        store != NULL && strcmp (store->value, "false") == 0)
     1839      {
     1840        errorException (m,
     1841                        _
     1842                        ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
     1843                        "InvalidParameterValue", "storeExecuteResponse");
     1844        freeService (&s1);
     1845        free (s1);
     1846        freeMaps (&m);
     1847        free (m);
     1848       
     1849        freeMaps (&request_input_real_format);
     1850        free (request_input_real_format);
     1851       
     1852        freeMaps (&request_output_real_format);
     1853        free (request_output_real_format);
     1854
     1855        free (REQUEST);
     1856        free (SERVICE_URL);
     1857        return 1;
     1858      }
     1859    r_inputs = getMap (request_inputs, "storeExecuteResponse");
     1860  }else{
     1861    // Define status depending on the WPS 2.0.0 mode attribute
     1862    status = getMap (request_inputs, "mode");
     1863    map* mode=getMap(s1->content,"mode");
     1864    if(strcasecmp(status->value,"async")==0){
     1865      if(mode!=NULL && strcasecmp(mode->value,"async")==0)
     1866        addToMap(request_inputs,"status","true");
     1867      else{
     1868        if(mode!=NULL){
     1869          // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61
     1870          errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 
     1871          fflush (stdout);
     1872          freeMaps (&m);
     1873          free (m);
     1874          if(zooRegistry!=NULL){
     1875            freeRegistry(&zooRegistry);
     1876            free(zooRegistry);
     1877          }
     1878          freeMaps (&request_input_real_format);
     1879          free (request_input_real_format);
     1880          freeMaps (&request_output_real_format);
     1881          free (request_output_real_format);
     1882          free (REQUEST);
     1883          free (SERVICE_URL);
     1884          return 0;
     1885        }else
     1886          addToMap(request_inputs,"status","true");
     1887      }
     1888    }
     1889    else{
     1890      if(strcasecmp(status->value,"auto")==0){
     1891        if(mode!=NULL){
     1892          if(strcasecmp(mode->value,"async")==0)
     1893            addToMap(request_inputs,"status","false");
     1894          else
     1895            addToMap(request_inputs,"status","true");
     1896        }
     1897        else
     1898          addToMap(request_inputs,"status","false");
     1899      }else
     1900        addToMap(request_inputs,"status","false");
     1901    }
     1902    status = getMap (request_inputs, "status");
     1903  }
     1904
    17641905  int eres = SERVICE_STARTED;
    17651906  int cpid = getpid ();
     
    18081949  else
    18091950    addToMap (_tmpMaps->content, "soap", "false");
     1951
     1952  // Parse the session file and add it to the main maps
    18101953  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
    18111954    {
     
    18832026  freeMaps (&_tmpMaps);
    18842027  free (_tmpMaps);
    1885 
     2028  maps* bmap=NULL;
    18862029#ifdef DEBUG
    18872030  dumpMap (request_inputs);
     
    19072050    }
    19082051#endif
    1909   char *fbkp, *fbkpid, *fbkp1, *flog;
     2052  char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
    19102053  FILE *f0, *f1;
    19112054  if (status != NULL)
     
    19582101      if (pid > 0)
    19592102        {
    1960       /**
    1961        * dady :
    1962        * set status to SERVICE_ACCEPTED
    1963        */
     2103          /**
     2104           * dady :
     2105           * set status to SERVICE_ACCEPTED
     2106           */
    19642107#ifdef DEBUG
    19652108          fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
     
    19752118           */
    19762119          map* usid = getMapFromMaps (m, "lenv", "uusid");
    1977           r_inputs = getMapFromMaps (m, "lenv", "osid");
    1978           int cpid = atoi (r_inputs->value);
     2120          map* tmpm = getMapFromMaps (m, "lenv", "osid");
     2121          int cpid = atoi (tmpm->value);
    19792122          r_inputs = getMapFromMaps (m, "main", "tmpPath");
    19802123          map* r_inputs1 = createMap("ServiceName", s1->name);
    19812124
     2125          // Create the filename for the result file (.res)
     2126          fbkpres =
     2127            (char *)
     2128            malloc ((strlen (r_inputs->value) +
     2129                     strlen (usid->value) + 7) * sizeof (char));
     2130          sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
     2131          bmap = (maps *) malloc (MAPS_SIZE);
     2132          bmap->name=zStrdup("status");
     2133          bmap->content=createMap("usid",usid->value);
     2134          bmap->next=NULL;
     2135          addToMap(bmap->content,"sid",tmpm->value);
     2136          addIntToMap(bmap->content,"pid",getpid());
     2137         
    19822138          // Create PID file referencing the OS process identifier
    19832139          fbkpid =
     
    19992155
    20002156          FILE* f2 = fopen (fbkp, "w+");
    2001           map* tmpm=getMapFromMaps (m, "lenv", "osid");
    20022157          fprintf(f2,"%s",tmpm->value);
    20032158          fflush(f2);
     
    20252180          freopen (flog, "w+", stderr);
    20262181          fflush (stderr);
    2027           f0 = freopen (fbkp, "w+", stdout);
    2028           rewind (stdout);
     2182          f0 = freopen (fbkp, "w+", stdout);
     2183          rewind (stdout);
    20292184#ifndef WIN32
    2030           fclose (stdin);
    2031 #endif
    2032 
    2033           /**
    2034            * set status to SERVICE_STARTED and flush stdout to ensure full
    2035            * content was outputed (the file used to store the ResponseDocument).
    2036            * The rewind stdout to restart writing from the bgining of the file,
    2037            * this way the data will be updated at the end of the process run.
    2038            */
    2039           printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
    2040                                 SERVICE_STARTED, request_input_real_format,
    2041                                 request_output_real_format);
    2042           fflush (stdout);
     2185          fclose (stdin);
     2186#endif
     2187
    20432188#ifdef RELY_ON_DB
    20442189          init_sql(m);
    20452190          recordServiceStatus(m);
    2046           recordResponse(m,fbkp);
    2047 #endif
     2191#endif
     2192          if(vid==0){
     2193            /**
     2194             * set status to SERVICE_STARTED and flush stdout to ensure full
     2195             * content was outputed (the file used to store the ResponseDocument).
     2196             * The rewind stdout to restart writing from the bgining of the file,
     2197             * this way the data will be updated at the end of the process run.
     2198             */
     2199            printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
     2200                                  SERVICE_STARTED, request_input_real_format,
     2201                                  request_output_real_format);
     2202            fflush (stdout);
     2203#ifdef RELY_ON_DB
     2204            recordResponse(m,fbkp);
     2205#endif
     2206          }
     2207
    20482208          fflush (stderr);
     2209
    20492210          fbkp1 =
    20502211            (char *)
     
    21162277    {
    21172278      fclose (stdout);
    2118       fclose (stderr);
     2279      //fclose (stderr);
    21192280      /**
    21202281       * Dump back the final file fbkp1 to fbkp
     
    21222283      fclose (f0);
    21232284      fclose (f1);
     2285
    21242286      FILE *f2 = fopen (fbkp1, "rb");
    21252287#ifndef RELY_ON_DB
     
    21292291      lockShm (lid);
    21302292#endif
     2293      fclose(f0);
    21312294      FILE *f3 = fopen (fbkp, "wb+");
    21322295      free (fbkp);
     
    21402303      fclose (f3);
    21412304      unlink (fbkpid);
     2305      switch(eres){
     2306      default:
     2307      case SERVICE_FAILED:
     2308        setMapInMaps(bmap,"status","status",wpsStatus[1]);
     2309        setMapInMaps(m,"lenv","fstate",wpsStatus[1]);
     2310        break;
     2311      case SERVICE_SUCCEEDED:
     2312        setMapInMaps(bmap,"status","status",wpsStatus[0]);
     2313        setMapInMaps(m,"lenv","fstate",wpsStatus[0]);
     2314        break;
     2315      }
    21422316#ifndef RELY_ON_DB
     2317      dumpMapsToFile(bmap,fbkpres);
    21432318      removeShmLock (m, 1);
    21442319#else
    21452320      recordResponse(m,fbkp1);
    21462321#endif
     2322      freeMaps(&bmap);
     2323      free(bmap);
    21472324      unlink (fbkp1);
    21482325      unlink (flog);
    21492326      unhandleStatus (m);
    21502327      free(fbkpid);
     2328      free(fbkpres);
    21512329      free (flog);
    21522330      free (fbkp1);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

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

Become a sponsor !

Knowledge partners

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

Become a knowledge partner

Related links

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